The relationship between the image coordinate system in OpenCV and NumPy Arrays in Python

The relationship between the image coordinate system in OpenCV and NumPy Arrays in Python

Foreword:

The coordinate system of OpenCV is different from that of numpy. The coordinates (x, y) are often obtained, and the problem of inverted coordinates will occur if they are directly substituted.
And before, I could only determine through temporary debugging, whether my coordinates are correct.
This makes me very amateur, why can't I find the characteristics of the two, remember?
I found a good-looking blog, copy and paste it directly, and see if I can remember it.

Suppose our camera parameter is 1920*1080, according to our display to display, then the horizontal one is 1920, the vertical one is 1080.

Reference link:

Deep understanding of (row, col) and (x, y) in OpenCV

The relationship between image.shape and length and width:

The ranks of the image coordinate system in OpenCV

Rows and columns are generally used in matrices and belong to the concept of matrices, which is the numpy Array object in OpenCV-Python. As shown below:

Insert picture description here

Width and height

Width and height are the concepts in the image. The insider speaks of the matrix, and the outsider sees the image. The width and height of an image are relative, depending on the current direction. Generally speaking, the width corresponds to the column of the pixel matrix and the height corresponds to the row of the pixel matrix.

x and y

In fact, when we are learning plane geometry in junior high school, the most commonly used coordinates are x and y. By default, we will regard x as the abscissa and y as the ordinate. We have such a preconceived concept. In fact, this is just a matter of usage habits. We can also use y to represent the abscissa and x to represent the ordinate, so in essence, x and y have no physical meaning. If you look at the habit of x being the abscissa and y being the ordinate, the coordinate system integrated into the image generally takes the upper left corner as the origin, the x axis to the right and the y axis to the down, then the corresponding range of x is [0, col), the corresponding range of y is [0,row). That is, x corresponds to the column and y corresponds to the row.

Select information in Python

Selecting ROI objects using slicing method is very simple

roi = image[y1:y2,x1:x2,:]  #先是行,再是列

Select pixels

for i in range(row):
    for j in range(col):
        p = img[i,j,0]  #注意范围,行在0~row之间,列在0~col之间

Guess you like

Origin blog.csdn.net/hehedadaq/article/details/112969490