2

I would like to capture images with a webcam (i.e. logitech C922) with C++. Does anyone succeed in capturing images with the webcam at 60fps and 720p? I read the code in the following thread and add "cap.set(CAP_PROP_FPS, 60)", but the frame rate was maintained at about 30fps. How to set camera fps in opencv?

Then I posted the same question, but the forum is under maintenance. http://answers.opencv.org/question/172992/streaming-logitec-c922-at-60fps-with-c/ I added the both proposed codes to mine. As the result, the value of fps was 33.3... and FPS was 60.0 in the case that I used cap.set(CAP_PROP_EXPOSURE, -5) because I'm in office and at night here. I tried to use lower value for CAP_PROP_EXPOSURE (e.g. -10), but the fps didn't change. The image shown with imshow wasn't updated obviously at 60fps. Is there anything I can do?

This is the code I used.

VideoCapture cap(0); //capture the video from web cam

if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the web cam" << endl;
    return -1;
}
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
cap.set(CAP_PROP_FPS, 60);
cap.set(CAP_PROP_EXPOSURE, -5);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

cout << cap.get(CAP_PROP_FPS) << endl;

cvNamedWindow("img");
time_t cap_start, cap_end;
Mat frame;
double MAX_FRAME_NUM = 100;
time(&cap_start);
for (int n = 0; n < MAX_FRAME_NUM; n++) {
    cap >> frame;
}
time(&cap_end);
double fps = MAX_FRAME_NUM / difftime(cap_end, cap_start);
cout << "fps:" << fps << endl;
cv::waitKey(0);

Environment Information OpenCv: 3.3.0 OS: Windows 10 Pro IDE: Visual Studio 2017 CPU: i7-7560U RAM 16GB USB: 3.0

Best regards, gellpro

gellpro
  • 51
  • 1
  • 6
  • Huh? There is no `imshow()` in your code. Also, 100 frames at 60fps is less than 2s of recording which is not a good test if there is, say, a 2s startup delay - so you should average over more frames. – Mark Setchell Aug 25 '17 at 19:53
  • Hi, Mark Thank you for your reply. I modified the code and add 3s delay for wainting for setup. After that, I calculate the average with 600 frames. As the result, the fps is 33.33. Additionally, I checked a while loop for imshow and calculated the fps in it for every frames. The fps are 34, 83,34,55,90,100,34,90,58,76,333,55,47,43,38... The fps isn't stable at all although the light condition doesn't change in my office. It seems that the fps is fundamentally much lower than 60fps. – gellpro Aug 25 '17 at 21:28
  • Mmmm... it looks like there is little support from Logitech for the C922. Their Support offering seems to be a broken record that only says "tough luck"... https://community.logitech.com/s/question/0D53100005mTv7SCAS/why-no-sdk-for-webcams and https://community.logitech.com/s/question/0D53100006TjpE7CAJ/c920-sdk and so on... – Mark Setchell Aug 26 '17 at 22:19
  • http://support.logitech.com/en_us/article/Maintain-a-constant-720p-60fps-stream – Mark Setchell Aug 27 '17 at 21:05
  • Hi, Mark. Thank you for your reply. I inquired of Logicool which is the name of Logitech in Japan this problem. If I got the answer from them, I'll share it here. – gellpro Aug 30 '17 at 20:44

1 Answers1

0

I stumbled upon the same issue with this camera. My environment is Ubuntu 18.04, python 3.6.5 and OpenCV 3.4.

I found this solution from your first link to be working:

cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

For python, the code I use is:

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G'))
cap.set(cv2.CAP_PROP_FPS, 60)
lehippie
  • 1
  • 2