Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing 1080p at 30fps from logitech c920 with openCV 2.4.3

Tags:

I'm trying to capture the video stream off of my Logitech C920 in OpenCV. With Labview I can access an MJPG stream at 30fps 1080p. In opencv I am limited to either 5fps or 640x480.

Here is the code relevant to the camera settings:

this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, 1920); this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, 1080); this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G')); 

These all return 1, yet I get a 5fps stream of 1080p which corresponds to the YUY2 stream.
If I add the following line:

this->camRef.set(CV_CAP_PROP_FPS, 30); 

This returns 0. I get a 30 fps stream at 640x480. To me it looks like the MJPG setting isn't be accepted but I don't know what to do or how to fix that.

EDIT: The following crashes the program.

 this->camRef.read(this->image);  std::cout<< this->camRef.get(CV_CAP_PROP_FOURCC)                            << std::endl;  std::cout<< this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, config.width)         << std::endl;  std::cout<< this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, config.height)       << std::endl;  std::cout<< this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G')) << std::endl;  std::cout<< this->camRef.get(CV_CAP_PROP_FOURCC)                            << std::endl; 

Then in my run code I have the following:

void camera::run() {     while(true)     {         if(this->camRef.read(this->image) == 0)         {            if(this->capture)             {                 cv::imwrite(fileName,this->image);                 this->count++;             }         }         msleep(15);     } } 

EDIT2: Solution is to set the fourCC codec before setting camera height and width.

like image 255
Daniel Moodie Avatar asked Apr 18 '13 20:04

Daniel Moodie


People also ask

Is the Logitech C920 30fps?

Specifications. The Logitech C920 records in 1080p 30 FPS. Although the native Logi Capture app allows you to set it to “60 FPS”, this really just make the webcam duplicate each frame. It has a 78 degree field of view.

Can Logitech C920 do 60FPS?

Serious streaming webcam. Hyper-fast HD 720p at 60fps.


1 Answers

As the author of the post already found the solution but didn't add it as an answer I will put the solution here.

You have to set the codec before you set the wanted resolution:

this->camRef.set(CV_CAP_PROP_FOURCC,CV_FOURCC('M','J','P','G')); this->camRef.set(CV_CAP_PROP_FRAME_WIDTH, 1920); this->camRef.set(CV_CAP_PROP_FRAME_HEIGHT, 1080); 
like image 90
2 revs, 2 users 92% Avatar answered Nov 05 '22 05:11

2 revs, 2 users 92%