简体   繁体   中英

C++ OpenCV cvMAT Playback

I have a vector of type cvMat into which I have been storing frames taken from my computer's webcam. After storing 100 frames, I would like to play the frames back. If record is my vector of cvMats, I thought this might be done as so:

cvNamedWindow("play-back",CV_WINDOW_AUTOSIZE);
cvMoveWindow("play-back",100,100);
for (vector<Mat>::iterator iter = record.begin(); iter != record.end();++iter) {
   imshow("play-back",*iter);
}

When executed, the program seems to work well enough for storing the cvMats and getting input from the webcam, but when I attempt to get playback, the program seems to execute that portion of code very quickly -- so quickly, in fact, that I don't have time to appreciate the results. How might I be able to improve this code so that the playback is not so rushed?

You need to give control to OpenCV to actually render each image in the window and hold it for a brief period of time before switching to the next. You should add a call to cvWaitKey with a delay of, say 41ms (approximately 24 fps). Then you can check cvWaitKey's return value so that the user can stop the playback. Something like this:

cvNamedWindow("play-back",CV_WINDOW_AUTOSIZE);
cvMoveWindow("play-back",100,100);
for (vector<Mat>::iterator iter = record.begin(); iter != record.end();++iter) {
   imshow("play-back",*iter);
   if( cvWaitKey(41) == 27 ) // ESC
       break;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM