zl程序教程

您现在的位置是:首页 >  后端

当前栏目

OpenCV显示图像Type位深度输出

Opencv输出 显示 深度 图像 type
2023-09-27 14:25:48 时间

直接给出代码:

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

输出结果: