c++ - OpenCV Display Pixels Value -
i have below code. when run program, unknown characters instead of pixel values comes screen. want display pixel values. how do this? thank you.
#include <opencv2/opencv.hpp> #include <opencv2/highgui.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main() { mat image = imread("/home/fd/baby.jpg"); for( int = 0 ; < image.rows ; i++) { for( int j = 0 ; j < image.cols ; j++ ) { if(image.type() == cv_8uc1) { image.at<uchar>(i,j) = 255; } else if(image.type() == cv_8uc3) { cout << image.at<vec3b>(i,j)[0] << " " << image.at<vec3b>(i,j)[1] << " " << image.at<vec3b>(i,j)[2] << endl; image.at<vec3b>(i,j)[0] = 255; image.at<vec3b>(i,j)[1] = 255; image.at<vec3b>(i,j)[2] = 255; cout << image.at<vec3b>(i,j)[0] << " " << image.at<vec3b>(i,j)[1] << " " << image.at<vec3b>(i,j)[2] << endl; } else { cout << "anknown image format" << endl; return 0; } } } imshow("result İmage", image); waitkey(0); }
this result screen:
cast each of outputs integer
<< image.at<vec3b>(i,j)[0] ...
change to
<< (int)image.at<vec3b>(i,j)[0] ...
you printing char
(or unsigned char
) printed through stream single character (which @ 255 looks see). cast int
forces display numerical representation of value.
the other answers changing image.at<type>
changes how raw data interpreted; don't that. must interpreted properly.
Comments
Post a Comment