[OLPC-Games] Camera functionality in olpcgames
Mike C. Fletcher
mcfletch at vrplumber.com
Tue Nov 13 17:16:15 EST 2007
The current Camera implementation in olpcgames has a number of issues,
not least of which is that if your gstreamer bus fails for any reason,
your "snap" call will never return (and in my tests, that hangs your
entire GUI). I've reimplemented the Camera class to provide a number of
features, the most important of which is an asynchronous API that
delivers the captured image as a Pygame event, rather than returning it
directly from the "snap" call. It also allows you to specify the image
format and data source (e.g. to use a testing source on machines without
v4l2src sources available).
The current API should still work, though I don't see a lot of
activities that actually use the camera. "snap" should be considered
deprecated at the moment, as it is not particularly safe (it could be
made safe with some work, it just isn't now). I've also refactored the
code so that the same code can be used for initialising the gstreamer
pipeline, loading the images etceteras for all of the entry points.
Changes should land as soon as I get write access to the repository. At
the moment the only code I see that uses it is the TicTacToe test stuff
(doesn't seem very useful there, but I've converted it to the async api
anyway).
Example of use:
elif evt.key == pygame.K_a:
cam.snap_async( 'you', source='test' )
elif evt.type in (olpcgames.camera.CAMERA_LOAD,
olpcgames.camera.CAMERA_LOAD_FAIL):
if evt.success
if evt.token == 'you':
pic = evt.image
else:
print 'Failure loading picture: %s'%( evt.err, )
Have fun,
Mike
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
More information about the Games
mailing list