OpenCV Individual Pixel Access

255 Views Asked by At

I'm trying to learn OpenCV and have been going through various tutorials and books. I've ran into an odd problem. I have a 3 row, 3 column 3-channel matrix in OpenCV I named test. I filled it with dummy data like so:

Mat test(3,3, CV_8UC3, Scalar(50,100,200));

When I print out the matrix I get:

[[[50, 100, 200], [50, 100, 200], [50, 100, 200]], 
  [[50, 100, 200], [50, 100, 200], [50, 100, 200]], 
  [[50, 100, 200], [50, 100, 200], [50, 100, 200]]]

So far so good.

I want to access each individual RGB values for row 1, column 1. I read in the documentation and other answers on StackOverFlow to do the following for individual pixel access:
test.at(1,1)[0];

When I print out the values I get:

test.at<Vec3b>(1,1)[0] = 2
test.at<Vec3b>(1,1)[1] = d
test.at<Vec3b>(1,1)[2] = /310

Any ideas on what I'm doing wrong? I'm running OpenCV 2.10 on a Mac. Language is C++.

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

The values you are printing out are the ASCII characters for the integer values stored.

For example if you look up the ASCII table, say at this url, http://simple.wikipedia.org/wiki/ASCII

You will see that decimal 50 is equivalent to the character '2' and decimal 100 is 'd'.

In C++ you will get this result if you set a value into an int variable and then cast that int to a char.