Skip to content

Instantly share code, notes, and snippets.

@sgarciav
Created March 15, 2021 22:05
Show Gist options
  • Save sgarciav/795acdce116678265d7514d1ccf799a3 to your computer and use it in GitHub Desktop.
Save sgarciav/795acdce116678265d7514d1ccf799a3 to your computer and use it in GitHub Desktop.
Determine the type of cv::Mat
// previously defined
cv::Mat cv_matrix;
std::string r;
int type = cv_matrix.type();
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch ( depth ) {
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
case CV_16S: r = "16S"; break;
case CV_32S: r = "32S"; break;
case CV_32F: r = "32F"; break;
case CV_64F: r = "64F"; break;
default: r = "User"; break;
}
r += "C";
r += (chans+'0');
// display result
std::cout << "type: " << r.c_str() << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment