2013-07-19 2 views
1

CV_8UC4 유형의 이미지 파일에서 입력으로 가져온 행렬의 값을 인쇄하려고합니다. 내 코드는 아래와 같습니다. 내 문제는 2, 1 등의 값을 기대하는 반면 나는 단지 48과 255의 값을 얻는다는 것입니다. 아무도 이유를 알고 있습니까? 나는 잘못된 방식으로 값을 인쇄하고 있다고 생각합니다. CV_8UC4의 값을 인쇄하는 다른 방법이 있습니까? 내 코드는 다음과 같습니다OpenCV에서 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 값을 인쇄 할 다른 방법이 있나요? 제대로

답변

5

에 액세스합니다 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]; 
+0

그래 난 4 다른 문에서 값을 인쇄하려고했지만 여전히 48 ~ 255 값을 받고 – user227666

관련 문제