2

From my question, Can I determine the number of channels in cv::Mat Opencv

I am using the same code, to find the Laplacian of Gaussian of the image. The edges around the objects are well detected in the image.

How can I access the single element value of the final output image, abs_dst_gray?

I know I have to use the '.at' operator and I also found its datatype to be CV_8U. I tried the following

cout<<abs_dst_gray.at<uchar>(10,10)<<endl;

But using this method, I was not able to know what value it holds there. How can I find that value? If I use int or long, I end up with garbage values. I have always had this error and problem. Please help me here. I need those values so that I can try and determine the border values, given in the edges, which I can later use for segmentation purposes.

Milan
  • 1,743
  • 2
  • 13
  • 36
Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92

2 Answers2

5

You print the character not the integer representation. See:

cv::Mat img(3,3,CV_8U,cvScalar(123));
cout<<"Number "<<(int)img.at<uchar>(1,1)<<" represents ASCII character \""<<img.at<uchar>(1,1)<<"\"";

Output:

Number 123 represents ASCII character "{"

You can validate this fact here.

LovaBill
  • 5,107
  • 1
  • 24
  • 32
2

William already touched on this, but you want the numeric representation of the value in your matrix. Instead of casting it as suggested by William (which works!), you can simply request the data as an unsigned integer.

cout << abs_dst_gray.at<unsigned int>(10,10) << endl;
Chris
  • 4,663
  • 5
  • 24
  • 33