Here is a handy feature that you can use to help identify your opencv matrices at runtime. I find this useful for debugging, at least.
string type2str(int type) { string r; 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'); return r; }
If M is a var of type Mat , you can call it like this:
string ty = type2str( M.type() ); printf("Matrix: %s %dx%d \n", ty.c_str(), M.cols, M.rows );
Print data such as:
Matrix: 8UC3 640x480 Matrix: 64FC1 3x2
It is worth noting that there are also Matrix methods Mat::depth() and Mat::channels() . This function is just a convenient way to get a human-readable interpretation from a combination of these two values, whose bits are stored in the same value.
Octopus Jul 23 '13 at 20:40 2013-07-23 20:40
source share