Get grayscale image directly from webcam using Opencv

守給你的承諾、 提交于 2019-12-08 08:30:37

问题


Since in my embedded application I need images in grayscale, in order to save time I'm trying to get a frame from the webcam directly in grayscale without getting it from RGB format conversion.

The examples that I've found gets the frame in RGB and then converts it with

cvCvtColor(im_rgb,im_gray,CV_RGB2GRAY)  

Thanks.


回答1:


On Linux, simply use the v4l2-ctl command to reduce all saturation and get the camera to spit out grayscale output:

 v4l2-ctl -c saturation=0

Of course, that will work only if your webcam supports the saturation option. To check whether it does, take a look at all available controls:

v4l2-ctl -l



回答2:


In short, NO!

Most of the camera output are in YUV formats. The videoCapture function converts this to RGB. cvSetCaptureProperty function can be used to set the value of CV_CAP_PROP_CONVERT_RGB flag as FALSE. Thus the output will be in YUV. Converting this image to gray scale image.

By doing so, we could avoid the YUV-to-RGB conversion. And the YUV-to-Gray conversion is computationally less intensive as Y-channel is indeed the gray data. I am not so sure, will have to give it a try.



来源:https://stackoverflow.com/questions/21881299/get-grayscale-image-directly-from-webcam-using-opencv

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