问题
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 I was not able to know wat value it holds there, using this method. 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. Thanks in advance
回答1:
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.
回答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;
来源:https://stackoverflow.com/questions/17364987/knowing-the-value-of-an-mat-element-opencv