[英]manually stop a video in openCV
I have an OpenCV code that was given to me, and it displays a video using a linked list of pictures.我有一个给我的 OpenCV 代码,它使用图片链接列表显示视频。 I want to add to it the option of stoping the video in case of a loop, using a keyboard key.
我想添加一个在循环的情况下使用键盘键停止视频的选项。 I did some searching and got to the 'WaitKey' feature, but I'm not sure where and how I'm supposed to use it in my code.
我进行了一些搜索并找到了“WaitKey”功能,但我不确定在我的代码中应该在哪里以及如何使用它。
cvNamedWindow("Display window", CV_WINDOW_AUTOSIZE); //create a window
FrameNode* head = list;
int imgNum = 1, playCount = 0;
IplImage* image;
while (playCount < GIF_REPEAT)
{
while (list != 0)
{
image = cvLoadImage(list->frame->path, 1);
IplImage* pGrayImg = 0;
pGrayImg = cvCreateImage(cvSize(image->width, image->height), image->depth, 1);
if (!image) //The image is empty - shouldn't happen since we checked already.
{
printf("Could not open or find image number %d", imgNum);
}
else
{
cvShowImage("Display window", image); //display the image
cvWaitKey(list->frame->duration); //wait
list = list->next;
cvReleaseImage(&image);
}
imgNum++;
}
list = head; // rewind
playCount++;
}
cvDestroyWindow("Display window");
return;
cv::imshow("display", image);
char ch = cv::waitKey(duration);
if (ch == ' ')
ch = cv::waitKey(0); // waits until user presses a key
if cv2.waitKey(1) & 0xFF == ord("q"):
break
waitKey(0
will display the window infinitely until any keypress (it is suitable for image display). waitKey(0
将无限显示 window 直到任意按键(适用于图像显示)。
waitKey(25)
will display a frame for 25 ms
, after which display will be automatically closed. waitKey(25)
将显示一帧25 ms
,之后显示将自动关闭。 (If you put it in a loop to read videos, it will display the video frame-by-frame) (如果你把它放在一个循环中读取视频,它会逐帧显示视频)
See https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=waitkey请参阅https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=waitkey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.