본문 바로가기

Computer Vision by OpenCV

OpenCV Mat 이미지 형식 출력하기

반응형





Mat 클래스에 저장된 이미지의 타입을 출력하는 utility함수는 다음과 같다.


The following is a utility function you can use to identify the types of OpenCV matrices at run-time.



void showType(Mat &m) 
{
	string r;
	int type = m.type();

	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');

	printf("Matrix: %s %d(w)x%d(h) \n", r.c_str(), m.cols, m.rows);
}



반응형