Pages

Tuesday, June 18, 2013

Testing Logitech C270 and C920 video VGA, HD720, and HD1080 mode

Now I have used TestWebCamera08() to test C270 and C920 VGA, HD720, and HD1080 resolution.  I found pygame cannot do HD1080.  So I have to settle with HD720.

# *****************************************************************************
# Function - TestWebcam()
# Notes - 
#   * BenQ 737s 17" LCD monitor native Resolution 1280 x 1024
#   * C920 image size = HD1080 (1920 x 1080), HD720 (1280 x 720)
#   * pygame error: No video mode large enough for 1920 x 1080
# *****************************************************************************

Size640x480 = (640, 480)
Size1280x720 = (1280, 720)
Size1280x1024 = (1280, 1024) # ValueError: Destination surface not the correct width or height
Size1920x1080 = (1920, 1080) # pygame.error: No video mode large enough for 1920x1080

def TestWebcamCamera08(cameraNumber, imageSize, imageCount, timerSecond):

    ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera08() 2013jun18hkt10:54 ***")    

    pygame.init()
    pygame.camera.init()

    webCamList = pygame.camera.list_cameras()
    webCamCount = len(webCamList)
    print "Number of cameras found = ", webCamCount
    print "Camera used = ", cameraNumber
    print "Image size = (", imageSize[0], ", ", imageSize[1], ")"
    print "Number of images to get = ", imageCount
    print "Time between images (in seconds) = ", timerSecond

    imageSize = Size1280x720 # debug only !!!

    webCamCamera = pygame.camera.Camera(webCamList[int(cameraNumber)], imageSize)
    webCamCamera.start()

    pygame.display.init()
    webCamDisplay = pygame.display.set_mode(imageSize, 0)

    webCamSurface = pygame.surface.Surface(imageSize, 0, webCamDisplay)   

    for count in range(imageCount):

        for event in pygame.event.get(): # Escape key from local keyboard, NOT PuTTY!!!
   if (event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE)):                                  
                webCamCamera.stop()
                pygame.quit()
return
        
if webCamCamera.query_image(): 
            webCamSurface = webCamCamera.get_image(webCamSurface)
            webCamDisplay.blit(webCamSurface, (0,0))
            pygame.display.flip()

        time.sleep(timerSecond)
print "Image number = ", count

    pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")

    print "File name of last image = /home/pi/fongtoy/testImage.bmp", 

    ftprint.PrintDoubleSpaceLine("*** Sample run end ***")

# *** Sample call ***

# ftwebcam.TestWebcamCamera08(cameraNumber = 0, imageSize = (640, 480), imageCount = 10, timerSecond = 1)
# ftwebcam.TestWebcamCamera08(cameraNumber = 1, imageSize = (640, 480), imageCount = 10, timerSecond = 1)
# ftwebcam.TestWebcamCamera08(cameraNumber = 0, imageSize = (1280, 720), imageCount = 10, timerSecond = 1)
# ftwebcam.TestWebcamCamera08(cameraNumber = 1, imageSize = (1280, 720), imageCount = 10, timerSecond = 1)

# ** Sample output ***

# pi@raspberrypi ~/fongtoy $ sudo python fongtoy.py
# *** Start Program - FongToy v1.12 tlfong01 2013jun18 ***
# *** Sample run begin - TestWebCamCamera08() 2013jun18hkt10:54 ***
# ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
# Number of cameras found =  2
# Camera used =  1
# Image size = ( 1280 ,  720 )
# Number of images to get =  10
# Time between images (in seconds) =  1
# Image number =  0
# Image number =  1
# Image number =  2
# Image number =  3
# Image number =  4
# Image number =  5
# Image number =  6
# Image number =  7
# Image number =  8
# Image number =  9
# File name of last image = /home/pi/fongtoy/testImage.bmp
# *** Sample run end ***
# *** Stop Program ***
# pi@raspberrypi ~/fongtoy $ date
# Tue Jun 18 05:27:42 UTC 2013

.END

No comments:

Post a Comment