Search code examples
c++opencvhsv

Separate hsv channels in opencv


I am having an hsv mat file in opencv and I want to separate the channels. I found cvSplit( hsv, h, s, v, NULL ), but it doesn't work with Mat files. How is it then, to keep just the first channel h of from the Mat image file?? My result is the above. Basically is the image that I convert, I can see the face but in weird tones.

h channel

The code used:

    cvtColor(cropped_rgb, cropped_hsv, CV_BGR2HSV);
    split(cropped_hsv, channels);
    cropped_hsv = channels[0]; 
    imshow("cropped_hsv", cropped_hsv);

Solution

  • You can simply use split:

    Mat hsv;
    vector<Mat> channels;
    split(hsv, channels);
    

    channels[0], channels[1], channels[2] will contain your H, S, V respectively.