[英]cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
I am receiving this error when running this line of code:运行这行代码时收到此错误:
pixels.append( cv2.resize(cv2.imread(raw_folder + folder +"/" + file),dsize=(128,128)))**
Error:错误:
cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\imgproc\src\resize.cpp:4051:
error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
You may have common problem: when CV2 can't read file then it doesn't raise error but it returns None
and now you try to resize None
- empty image - and this shows .ssize.empty()
.您可能遇到常见问题:当 CV2 无法读取文件时,它不会引发错误,但会返回None
,现在您尝试调整None
- 空图像 - 这显示.ssize.empty()
。
You should first read image, next check if you get None
and next try to resize it.您应该首先阅读图像,然后检查您是否得到None
然后尝试调整它的大小。
You should check if raw_folder + folder +"/" + file
creates correct path and if you can open it in any other program.您应该检查raw_folder + folder +"/" + file
是否创建正确的路径以及是否可以在任何其他程序中打开它。 Maybe you forgot some /
in path (ie. between raw_folder
and folder
) or forgot file extension or you create path to not existing file.也许您在路径中忘记了一些/
(即在raw_folder
和folder
之间)或忘记了文件扩展名,或者您创建了不存在文件的路径。
path = os.path.join(raw_folder, folder, file)
print('[DEBUG] path:', path)
img = cv2.imread(path)
if img is None:
print('Wrong path:', path)
else:
img = cv2.resize(img, dsize=(128,128))
pixels.append(img)
Another situation that lead to this error was to input an image of the wrong shape.导致此错误的另一种情况是输入了错误形状的图像。 I had an RGB image of shape (3, 540, 960) and got the misleading 'ssize is not empty'.我有一个形状为 (3, 540, 960) 的 RGB 图像,并得到了误导性的“大小不是空的”。 Changing the shape to (540, 960, 3) fixed my problem.将形状更改为 (540, 960, 3) 解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.