Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何每秒仅处理2帧?如何在c或c+中循环时退出+;?_C++_C_Opencv_Visual Studio 2012_Image Processing - Fatal编程技术网

C++ 如何每秒仅处理2帧?如何在c或c+中循环时退出+;?

C++ 如何每秒仅处理2帧?如何在c或c+中循环时退出+;?,c++,c,opencv,visual-studio-2012,image-processing,C++,C,Opencv,Visual Studio 2012,Image Processing,当我运行此代码并按键盘上的Esc键时,我无法退出循环。 我在另一个程序中使用相同的代码(在main()函数中)并退出while循环。 我不在main()函数中使用下面的代码。它是在main()中使用的函数调用的。 我想停止处理视频捕获和其他工作,我不想完全关闭程序。我只想每秒处理2帧,我怎么做? (在opencv 2.4.6、windows7、vs2012中从视频或cam捕获帧时) 请帮帮我 void Demo::processVideo() { VideoCapture cap(this-&g

当我运行此代码并按键盘上的Esc键时,我无法退出循环。 我在另一个程序中使用相同的代码(在main()函数中)并退出while循环。 我不在main()函数中使用下面的代码。它是在main()中使用的函数调用的。 我想停止处理视频捕获和其他工作,我不想完全关闭程序。我只想每秒处理2帧,我怎么做? (在opencv 2.4.6、windows7、vs2012中从视频或cam捕获帧时) 请帮帮我

void Demo::processVideo()
{
VideoCapture cap(this->videofile.c_str());
cout<<"Loading classifier...."<<endl;
MultiTrain mt;
mt.loadModel(("f:\dataset/eye_svm_model.xml"));
int fps=(int) cap.get(CV_CAP_PROP_FPS);
if(!cap.isOpened())
{
cout<<"problems with avi file"<<endl;
}
else
{
cout<<"Processing video...."<<endl;
Mat frame;
int k = 0,key1=0;
while(1)
{
//char c = WaitKey(15);
// if( c == 27 ) break;
cap>>frame;
int res = (int)mt.getPrediction(frame);
cout<<"Prediction for frame #"<<k<<" => "<<res<<endl;
this->predictions.push_back(res);
k++;
}
cap.release();
}

}
void Demo::processVideo()
{
VideoCapture(this->videofile.c_str());

cout这应该是一个类型转换问题,因为函数原型是
int-cvWaitKey(int)
在循环中尝试以下操作,然后按ESC退出程序

char c = cvWaitKey(15);
if( c == 27 ) break;

如果需要精确的时间控制或帧速率控制,可以计算时钟滴答声。有关示例的详细信息,请参阅。
祝你好运,快乐的编码。< /P>请使用OpenCV的C++ API,而不是过时的C。我需要你的帮助。除非你换成C++。请更改MeNoT。请更改我的C++。对于2个FPS,你需要等待500毫秒,但是WaigKi只工作,如果有一个高GUI窗口(它在窗口中等待按键)。(也许你有自己的gui),waitKey()永远找不到任何东西。嗨,eric。我使用你建议的代码,但我不能在循环时停止。我尝试cvWaitKey(0)但我无法停止,因为您是否在cvWindow中显示视频帧?我想从视频中捕获并处理这些帧,然后在另一个函数的窗口中显示结果,在这个函数中,我想从视频文件中抓取帧,直到我按下Esc键。按下Esc键后,我在另一个函数中显示结果