title: VideoCapture on OpenCV updating automatically the frame
body: <p>I'm implementing an algorithm that requires a video frame from instant t and another from instant t+1. Seeing a few examples it seemed really straightforward. I thought that this would work perfectly:</p>
  
  <pre><code>VideoCapture cap(0);
  Mat img1, img2;
  while(1) {
      cap &gt;&gt; img1; // instant t
      cap &gt;&gt; img2; // instant t+1
      imshow(img1 == img2);
  }
  </code></pre>
  
  <p>But it didn't, the images were the same, because the image displayed (img1 == img2) was completely white, indicating value 255 for every pixel.</p>
  
  <p>I thought that maybe I wasn't giving enough time for the camera to capture a second frame and I was using the same one that was still in the buffer. What I did was simple:</p>
  
  <pre><code>VideoCapture cap(0);
  Mat img1, img2;
  while(1) {
      cap &gt;&gt; img1; // instant t
  
      // I added 2.5 seconds between the acquisition of each frame
      waitKey(2500); 
  
      cap &gt;&gt; img2; // instant t+1
      waitKey(2500);
      imshow(img1 == img2);
  }
  </code></pre>
  
  <p>It still didn't work. Just to be sure, I added the following lines of code:</p>
  
  <pre><code>VideoCapture cap(0);
  Mat img1, img2;
  while(1) {
      cap &gt;&gt; img1; // instant t
      imshow("img1", img1);
      waitKey(2500); // I added 2.5 seconds between the acquisition of each frame
  
      cap &gt;&gt; img2; // instant t+1
  
      // Here I display both images after img2 is captured
      imshow("img2", img2);
      imshow("img1", img1);
      waitKey(2500);
      imshow(img1 == img2);
  }
  </code></pre>
  
  <p>When I displayed the two images after capturing img1 again, both images had changed! I've tried using different VideoCapture objects for the different images, but that didn't have any effect...</p>
  
  <p>Can anyone advise me on what I'm doing wrong?</p>
  
  <p>Thanks,</p>
  
  <p>Renan</p>