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

后端 未结 2 703
既然无缘
既然无缘 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条回答
  • you might use:

    Mat::channels()
    

    http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-channels

    0 讨论(0)
  • 2020-12-15 17:38

    Call Mat.channels() :

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

    Output:

    1
    

    which is the number of channels.

    Also, try:

    std::cout<<img.type();
    

    Output:

    0
    

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

    0 讨论(0)
提交回复
热议问题