OpenCV 错误:(-215:断言失败)函数“cv::resize”中的 inv_scale_x > 0

问题描述 投票:0回答:2
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:/Users/User/Documents/sypder/try/resize.py”,第 18 行,在 调整大小 = cv2.resize(img,dim,插值 = cv2.INTER_AREA) 错误:OpenCV(4.5.5) D:\opencv-python\opencv-python\opencv\modules\imgproc\src esize.cpp:4055:错误:(-215:断言失败)函数“cv :: resize”中的inv_scale_x > 0

python image-processing image-resizing
2个回答
0
投票

您检查一下img路径是否正确?如果路径不正确,img可能为空,并且在调整大小时报告错误。 能否在第123行后添加一行来检查img是否读取成功? assert img!=None, "图片读取错误,请检查你的图片路径是否正确。"

如果是这种情况,请仔细检查您的图像路径。


0
投票

即使正确提供了输入图像数据,我们也会随机观察到这个特定错误和 CV 内存不足错误。我们将 OpenCV 库从版本 4.4.0 升级到 4.7.0。基本上,输入 arument 值在 Open CV API 函数 cv::resize 中被损坏。 后来问题的根本原因是在我们的 VC++ 项目设置 --> C\C++ include header dir 中发现的。首先提到了 Open CV 旧标头目录路径(版本 4.4.0),然后是新标头目录路径(版本 4.7.0)。 删除旧目录路径和我们的项目构建后,问题得到解决。希望我的回答对遇到类似问题的人有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.