タイプ CV_8UC4 の画像ファイルから入力として取得した行列の値を印刷しようとしています。私のコードは以下に書かれています。私の問題は、2 と 1 または何かの値を期待していたのに、48 と 255 の値しか得られないことです。誰かが理由を知っていますか? 値を間違った方法で出力していると思います。CV_8UC4 の値を出力する他の方法はありますか。私のコードは次のとおりです。
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 の値を出力する他の方法はありますか?