Access to each separate channel in OpenCV

后端 未结 5 1102
执念已碎
执念已碎 2021-01-01 10:06

I have an image with 3 channels (img) and another one with a single channel (ch1).

    Mat img(5,5,CV_64FC3);
    Mat ch1 (5,5,CV_64FC1);

I

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 11:07

    In fact, if you just want to copy one of the channels or split the color image in 3 different channels, CvSplit() is more appropriate (I mean simple to use).

    Mat img(5,5,CV_64FC3);
    Mat ch1, ch2, ch3;
    // "channels" is a vector of 3 Mat arrays:
    vector channels(3);
    // split img:
    split(img, channels);
    // get the channels (dont forget they follow BGR order in OpenCV)
    ch1 = channels[0];
    ch2 = channels[1];
    ch3 = channels[2];
    

提交回复
热议问题