gbt
gbt

Reputation: 809

why should I use (y,x) instead of (x,y) to access a pixel in opencv?

I had to access a pixel into an image, using openCV but at first I wasn't able since python was telling me that the value I wanted to access was out of bound.

Then I searched for this error and I discovered that I should access a pixel using image[y, x] instead of image[x, y].

I found this piece of information in the comments of this page, but there is no explanation: https://www.pyimagesearch.com/2016/02/01/opencv-center-of-contour/

Adrian Rosebrock February 12, 2016 at 3:19 pm #: When accessing pixel values in OpenCV + NumPy, you actually specify them in (y, x) order rather than (x, y) order. Thus, you need to use: image[cY, cX]

So, the question is...why should I invert the coordinates while trying to access a pixel?

Upvotes: 3

Views: 3036

Answers (1)

gbt
gbt

Reputation: 809

find the answer in the comments. It is related to how a language store matrices:

Apart from Fortran, most languages store matrices in row-major order, so the indices are row, column, aka y, x. – Paul R Feb 6 at 8:30

Upvotes: 2

Related Questions