Can I set the color depth while capturing the webcam image using OpenCV?

安稳与你 提交于 2020-01-11 11:44:46

问题


I am capturing the image using OpenCV in C++

firstFrame = cvQueryFrame(capture);

it is easy to set the width and height properties by

cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, WIDTH );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, HEIGHT );

I wonder if there is a way to specify the color depth as well without further processing the frame?


回答1:


According to the documentation, you should be able to do it using CV_CAP_PROP_FORMAT if you use the function retrive() to get your frame.

CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .

However, notice also that:

When querying a property that is not supported by the backend used by the VideoCapture class, value 0 is returned.




回答2:


Have forked a seperate branch on github, with changes to videoio to support custom streams & formats.

Git hub repo link

https://github.com/shawndfernandes/opencv

Added support for custom stream & depth for opencv capture, reverts to default opencv values if not set.

Set via VideoWriter::set method

CV_CAP_PROP_DEPTH

matrix_depth = 8,16 //* for 8U and 16 for 16U depth

CV_CAP_PROP_STREAM

stream_format = 1,2,3,4,5…12; //choose the raw camera stream via V4L

"BGR24" 1:

"YVU420" 2:

"YUV411P" 3:

"MJPEG" 4:

"JPEG" 5:

"YUYV" 6:

"UYVY" 7:

"SN9C10X" 8:

"SBGGR8" 9:

"SGBRG8" 10:

"RGB24" 11:

"Y16" 12:



来源:https://stackoverflow.com/questions/21555572/can-i-set-the-color-depth-while-capturing-the-webcam-image-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!