Pages

Tuesday, June 18, 2013

Test webcam function refactoring notes

Now I am incrementally enhancing the test web cam program.


# *****************************************************************************
# 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 TestWebcamCamera09(cameraNumber, imageSize, imageCount, timerSecond, fileName):

    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 (event.type == KEYDOWN and event.key == K_x):                                  
                webCamCamera.stop()
                pygame.quit()
return

   if (event.type == KEYDOWN and event.key == K_s):  
       fullPathFileName = os.path.join('/home/pi/fongtoy/', fileName)
                pygame.image.save(webCamSurface, fullPathFileName)
print "Image saved"          

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 ***")

# *** sampel call *
# ftwebcam.TestWebcamCamera09(cameraNumber = 1, imageSize = (1280, 720), imageCount = 10, timerSecond = 1, fileName = "file20130618hkt1725.bmp")

.END

No comments:

Post a Comment