user9507127
user9507127

Reputation:

Get type of mat

I'd like to check if a matrix is converted 2GRAY.

So this code should return false

cv::Mat myImage; // (rgb)
cout << isMatGray(myImage) << endl;

while this code should return true

cv::Mat myImage; // (rgb)
cv::cvtColor(myImage, myImage, CV_RGB2GRAY);
cout << isMatGray(myImage) << endl;

My idea was using the .type() call but I'm not really sure how to use this function the right way.

static bool isMatGray(cv::Mat image) {
   return ( image.type() == ?? );
}

Upvotes: 0

Views: 129

Answers (1)

Miki
Miki

Reputation: 41765

You can check if the matrix is gray scale (i.e. single channel) with:

static bool isMatGray(const cv::Mat& image) {
   return (image.channels() == 1);
}

Upvotes: 3

Related Questions