简体   繁体   English

OpenCV网络摄像头MJPG低FPS

[英]OpenCV webcam MJPG low FPS

The problem is that I am keep getting low FPS from Logitech C270 webcam capture in OpenCV3. 问题是我从OpenCV3的Logitech C270网络摄像头捕获中获得的FPS一直很低。 Things i've tried are described in code comments 我尝试过的事情在代码注释中描述

Mat frame;
int main(int argc, char *argv[])

{
    // i've tried it this way
//int apiBackend = cv::CAP_DSHOW;
//cv::VideoCapture cap(0+apiBackend);

//and tis way
VideoCapture cap(0);
cap.open(0);

cap.set(CAP_PROP_FOURCC ,cv::VideoWriter::fourcc('M', 'J', 'P', 'G') );

//cap.set(CAP_PROP_EXPOSURE , 1); //changing this gives no result
//cap.set(CAP_PROP_GAIN , 10);    // same with this

cap.set(CAP_PROP_FPS, 100);
cap.set(CAP_PROP_FRAME_WIDTH, 640);
cap.set(CAP_PROP_FRAME_HEIGHT, 480);

while(1)
{
    float e1 = cv::getTickCount();

    cap >> frame; // get a new frame from camera

    imshow("frame", frame);

    float e2 = cv::getTickCount();
    float t = (e2 - e1)/cv::getTickFrequency();
    float fps = 1.0 / t;
    std::cout << fps << std::endl;

    if(waitKey(1) >= 0) break;
}

return 0;
}

Changing CAP_PROP_FPS to 5 works, and FPS drops ok. 将CAP_PROP_FPS更改为5可以工作,并且FPS可以正常运行。

Playing with resolution didn't help: from 320*240 to 1280*720 i keep getting about 16 FPS. 使用分辨率没有帮助:从320 * 240到1280 * 720,我一直保持约16 FPS的速度。

Webcam drivers are latest. 网络摄像头驱动程序是最新的。 Am i missing something? 我想念什么吗?

Thanks fo suggestions everybody! 谢谢大家的建议! Looks like the answer is camera-specific: i had to install Logitech Webcam Software and disable RightLight feature, now FPS is about 30. Maybe there is some way to disable RightLight from OpenCV using cap.set(...), but this is subject for further investigation. 看来答案是特定于摄像机的:我必须安装Logitech Webcam Software并禁用RightLight功能,现在FPS约为30。也许有一些方法可以使用cap.set(...)从OpenCV禁用RightLight,但这是进行进一步调查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM