title: OpenCV "stuck" frames with VideoCapture
body: <p>I'm using OpenCV 3.1, I try to run a simple code as the following one (main function):</p>
  
  <pre><code> cv::VideoCapture cam;
  cv::Mat matTestingNumbers;
  
  cam.open(0);
  
  if (!cam.isOpened()) { printf("--(!)Error opening video capture\n"); return -1; }
  
  while (cam.read(matTestingNumbers))
  {
      cv::imshow("matTestingNumbers", matTestingNumbers);
      cv::waitKey(5000);
  }
  </code></pre>
  
  <p>When I move the camera it seems that the code does not capture and show the current frame but shows all the captured frames from the previous position and only then from the new one.</p>
  
  <p>So when I capture the wall it shows the correct frames (the wall itself) in the correct delay, but, when I twist the camera to my computer, I first see about 3 frames of the wall and only then the computer, it seems that the frames are stuck.</p>
  
  <p>I've tried to use videoCapture.set() functions and set the FPS to 1, and I tried to switch the method of capturing to cam >> matTestingNumbers (and the rest of the main function according to this change) but nothing helped, I still got "stuck" frames.</p>
  
  <p>BTW, These are the solutions I found on web.</p>
  
  <p>What can I do to fix this problem?</p>
  
  <p>Thank you, Dan.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried to retrieve frames as the following:</p>
  
  <pre><code>#include "opencv2/opencv.hpp"
  
  using namespace cv;
  
  int main(int, char**)
  {
      VideoCapture cap(0); // open the default camera
      if(!cap.isOpened())  // check if we succeeded
          return -1;
  
      Mat frame;
      namedWindow("edges",1);
  
      for(;;)
      {
          cap.grab();
  
          if (waitKey(11) &gt;= 0)
          {
              cap.retrieve(frame);
              imshow("edges", frame);
          }
  
      }
      return 0;
  }
  </code></pre>
  
  <p>But, it gave the result (when I pointed the camera on one spot and pressed a key it showed one more of the previous frames that were captured of the other point).</p>
  
  <p>It is just like you're trying to picture one person then another but when you picture the second you get the photo of the first person what doesn't make sense.</p>
  
  <p>Then, I tried the following:</p>
  
  <pre><code>#include "opencv2/opencv.hpp"
  
  using namespace cv;
  
  int main(int, char**)
  {
      VideoCapture cap(0); // open the default camera
      if(!cap.isOpened())  // check if we succeeded
          return -1;
  
      Mat frame;
      namedWindow("edges",1);
  
      for(;;)
      {
          cap &gt;&gt; frame;
  
          if (waitKey(33) &gt;= 0)
  
              imshow("edges", frame);
  
      }
      return 0;
  }
  </code></pre>
  
  <p>And it worked as expected.</p>