Search code examples
c++linuxopencvwebcamgrayscale

Get grayscale image directly from webcam using Opencv


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.


Solution

  • 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