Problem with webcam C922 to configure 60 FPS 720p

Hello, this is my first topic and I don’t have a lot experience with advance OpenCV features and C++ but I try to understand, so. I have a problem with the Logitech c922 webcam to set CAP_PROP_FPS to 60 FPS. I use Visual Studio 2019 or Code Blocks IDE with C++. I read some posts, but the proposed solutions can not help me. I’m trying to run C922 at 60 FPS 720p for the realtime app. This is my code in C++ and I try the same with python and OpenCV but I have the same problem. Can someone help me please? Sorry for my English.

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()

    VideoCapture capture; + 1 + CAP_DSHOW);
    int codec = VideoWriter::fourcc('M', 'J', 'P', 'G');
    capture.set(CAP_PROP_FOURCC, codec);
    capture.set(CAP_PROP_FPS, 60);
    capture.set(CAP_PROP_FRAME_WIDTH, 1280);
    capture.set(CAP_PROP_FRAME_HEIGHT, 720);

    capture.set(CAP_PROP_AUTOFOCUS, 0);            
    capture.set(CAP_PROP_FOCUS, 25);                  /
    capture.set(CAP_PROP_AUTO_EXPOSURE, 0);        
    capture.set(CAP_PROP_EXPOSURE, -7);     
    int64 counter = 0;
    double elapsed = 0, fps = 0;
    int64 start = getTickCount();
    Mat frame;
    while (capture.isOpened())

        capture >> frame;
        int64 delta = getTickCount() - start;

        double freq = getTickFrequency();
        double elap = delta / freq;

        counter += 1;

        if (elap > 1)
            fps = counter / elap;
            elapsed = elap / fps;
            counter = 0;
            start = getTickCount();

        string text = cv::format("Elapsed time: %.3f s - FPS: %.2f", elapsed, fps);

        int baseline = 0;
        Size sizee = cv::getTextSize(text, FONT_HERSHEY_PLAIN, 1.0, 1, &baseline);

        cv::rectangle(frame, cv::Rect(5, 5, sizee.width + 10, sizee.height + 10), Scalar(0, 128, 128), FILLED, LINE_AA);
        cv::putText(frame, text, Point(10, sizee.height + 10), FONT_HERSHEY_PLAIN, 1.0, Scalar(255, 255, 255), 1, LINE_AA);
        cv::namedWindow("face", WINDOW_AUTOSIZE);
        cv::imshow("face", frame);

        if (waitKey(1) == 27) break;

please do not.

do this instead:

open(1, CAP_DSHOW)

apart from that, the code should run fast enough… profile it, figure out where it spends time. getTickCount is ok to use for that.

you can also try pollKey() instead of waitKey… I’d recommend trying it.

and verify that you can actually get 60 fps from the camera under the current lighting conditions. these cameras, in a dark scene, throttle the frame rate to get longer exposure times to combat image noise.

1 Like

Hi crackwitz! Thank you for reply to me. I try with open(1, CAP_DSHOW) but is the same, and check pollKey() instead of waitKey() and it is the same. About the lighting condition, I use some leds to control lighting and is is constant, I know that with a longer exposure time the FPS are less.

a few LEDs won’t be enough. try daylight. and vary the exposure parameter.

play around with this using OBS Studio or another program. then you know it’s not an OpenCV issue.

I don’t understand :

    capture.set(CAP_PROP_FOURCC, codec); ??
    capture.set(CAP_PROP_FPS, 60); ??

    capture.set(CAP_PROP_AUTO_EXPOSURE, 0);        
    capture.set(CAP_PROP_EXPOSURE, -7);    

CAP_PROP_FOURCC and CAP_PROP_FPS is usually used for videowritter not for VideoCapture (C922 is USB camera not a IP camera)
if you use CAP_PROP_AUTO_EXPOSURE why use CAP_PROP_EXPOSURE ? (-7 why try -20 )

try you camera outside with a sunny weather and it should work

no, it is regularly used for VideoCapture, to ask for MJPEG instead of something uncompressed, and to select one of the various frame rates that most cameras can do, yes even webcams.

that disables autoexposure, before setting exposure manually.

May be you try

fourcc = cv.VideoWriter_fourcc(*'MJPG')
v.set(cv.CAP_PROP_FOURCC, fourcc)

Last result is it true or False on logitech c922?

If i believe this c922-mod/c922 at master · ServusCarolus/c922-mod · GitHub time exposure must be positive for c922

you don’t need to suggest that to me. I can’t speak for the C922 but I can speak for the C920. it has an effect there. your point was that it’s questionable in general to try that on a webcam.

Hi! I use 60 leds inside of a small environment. I don’t have a problem with the lighting condition. I think that the lighting is sufficient and I can use a low value of exposure. I tried with OBS and you have reason, I can use 60 FPS with OBS but I can’t use 60 FPS with OpenCV, I think that maybe it is my OpenCV but I don’t now.

Hi Laurent, Thank you for reply to me. I check your link [c922-mod/c922 at master · ServusCarolus/c922-mod · GitHub] (c922-mod/c922 at master · ServusCarolus/c922-mod · GitHub), but I can’t understand everything, could you explain to me more please?. I use C++ but I can’t understand your code I am sorry.

If I use a positive exposure value the FPS are lower than with a negative exposure value and I tried to run my code without CAP_PROP_FOURCC and it is the same result, I can’t configurate c922 at 60 FPS.

Have you got API for c922?
For old logitech only doc I found it’s here
In v4l link may be time is translated in good unit.
Now I beleive old doc

capture.set(CAP_PROP_EXPOSURE, -7);  

try -14