如何在opencv中从受支持的网络摄像头获得超过30FPS的视频?

时间:2018-08-26 11:40:50

标签: opencv opencv3.0

我正在使用一个用于Aruco检测的网络摄像头,该摄像头使用YUY2捕获可以在640X480(MJPEG)或更低的分辨率下提供90FPS。

在OpenCV中,无论如何我都可以达到30 fps。 我确保将分辨率设置为640X480,然后再将FOURCC定义为MJPEG。

    inputVideo.open(camId);
    inputVideo.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
    inputVideo.set(cv::CAP_PROP_FRAME_HEIGHT, height);
    inputVideo.set(cv::CAP_PROP_FRAME_WIDTH, width);
    inputVideo.grab()
.
.
.

任何想法都可以使用OpenCV获得更高的FPS

更新

这是我用来抓取帧并计算FPS的代码

VideoCapture video2(0);

video2.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
video2.set(cv::CAP_PROP_FRAME_WIDTH, 640);  
int h = video2.get(CAP_PROP_FRAME_HEIGHT);
int w = video2.get(CAP_PROP_FRAME_WIDTH);

double fps = video2.get(CAP_PROP_FPS);      
cout << "Frames per second using video.get(CV_CAP_PROP_FPS) : " << w << " " << h << " " << fps << endl;

// Number of frames to capture
int num_frames = 120;

// Start and end times
time_t start, end;

// Variable for storing video frames
Mat frame;

cout << "Capturing " << num_frames << " frames" << endl;

// Start time
time(&start);

// Grab a few frames
for (int i = 0; i < num_frames; i++)
{
    video2 >> frame;
}

// End Time
time(&end);

// Time elapsed
double seconds = difftime(end, start);
cout << "Time taken : " << seconds << " seconds" << endl;

// Calculate frames per second
fps = num_frames / seconds;
cout << "Estimated frames per second : " << fps << endl;

// Release video
video2.release();
return 0;

0 个答案:

没有答案
相关问题