我正在用OpenCV在C++应用程序中从摄像头上捕捉帧,无论是在我的Windows机器上还是在RaspberryPi (ARM,Debian )上。问题在于CPU的使用。我只需要处理帧像每2秒-所以没有实时实时视图。但如何做到这一点呢?你建议哪一个?
提前感谢
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <unistd.h>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
cv::VideoCapture cap(0); //0=default, -1=any camera, 1..99=your camera
if(!cap.isOpened())
{
cout << "No camera detected" << endl;
return 0;
}
// set resolution & frame rate (FPS)
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
cap.set(CV_CAP_PROP_FPS, 5);
int i = 0;
cv::Mat frame;
for(;;)
{
if (!cap.grab())
continue;
// Version 1: dismiss frames
i++;
if (i % 50 != 0)
continue;
if( !cap.retrieve(frame) || frame.empty() )
continue;
// ToDo: manipulate your frame (image processing)
if(cv::waitKey(255) ==27)
break; // stop on ESC key
// Version 2: sleep
//sleep(1);
}
return 0;
}发布于 2013-06-10 23:32:15
在Windows上,这可能有点麻烦(在其他操作系统上也是如此)--创建VideoCapture后抢占的第一帧通常是黑色或灰色的。第二帧应该很好:)
其他想法:
https://stackoverflow.com/questions/17027085
复制相似问题