Pages

Friday, June 14, 2013

Web cam test function refactoring notes

Now I am refactoring the webcam test function.  I am making the names more consistent.

webCamList

webCamCamera

webCamDisplay

webCamSurface

.END


def TestWebcamCamera04():

    ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera04() 2013jun14hkt21:13 ***")  
     
    Size640x480 = (640, 480)
    Size1280x1024 = (1280, 1024)
    Size1920x1024 = (1920, 1024)

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

    webCamList = pygame.camera.list_cameras()
    if webCamList:
        print "List of available cameras = ", webCamList
    else:
        print "!!! No camera!!! "

    # webCam = pygame.camera.Camera(webCamList[0], Size1280x1024)
    webCamCamera = pygame.camera.Camera(webCamList[0], Size640x480)
    webCamCamera.start()

    pygame.display.init()
    # webCamDisplay = pygame.display.set_mode(Size1280x1024, 0)
    webCamDisplay = pygame.display.set_mode(Size640x480, 0)

    # webCamSurface = pygame.surface.Surface(Size1280x1024, 0, webCamDisplay)    
    webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)  

    while True:
        if webCamCamera.query_image():
            webCamSurface = webCamCamera.get_image(webCamSurface)
            webCamDisplay.blit(webCamSurface, (0,0))
            pygame.display.flip()

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

    webCamCamera.stop()
    pygame.quit()

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

.END

No comments:

Post a Comment