import numpy as np
import cv2
img = cv2.imread(r"C:\Users\User\Documents\sypder\try\bird.jpg", cv2.IMREAD_UNCHANGED)
print('Original Dimension:',img.shape)
scale_percentage = 30
width = int(img.shape[0] * scale_percentage/100)
height = int(img.shape[0] * scale_percentage/100)
dim = (width,height)
resized = cv2.resize(img,dim,interpolation = cv2.INTER_AREA)
print('Resized image',resized.shape)
cv2.imwrite('resized.jpg',resized)
cv2.imshow("Resized image",resized)
cv2.waitKey(0)
错误:ile"C:/用户/用户/文档/sypder/try/resize.py",第18行, resized = cv2.resize(img,dim,interpolation = cv2.INTER_AREA) 错误:OpenCV(4.5.5)D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp: 4055: 错误:(-215:断言失败)inv_scale_x > 0在函数'cv :: resize'中
int(img.shape[0] * scale_percentage/100)
时,如果int()
内部的值小于1,则宽度和高度将为0,从而引发同样的错误。 - Javier TG