Ask Your Question
0

Using Mat.at<>() is giving me numbers much larger than 255.

asked 2012-09-16 20:39:58 -0600

ZachTM gravatar image

updated 2012-09-17 02:31:43 -0600

Hi guys I am trying to get the value of a single channel (greyscale matrix). WHen I output it i get a bunch of values like this :

 [26, 189, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 55, 0;
  70, 255, 18, 0, 0, 0, 0, 0, 0, 0, 0, 53, 212, 170, 0;
  79, 249, 6, 0, 0, 0, 0, 0, 0, 37, 176, 227, 101, 1, 0;
  99, 237, 0, 0, 0, 0, 0, 1, 106, 236, 121, 8, 0, 0, 0;
  125, 213, 0, 0, 0, 0, 28, 181, 206, 42, 0, 0, 0, 0, 0;
  150, 194, 0, 0, 10, 122, 235, 134, 7, 0, 0, 0, 0, 0, 0;
  150, 193, 0, 49, 217, 173, 38, 0, 0, 0, 0, 0, 0, 0, 0;
  169, 170, 92, 241, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  191, 252, 204, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  202, 255, 169, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  202, 158, 176, 215, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  203, 124, 0, 93, 242, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  202, 141, 0, 0, 52, 225, 150, 3, 0, 0, 0, 0, 0, 0, 0;
  202, 141, 0, 0, 0, 24, 213, 177, 22, 0, 0, 0, 0, 0, 0;
  202, 141, 0, 0, 0, 0, 10, 153, 222, 32, 0, 0, 0, 0, 0;
  181, 156, 0, 0, 0, 0, 0, 1, 135, 231, 77, 0, 0, 0, 0;
  176, 167, 0, 0, 0, 0, 0, 0, 0, 76, 225, 161, 7, 0, 0;
  159, 167, 0, 0, 0, 0, 0, 0, 0, 0, 19, 195, 185, 5, 0;
  196, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 208, 180, 28;
  12, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 141, 121]

Here is how i declare the matrix:

Mat downSize = Mat(20,15,CV_32F,Scalar(0));

The matrix get filled up with any non-zero values and still displays properly like I have shown above. Now I am trying to get the value of any pixel so I use Mat.at, but its giving me huge numbers and really small numbers and anything in between. Isnt CV_32F a float? I was using float, but when that didnt work I used every other type (unsigned short, signed short ... double) and I still get thes outrageous values. Does anyone know what my problem is?

Edit: The image values get set by:

resize(image,downSize,downSize.size(),0,0,INTER_AREA);

image is a larger greyscale image. The above grid of values is what gets outputted after this resize. with:

cout << downSize << endl;

By the way I am getting extremely small values too.

Or values like -2.14381e+09.

edit retag flag offensive close merge delete

Comments

Mat.at<>() just returns a reference to specified array element: http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=mat%3A%3Aat#mat-at. You declared downSize as a float matrix, so it has float elements (can be greater, than 255).

Daniil Osokin gravatar imageDaniil Osokin ( 2012-09-17 00:00:23 -0600 )edit

Thanks for your reply but I realize that. When I output the greyscale image I get nothing but values between 0 and 255. Yet when I output downSize.at<float>(row,col) i get values like -4.61972e-20

ZachTM gravatar imageZachTM ( 2012-09-17 00:10:43 -0600 )edit

What do you mean by grayscale image? Please, post some code. In example, that you wrote with downSize, I've got zeros.

Daniil Osokin gravatar imageDaniil Osokin ( 2012-09-17 00:31:33 -0600 )edit

I added more to the original question.

ZachTM gravatar imageZachTM ( 2012-09-17 02:32:20 -0600 )edit

Zach, it is impossible to understand your question. Could you please rewrite it from scratch in the following order: here is how I declare my Mat, here is how I fill it, here it is printed, here I call resize and get this. But I want to see that.

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-09-17 12:13:33 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-09-16 23:48:31 -0600

Daniil Osokin gravatar image

updated 2012-09-17 03:07:19 -0600

Hi! As I see, your source has type CV_U8C1, so you should use downSize.at<unsigned char>(row, column). Destination type isn't taken into account, as described here: resize.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-09-16 20:39:58 -0600

Seen: 1,737 times

Last updated: Sep 17 '12