我有一個非常簡單的程序上的OpenCV:如何讓Linux系統在OpenCV程序上等待?
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
void showVideo(CvCapture *video)
{
int width = (int) cvGetCaptureProperty(video, CV_CAP_PROP_FRAME_WIDTH);
int height = (int) cvGetCaptureProperty(video, CV_CAP_PROP_FRAME_HEIGHT);
//int fps = (int) cvGetCaptureProperty(video, CV_CAP_PROP_FPS);
IplImage* frame = cvCreateImage(cvSize(width, height), 8, 1);
cvNamedWindow("Showing Video:", 0);
while (true)
{
frame = cvQueryFrame(video);
cvShowImage("Showing Video:", frame);
cvWaitKey(10);
}
//cvDestroyWindow("Showing Video:");
//cvReleaseImage(&frame);
}
int main()
{
CvCapture *video = cvCaptureFromCAM(CV_CAP_ANY);
showVideo(video);
return 0;
}
我想有一個char ch;
像這樣while(ch != 'q')
東西然後它仍然播放視頻。有一些方法,如kbhit()
或getch()
,但它們不是標準的,我想要的東西,只要按下'q'鍵,然後顯示視頻將完成,否則視頻顯示將仍在運行。
我該怎麼做這份工作?