오류 내용

at을 이용해서 이미지의 픽셀값을 얻어온 후 c++의 표준입출력함수인 cout을 이용하여 출력할 때 쓰레기값이 출력됨

 

std::cout << img.at<cv::Vec3b>(1000,1000)[0] << std::endl;
std::cout << img.at<cv::Vec3b>(1000,1000)[1] << std::endl;
std::cout << img.at<cv::Vec3b>(1000,1000)[2] << std::endl;

/* 출력 결과 */
N2cv3MatE
3
]

 

해결방법

이유는 모르겠으나 C++의 cout이 아닌 C의 printf를 사용하면 정상적으로 출력된다.

uchar a = img.at<cv::Vec3b>(1000,1000)[0];
printf("value : %d", a);

/*	출력결과 */
value : 93