diff options
author | James Cameron <quozl@laptop.org> | 2011-12-07 11:08:45 (GMT) |
---|---|---|
committer | James Cameron <quozl@laptop.org> | 2011-12-07 11:08:45 (GMT) |
commit | 1c69184a9ad48d716469876cb6723d346396974b (patch) | |
tree | 6860a2feb8398fe6162696f9ab6a3dd44e000122 /data | |
parent | ecc71b292c6c5b229bf3d5e5dd5c062087bb57df (diff) |
camera example, fix for delay in image capture file being ready
Sometimes the file that should be there, is not. Waiting longer is
one workaround. In this patch we wait until the file is available,
checking every second.
Tested by: Laurent Bernabe <laurent.bernabe@gmail.com>
Diffstat (limited to 'data')
-rw-r--r-- | data/graphics/camera | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/data/graphics/camera b/data/graphics/camera index 2a37675..66d3d50 100644 --- a/data/graphics/camera +++ b/data/graphics/camera @@ -9,10 +9,6 @@ import time # grey background bgcolor = (128, 128, 128) -# grab a frame from camera to file -pipeline = gst.parse_launch('v4l2src ! ffmpegcolorspace ! jpegenc ! filesink location=/tmp/pippypic.jpg') -pipeline.set_state(gst.STATE_PLAYING) - # start using pygame pygame.init() @@ -23,15 +19,22 @@ pygame.mouse.set_visible(False) # drawing in that window. screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) -# pause for a second to allow the camera frame to be grabbed -time.sleep(1) +# grab a frame from camera to file +pipeline = gst.parse_launch('v4l2src ! ffmpegcolorspace ! jpegenc ! filesink location=/tmp/pippypic.jpg') +pipeline.set_state(gst.STATE_PLAYING) + +# keep trying to load in the grabbed camera frame until it works +while True: + try: + image = pygame.image.load('/tmp/pippypic.jpg') + break + except pygame.error: + time.sleep(1) # stop the camera frame grabbing pipeline.set_state(gst.STATE_NULL) -# load in the grabbed camera frame -image = pygame.image.load('/tmp/pippypic.jpg') - +# set initial rotation angle and scale angle = 0.0 scale = 2.0 |