title: Controlling USB web camera photo capture time on Raspberry Pi and Python
body: <p>I am taking pictures on my Raspberry Pi using an usb webcam and Pygame. These images will be used to track movement of an object, then rotate a motor. Therefore, a constant framerate would be nice. 
  Unfortunately, taking pictures of dark object seem to take up almost 4x as much time as with bright objects. I suspect this is the result of a longer exposure time. </p>
  
  <p>If this is indeed the problem, is there any way to set the exposure time to a fixed number? If not, what else can i do?</p>
  
  <p>result of code below:  </p>
  
  <p>Dark: (aimed at a black wall)<br>
  - Duration: 14213 ms<br>
  - Min:    12 ms<br>
  - Max:    387 ms<br>
  - Avg:    142 ms</p>
  
  <p>Bright: (aimed at a white wall)<br>
  - Duration: 3550 ms<br>
  - Min:    12 ms<br>
  - Max:    67 ms<br>
  - Avg:    35 ms  </p>
  
  <pre><code>print "importing.."
  
  import time
  import pygame
  import pygame.camera
  from pygame.locals import *
  
  # INITIALIZE 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
  
  for i in range(1, 100):
          start = int(round(time.time() * 1000))    
          img = cam.get_image()        
          stop = int(round(time.time() * 1000)) - start
  
          if(stop &gt; max):
                  max = stop
          if(stop &lt; 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)
  </code></pre>