美文网首页
4-2. Downscale with resize()

4-2. Downscale with resize()

作者: JaedenKil | 来源:发表于2020-01-14 11:25 被阅读0次

Key points:

  • dim = (width, height) # first param is width, second is height, contrary to height = image.shape[0], width = image.shape[1]
  • height = int(shape[0] * scale_percentage) & width = int(shape[1] * scale_percentage)
    Need to make sure width & height are int, else 'TypeError: integer argument expected, got float'.
import cv2


img = cv2.imread("C:\\Users\\zzheng\\Pictures\\tiger.png", cv2.IMREAD_UNCHANGED)
shape = img.shape
print("Original shape: ", shape)

scale_percentage = 60 / 100
height = int(shape[0] * scale_percentage)
# need to transfer float to int,
# or "TypeError: integer argument expected, got float"
width = int(shape[1] * scale_percentage)
dim = (width, height)
resized_img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
print("New shape: ", resized_img.shape)
cv2.imshow("Resized image", resized_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Original shape:  (1025, 1921, 3)
# New shape:  (615, 1152, 3)

相关文章

网友评论

      本文标题:4-2. Downscale with resize()

      本文链接:https://www.haomeiwen.com/subject/wdgoactx.html