Last active
December 6, 2016 08:22
-
-
Save udaya1223/ce25070810ae68c0a9c0ded137418097 to your computer and use it in GitHub Desktop.
Print OpenCV single channel Mat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _PrintMatrix(char *pMessage, cv::Mat &mat) | |
{ | |
printf("%s\n", pMessage); | |
for (int r = 0; r < mat.rows; r++) { | |
for (int c = 0; c < mat.cols; c++) { | |
switch (mat.depth()) | |
{ | |
case CV_8U: | |
{ | |
printf("%*u ", 3, mat.at<uchar>(r, c)); | |
break; | |
} | |
case CV_8S: | |
{ | |
printf("%*hhd ", 4, mat.at<schar>(r, c)); | |
break; | |
} | |
case CV_16U: | |
{ | |
printf("%*hu ", 5, mat.at<ushort>(r, c)); | |
break; | |
} | |
case CV_16S: | |
{ | |
printf("%*hd ", 6, mat.at<short>(r, c)); | |
break; | |
} | |
case CV_32S: | |
{ | |
printf("%*d ", 6, mat.at<int>(r, c)); | |
break; | |
} | |
case CV_32F: | |
{ | |
printf("%*.4f ", 10, mat.at<float>(r, c)); | |
break; | |
} | |
case CV_64F: | |
{ | |
printf("%*.4f ", 10, mat.at<double>(r, c)); | |
break; | |
} | |
} | |
} printf("\n"); | |
} printf("\n"); | |
} | |
int main(void){ | |
Mat a = Mat(3, 3, CV_8U, Scalar(255)); | |
_PrintMatrix("CV_8U", a); | |
a = Mat(3, 3, CV_8S, Scalar(-127)); | |
_PrintMatrix("CV_8S", a); | |
a = Mat(3, 3, CV_16U, Scalar(65535)); | |
_PrintMatrix("CV_16U", a); | |
a = Mat(3, 3, CV_16S, Scalar(-32768)); | |
_PrintMatrix("CV_16S", a); | |
a = Mat::eye(3, 3, CV_32S); | |
_PrintMatrix("CV_32S", a); | |
a = Mat::eye(3, 3, CV_32F); | |
_PrintMatrix("CV_32F", a); | |
a = Mat::eye(3, 3, CV_64F); | |
_PrintMatrix("CV_64F", a); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment