A little pit of cv2.resize()

When I looked at the code today, I felt a bit different from what I thought. It is the cv2.resize() function. First, give his parameters:

resize(src, dsize, dst=None, fx=None, fy=None, interpolation=None)

Generally, after seeing it, I think it means to resize the original image src to the size of dsize? Later I found that it is not so simple:
give the original picture and size:

import cv2
img = cv2.imread('E:\Poker\\train\cam_image1.jpg')
print(img.shape)  
# (270, 480, 3) (height, width, channel)

This is the picture below:
Insert picture description here
Then the following is different from what I thought:

img1 = cv2.resize(img, (960, 540))
print(img1.shape)
# (540, 960, 3)
img2 = cv2.resize(img, (540, 960))
print(img2.shape)
# (960, 540, 3)

Why is it different from the simple resize I thought? After reading the official document , I found:

The order of the two parameters in dsize should correspond to the order of fx, fy, so it is the order of cols, rows, that is, the order of width, height

One thing to note is that the printed shape is in the order of (height, width, channel), which is the opposite of the order of dsize (ignoring the channel dimension)

So when you write by yourself in the future, you have to pay a little attention here~~

Guess you like

Origin blog.csdn.net/laizi_laizi/article/details/104362504