Regarding the image shape problem read by the cv2.imread function in opencv

The image coordinate system is (w, h), w is the x-axis, h is the y-axis, (x, y)

But the array read by opencv is just the opposite, (h, w, 3), (y, x, 3)

So there will be a conversion here

image = cv2.imread('1.jpg')
print(image.shape[0:2])
##输出(365,500),也即(高度,宽度)

In fact, when converting to the image coordinate system, you need to transpose it, or image.shape[::-1]

Slicing operation [start, endstep], where: - start: indicates the starting subscript, if omitted, the default is 0 - end
: indicates the end subscript (not included), if omitted, the default is the sequence length
- step: indicates the step length, The default is 1, so the meaning of a[::-1] is: - start is the last element (because it is omitted): a[-1] - end is the first
element (because it is omitted): a[0]
- step is -1, which means reverse

The same goes for using matplotlib.pyplot.imread, plt.imread

Guess you like

Origin blog.csdn.net/m0_56514535/article/details/131516003