here’s the problem: I load an grayscale Image with OpenCV v.2.4.2.
Now I want to know for example value of pixel at position (0,0).
I’ve tried:
Mat image=imread("00001.jpg",1);
cvtColor(image,image,CV_RGB2GRAY);
int a=image.at<unsigned>(0,1);
printf("%d ",a);
This actually doesn’t work. How to get the pixel value with any data type (CV_8U, CV_32S …)?
Thanks!!!
You are making two mistakes here.
While reading the image, you are specifying 1 as input arguments. As explained for imread, the function can read image in three different formats.
for your case you will have to use
CV_LOAD_IMAGE_GRAYSCALEas the second argumentIn the next step where you are using:
image.at<unsigned>(0,1);which does not correspond to anything. you use<unsigned>but the compiler says “UNSIGNED? UNSIGNED what???”I believe a better way to do this is to use correct labels like
CV_LOAD_IMAGE_COLORorCV_LOAD_IMAGE_GRAYSCALE. In the example below, I am reading the image into one channel (CV_LOAD_IMAGE_GRAYSCALE), which automatically converts it to grayscale.