title: OpenCV VideoCapture only updates after 5 read()s
body: <p>I have a very strange error that has been plaguing my research for a few years now. I'm using OpenCV2 with Python to read image data from a webcam. However, the image is lagged by 5 frames. In other words, each call to read() is 5 frame behind real-time.</p>
  
  <p>One bandage fix I have been using is to grab() 4 frames and then read the 5th every time I need an updated image, but that absolutely murders my performance.</p>
  
  <p>Here's the code that I am using to display the images from the webcam</p>
  
  <pre><code>    frame = self.getGoodFrame()
  
      if self.DEBUG:
          window = cv2.namedWindow("Angles")
      imgHSV = cv2.cvtColor(frame, cv2.cv.CV_BGR2HSV)
  
      ... Reseach specific code I shouldn't be giving out here ...
      ... It finds the center of a few bright colors in an image
  
      if self.DEBUG:
          debugImage = numpy.zeros((self.CAMERA_HEIGHT, self.CAMERA_WIDTH), numpy.uint8) #blank image
  
         ... Then we draw some stuff to the image to be displayed ...
  
          cv2.imshow("Angles", debugImage)
          cv2.waitKey(1)
          raw_input()
  </code></pre>
  
  <p>and getGoodFrame()</p>
  
  <pre><code>def getGoodFrame(self):
      MIN_READS_FOR_GOOD_FRAME = 4
  
      for i in xrange(MIN_READS_FOR_GOOD_FRAME):
          successful_read = self.capture.grab() 
  
      successful_read, frame = self.capture.read()
  
      if not successful_read:
          print "Unable to read from webcam, exiting."
  
      return frame
  </code></pre>
  
  <p>You'll notice that I have a raw_input() call. That makes it so I can see how many reads need to happen by pressing enter a few times in console. This shows that there is exactly 5 frames of lag.</p>
  
  <p>I don't think it's a hardware issue, I've had this happen with multiple webcams and multiple USB cords. I haven't tried reproducing the error on another machine though.</p>