Get grayscale image directly from webcam using Ope

2019-06-07 16:50发布

问题:

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.