A quick webcam application using pyGame

Here’s a quick script to do a webcam using pyGame.

It works rather well on a Nokia n900 (while there are some issues getting hold of the webcam image on Mac OSX …).

Copy the text into a textfile and name it as you please – without spaces though.  Then copy the file to the n900, and run it using “python YourScriptName” < where you replace “YourScriptName” with the name of your script. ( You may find some instructions for transferring files and running them, on the n900, here ).


# import the relevant libraries
import time
import pygame
import pygame.camera
from pygame.locals import *
# this is where one sets how long the script
# sleeps for, between frames.sleeptime__in_seconds = 0.05
# initialise the display window
screen = pygame.display.set_mode([800,420])
# set up a camera object
cam = pygame.camera.Camera("/dev/video0",(640,480))
# start the camera

while 1:

    # sleep between every frame
    time.sleep( sleeptime__in_seconds )
    # fetch the camera image
    image = cam.get_image()
    # blank out the screen
    # copy the camera image to the screen
    screen.blit( image, ( 100, 0 ) )
    # update the screen to show the latest screen image


This entry was posted in Uncategorized. Bookmark the permalink.