简体   繁体   English

cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'

[英]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_folderfolder之间)或忘记了文件扩展名,或者您创建了不存在文件的路径。

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.

相关问题 resize.cpp:4052: error: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV(4.2.0),imwrite() 到子文件夹会破坏模块; cv2.error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'`' - OpenCV(4.2.0),imwrite() to a subfolder breaks the module; cv2.error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'`' cv2.error: OpenCV(4.5.2) C:\\Users\\ ... \\modules\\imgproc\\src\\resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'cv::hal: :调整大小' - cv2.error: OpenCV(4.5.2) C:\Users\ … \modules\imgproc\src\resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'cv::hal::resize' small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' - small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 错误:OpenCV(4.1.0) 错误:(-215:Assertion failed) !ssize.empty() in function 'cv::resize' - error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV(4.1.2) 错误: (-215:Assertion failed).ssize:empty() in function 'cv::resize' - OpenCV(4.1.2) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' 此错误的问题: (-215:Assertion failed).ssize:empty() in function 'cv::resize' OpenCV - Problem with this error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV 在函数 'cv::resize' 中检索 opencv 错误(-215:Assertion failed)!ssize.empty() - Retrieving opencv error (-215:Assertion failed) !ssize.empty() in function 'cv::resize' CV2 图像错误:错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - CV2 Image Error: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OPEN-CV 错误:(-215:Assertion failed).ssize:empty() in function 'cv::resize' - OPEN-CV error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM