Pages

Wednesday, June 12, 2013

Pygame.display without LXDE or GNOME

Now I discovered the following.

1. Pygame does not need RPi's GUI LXDE  (Lightweight X11Desktop Environment) to display a surface or image.  In other words, there is no need to start LXDE to display a webcam image.  Pygame will select the default windows environment, if not specified.

2. PuTTY can be used to SSH RPi console as usual, though the graphics will only be displayed in the RPi terminal.
  
3. Standard VGA resolution of 640 x 480 can be used for Logitech C920 webcam (maximum resolution 1920 x 1280 video) and BenQ FP737s (with maximum resolution 1280 x 1024).

The following program can capture an image and display it for 4 seconds.

Bug - The OS hangs after taking a couple of pictures.  Perhaps some buffer overflows.  Need to check later.


def TestWebcam02():

    ftprint.PrintDoubleSpaceLine("*** Sample run begin - Test web cam 2013jun12hkt16:23 ***")    
       
    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)
    webCam = pygame.camera.Camera(webCamList[0], Size640x480)
    webCam.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)   

    webCamSurface = webCam.get_image(webCamSurface)
    time.sleep(0.1)
    
    webCamDisplay.blit(webCamSurface, (0,0))
    pygame.display.flip()
    time.sleep(4)

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

    webCam.stop()
    pygame.quit()

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

.END

No comments:

Post a Comment