简体   繁体   中英

OpenCV webcam MJPG low FPS

The problem is that I am keep getting low FPS from Logitech C270 webcam capture in OpenCV3. 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.

Playing with resolution didn't help: from 320*240 to 1280*720 i keep getting about 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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