OpenCV type to str

简介

这是一个可以用于调试的函数,以整型类型作为输入,输出一个标识元素类型的字符串。

代码

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;
}

测试与结果

测试程序

Mat a(3,3,CV_8UC3);
cout << type2str(a.type()) << endl;

输出结果

8UC3

你可能感兴趣的:(调试,opencv)