Reputation: 1
I laod the image (png) file directly from 3 channel to 1 channel using imread(.., ...-GRAYSCAle), I can see the image on grayscale but the pixel value is 0, not 1. any help is appreciated!
cv::Mat image=cv::imread(filename1, CV_LOAD_IMAGE_GRAYSCALE);
if (!image.data){
std::cout<<"Problem laoding image";
}
cv::namedWindow("Window1");
cv::imshow("Window1",image);
for (i=0;i<720;i++){
for (j=0;j<720;j++){
std::cout<<image.at<int>(j,i)<<std::endl;
//printf("%d \t", vPixel);
}
}
Upvotes: 0
Views: 182
Reputation: 1227
OpenCV loads image as CV_8UCX (in your case, it would be CV_8UC1) type. So to print all pixel values, you should call at()
with template argument unsigned char
or uchar
:
for (int i = 0;i < image.rows; i++) {
for (int j = 0; j < image.cols; j++) {
std::cout<<image.at<uchar>(i, j)<<std::endl;
}
}
Upvotes: 1