直接给出代码:
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
string Type2String(int type)
{
string strType;
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch (depth)
{
case CV_8U:
strType = "CV_8U"; break;
case CV_8S:
strType = "CV_8S"; break;
case CV_16U:
strType = "CV_16U"; break;
case CV_16S:
strType = "CV_16S"; break;
case CV_32S:
strType = "CV_32S"; break;
case CV_32F:
strType = "CV_32F"; break;
case CV_64F:
strType = "CV_64F"; break;
default:
strType = "UNKNOWN_TYPE"; break;
}
strType += "C";
strType += (chans + '0');
return strType;
}
void main()
{
Mat img = imread("1.tif", IMREAD_UNCHANGED);
cout << img.type() << endl;
cout << Type2String(img.type()) << endl;
}
输出结果: