Ask Your Question
1

How to set camera format in OpenCV

asked 2015-10-22 17:24:00 -0600

vitruvius gravatar image

Hello,

I have a Logitech HD Pro Webcam C920, and it supports three formats: YUV4:2:2, H.264, and MJPEG. So I want to set its format to H.264 with OpenCV. How can I do that?

I can set height, width or some other properties of the frame with capture.set(), but I couldn't find any path for setting the format.

I am using OpenCV 2.4.11 and Visual Studio 2013.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-10-23 03:06:07 -0600

pklab gravatar image

H.264, and MJPEG are video codecs and can't apply to a single frame. In OpenCV you can save grabbed frames as video file with VideoWriter using all available codes on you computer.

YUV4:2:2 is an image format and it could be ok as grab format, but, I'm not sure, OpenCV grabs only in BGR format. You could play with grab properties mode and or frame format.

Look at the doc here and set desired properties after connection for frame size:

VideoCapture cap(0); // open the default camera
if(!cap.isOpened())  // check if we succeeded
  return -1;
// set frame size to 320x240 pix
cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);

For image format: Unfortunately properties aren't well documented, some of them are device dependant, you could to play around them to check if it's works

double grabMode,frameFormat,settings;
bool ok = false;
// Backed-specific value indicating the current capture mode.
grabMode = cap.get(CV_CAP_PROP_MODE);
// Format of the Mat objects returned by retrieve()
frameFormat = cap.get(CV_CAP_PROP_FORMAT); 
// Some available settings 
settings = cap.get(CV_CAP_PROP_SETTINGS);

// Playing around GRAB_MODE

// Boolean flags indicating whether images should be converted to RGB.
cap.set(CV_CAP_PROP_CONVERT_RGB, 0);
int i = -100;
while(ok == false && i<10)
{
 if (i != 0)
   ok = cap.set(CV_CAP_PROP_MODE, grabMode + i);
 i++;
}
if(ok)
{
 grabMode = cap.get(CV_CAP_PROP_MODE);
 cout << "Grab Mode=" << grabMode << " is supported" << endl;
}
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-10-22 17:24:00 -0600

Seen: 17,919 times

Last updated: Oct 23 '15