The pxc200 module adds support for the ImageNation
PXC-200 frame grabber to the Python Imaging
Library, using Alessandro Rubini's driver for Linux. Once you've
opened the driver's device file, image acquisition is very fast; on a
450MHz Pentium II machine, a Python program can read and JPEG-compress
over 25 frames per second.
The following little script demonstrates how to acquire an image from the PXC-200.
import os, fcntl, struct, FCNTL
import Image, pxc200
# Camera constants
BRIGHT = 75
CONTRAST = 164
# Open the PXC device and set it up
fd = os.open('/dev/pxc0bgr', FCNTL.O_RDWR)
fcntl.ioctl(fd, pxc200.PX_IOCSBRIGHT, struct.pack('i', BRIGHT) )
fcntl.ioctl(fd, pxc200.PX_IOCSCONTRAST, struct.pack('i', CONTRAST) )
# Create image object
im=Image.new( 'RGB', (320,240) )
# Grab a frame; the data is placed
# directly into the PIL object.
pxc200.snap(fd, im.im.id)
# Display the image
im.show()
# Close the device file
os.close(fd)
The module reads from the PXC device file until the image has been
filled; it can't verify that the frame's dimensions are the same as the size
of the provided image. If you notice the image being translated between
successive frames (continually shifting to the left, for example), verify
that the image size is correct (320x240 for the /dev/pxc0bgr
device, 640x480 for /dev/pxc0Hbgr. You only need to open the
device file once, and can then read multiple images over the same file
descriptor.