OpenCV顯示圖像type位深度輸出


直接給出代碼:

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

輸出結果:

 

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM