Sunday, 15 May 2011

pygame - Controlling USB web camera photo capture time on Raspberry Pi and Python -



pygame - Controlling USB web camera photo capture time on Raspberry Pi and Python -

i taking pictures on raspberry pi using usb webcam , pygame. these images used track motion of object, rotate motor. therefore, constant framerate nice. unfortunately, taking pictures of dark object seem take 4x much time bright objects. suspect result of longer exposure time.

if indeed problem, there way set exposure time fixed number? if not, else can do?

result of code below:

dark: (aimed @ black wall) - duration: 14213 ms - min: 12 ms - max: 387 ms - avg: 142 ms

bright: (aimed @ white wall) - duration: 3550 ms - min: 12 ms - max: 67 ms - avg: 35 ms

print "importing.." import time import pygame import pygame.camera pygame.locals import * # initialize photographic camera print "\ninitializing.." pygame.init() pygame.camera.init() camlist = pygame.camera.list_cameras() cam = pygame.camera.camera("/dev/video0", (320,240)) cam.start() time.sleep(1) # measure time print "running.." begin = int(round(time.time() * 1000)) min = 1000 max = 0 in range(1, 100): start = int(round(time.time() * 1000)) img = cam.get_image() stop = int(round(time.time() * 1000)) - start if(stop > max): max = stop if(stop < min): min = stop print "{}\t{} ms".format(i, stop) duration = int(round(time.time() * 1000)) - begin print "duration: {} ms".format(duration) print "min:\t{} ms".format(min) print "max:\t{} ms".format(max) print "avg:\t{} ms".format(duration / 100)

as long required frame rate low plenty accommodate slowest exposure, can sleep after processing each frame until it's time new frame. you've got time started first frame. when first frame done, add together required interval next start , calculate sleep time next frame.

python pygame raspberry-pi webcam

No comments:

Post a Comment