I have a very simple program on 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;
}
I want to have a char ch; and something like this while(ch != 'q') then it still plays the video. There is some ways such as kbhit() or getch() but they are not standard and I want something that whenever the ‘q’ key is pressed, then the showing the video will finish, otherwise video showing will be still running.
How can I do this job?
cvWaitKey() returns 0 if no key was pressed in the allotted time or the key code if a key is pressed. Change your call to cvWaitKey() to test the return value like this: