在OpenCV中打印CV_8UC4矩阵类型的值
我试图打印从图像文件(类型为CV_8UC4)中作为输入的矩阵值。我的代码写在下面。我的问题是我得到的值只有48和255,而我期望的值是2和1,或者别的什么。有人知道为什么吗?我想我用错误的方式打印了这些值。是否有其他方法打印CV_8UC4的值。 我的代码是:在OpenCV中打印CV_8UC4矩阵类型的值,c,opencv,image-processing,C,Opencv,Image Processing,我试图打印从图像文件(类型为CV_8UC4)中作为输入的矩阵值。我的代码写在下面。我的问题是我得到的值只有48和255,而我期望的值是2和1,或者别的什么。有人知道为什么吗?我想我用错误的方式打印了这些值。是否有其他方法打印CV_8UC4的值。 我的代码是: CvMat* m1 = cvLoadImageM(argv[1], CV_LOAD_IMAGE_UNCHANGED); // load the matrix from an image file cv::Mat m1cpp(m1); int
CvMat* m1 = cvLoadImageM(argv[1], CV_LOAD_IMAGE_UNCHANGED); // load the matrix from an image file
cv::Mat m1cpp(m1);
int type = m1cpp.type();
printf( " type is %d ", type );
switch( type ) {
case 24:
printf("\n --> Matrix type is CV_8U \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %d ", m1cpp.at<uchar>(i,j) );
} printf("\n");
}
break;
case 25:
printf("\n --> Matrix type is CV_8S \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %d ", m1cpp.at<schar>(i,j) );
} printf("\n");
}
break;
case 18:
printf("\n --> Matrix type is CV_16U \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %d ", m1cpp.at<ushort>(i,j) );
} printf("\n");
}
break;
case 27:
printf("\n --> Matrix type is CV_16S \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %d ", m1cpp.at<short>(i,j) );
} printf("\n");
}
break;
case 28:
printf("\n --> Matrix type is CV_32S \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %d ", m1cpp.at<int>(i,j) );
} printf("\n");
}
break;
case 29:
printf("\n --> Matrix type is CV_32F \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %.3f ", m1cpp.at<float>(i,j) );
} printf("\n");
}
break;
case 30:
printf("\n --> Matrix type is CV_64F \n");
for( size_t i = 0; i < m1cpp.rows; i++ ) {
for( size_t j = 0; j < m1cpp.cols; j++ ) {
printf( " %.3f ", m1cpp.at<double>(i,j) );
} printf("\n");
}
break;
default:
printf("\n --> Matrix type not found \n");
}
我的案例是24,我得到的有线值是48和255。是否有其他方法打印CV_8UC4值?正确访问您的CV_8UC4矩阵:
image.at<cv::Vec4b>(j,i)[0];
image.at<cv::Vec4b>(j,i)[1];
image.at<cv::Vec4b>(j,i)[2];
image.at<cv::Vec4b>(j,i)[3];
正确访问您的简历表:
image.at<cv::Vec4b>(j,i)[0];
image.at<cv::Vec4b>(j,i)[1];
image.at<cv::Vec4b>(j,i)[2];
image.at<cv::Vec4b>(j,i)[3];
是的,我尝试在4个不同的语句中打印值,但仍然只能得到48和255个值。我尝试在4个不同的语句中打印值,但仍然只能得到48和255个值