【发布时间】:2020-10-14 14:44:36
【问题描述】:
我收到了一个 OpenCV 代码,它使用图片链接列表显示视频。 我想添加一个在循环的情况下使用键盘键停止视频的选项。 我进行了一些搜索并找到了“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;
【问题讨论】: