Can I determine the number of channels in cv::Mat Opencv

后端 未结 2 709
既然无缘
既然无缘 2020-12-15 16:46

This maybe rudimentary, but is it possible to know how many channels a cv::Mat has? For eg, we load an RGB image, I know there are 3 channels. I do the followin

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 17:38

    Call Mat.channels() :

    cv::Mat img(1,1,CV_8U,cvScalar(0));
    std::cout<

    Output:

    1
    

    which is the number of channels.

    Also, try:

    std::cout<

    Output:

    0
    

    which belongs to CV_8U (look here at line 542). Study file types_c.h for each define.

提交回复
热议问题