[英]OpenCV: What is the limitation for the poor framerate?
Using OpenCV 2.4.3.2 on Ubuntu 12.10 with a PS3-Eye camera I'm not able to capture more than ~60 frames per second (FPS). 在Ubuntu 12.10上使用带有PS3-Eye摄像机的OpenCV 2.4.3.2, 我无法捕获超过每秒60帧 (FPS)的图像。 The camera itself delivers up to 125 FPS.
相机本身可提供高达125 FPS的速度。 I would like to know what limits the framerate in OpenCV.
我想知道什么限制了OpenCV中的帧率。 So here is what I did so far:
所以这是我到目前为止所做的:
#include <sys/time.h>
#include <time.h>
#include <iostream> // for standard I/O
using cv;
using std;
long time_diff( const timespec &t1, const timespec &t2 ) {
return (long)(t2.tv_sec-t1.tv_sec)*1000000000 + (t2.tv_nsec-t1.tv_nsec);
}
int main(int argc, char *argv[]) {
VideoCapture cap(0); // open the default camera
cap.set(CV_CAP_PROP_EXPOSURE, 0);
cap.set(CV_CAP_PROP_FPS, 125);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame;
timespec t_start, t_end;
for(int i=1;;++i) {
cap >> frame;
clock_gettime(CLOCK_REALTIME, &t_end);
if( i%20==0 )
std::cout << "FPS ~= " << time_diff(t_start, t_end) << std::endl;
clock_gettime(CLOCK_REALTIME, &t_start);
}
}
This outputs the framerate every 20 frames to stdout. 这样每20帧将帧速率输出到stdout。 Note that I had to patch the source to be able to set the framerate correctly for the PS3-Eye camera.
请注意,我必须修补源以能够正确设置PS3-Eye摄像机的帧频。
First I set the framerate to 30 ( cap.set(CV_CAP_PROP_FPS, 30);
) to verify that my measurement is correct. 首先,我将帧速率设置为30(
cap.set(CV_CAP_PROP_FPS, 30);
)以验证我的测量是正确的。 Then using higher framerates the reported framerate is capped at ~60 FPS . 然后使用更高的帧速率,报告的帧速率上限为〜60 FPS 。
The USB is not the problem because I can get the full 120 FPS with guvcview
. USB不是问题,因为我可以用
guvcview
获得完整的120 FPS。
I modified the code above to use grab()
and retrieve()
like this: 我修改了上面的代码以使用
grab()
和retrieve()
如下所示:
clock_gettime(ClOCK_REALTIME, &t_start);
cap->grab();
clock_gettime(ClOCK_REALTIME, &t_end);
cap->retrieve(frame);
but the framerate is capped again at ~60 FPS . 但帧率又被限制在〜60 FPS 。
So how can I tell what is limiting the framerate? 那我怎么知道是什么限制了帧速率呢?
After switching to a desktop machine (from laptop) I was able to capture the full framerate. 切换到台式机(从笔记本电脑)后,我可以捕获整个帧速率。 It seems OpenCVs capture implementation is not as efficient as the one in guvcview.
看来OpenCV的捕获实现不如guvcview中的捕获实现高效。
I have same issue with 65 FPS limit in win7 x64 with OpenCV and Delphi X6. 我在带有OpenCV和Delphi X6的win7 x64中具有65 FPS限制的相同问题。 Founded problem is in cvWaitKey or/and Windows message queue, which limits redraws in 65 Hz.
找到的问题在cvWaitKey或/和Windows消息队列中,该问题将重绘限制为65 Hz。 The solution - to call cvWaitKey less frequently, less 65 times per second.
解决方案-减少调用cvWaitKey的频率,减少每秒65次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.