Ravi
Ravi

Reputation: 255

Opencv, with video capture card, grabs frames only when a break point is set in the c++ code

Capturing a video with video capture card, opencv

The above question pretty much asks what i want to. I have an elgato (elgato video capture http://www.elgato.com/video/video-capture) frame grabber which has USB 2.0 interface. I am trying to use opencv to grab the frames from the elgato frame grabber. Frame grabbing is happening inside a while loop as shown below.

grabSuccess        = ( cvGrabFrame (captureDev[0]) == 1 );
frameGrabbed       = (grabSuccess ? cvRetrieveFrame (captureDev[0]) : NULL);    
while (1)
{

    grabSuccess  = ( cvGrabFrame (captureDev[0]) == 1);
    frameGrabbed = (grabSuccess ? cvRetrieveFrame (captureDev[0]) : NULL);
      .
      .
      .
      //some processing
      .
      .
      .
      //show image here
}

when I set a break point before the loop and continue the execution after the debugger stops at the break point. Everything works fine( video frames are displayed in cvWindow). But without the break-point interrupt , I see a blank grayed out window.

Any help would be appreciated.

P:S: I am developing using visual studio 2012 express in windows 8 with opencv 2.3.1 , elgato specification are as follows: 1) Video resolution: 640×480 (4:3) or 640×360 (16:9) 2) Video format PC Software: H.264 at 1.4 MBit/sec

Upvotes: 0

Views: 1636

Answers (1)

FutureJJ
FutureJJ

Reputation: 2678

Add

cv::waitKey(1);

After the code line to show the image in a window.

cv::waitKey() tells the computer to wait for some time (1ms here) to render the image in a window. cv::waitKey() is very similar to _getch(), which waits for the user to input a key.

Upvotes: 0

Related Questions