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

We Are Going To Discuss About cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’. So lets Start this Python Article.

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

  1. How to solve cv2.error: OpenCV(4.5.2) 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().
    You should first read image, next check if you get None and next try to resize it.
    You should check if raw_folder + folder +"/" + file creates correct path and if you can open it in any other program. Maybe you forgot some / in path (ie. between raw_folder and folder) or forgot file extension or you create path to not existing file.
    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)

  2. cv2.error: OpenCV(4.5.2) 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().
    You should first read image, next check if you get None and next try to resize it.
    You should check if raw_folder + folder +"/" + file creates correct path and if you can open it in any other program. Maybe you forgot some / in path (ie. between raw_folder and folder) or forgot file extension or you create path to not existing file.
    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)

Solution 1

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().

You should first read image, next check if you get None and next try to resize it.

You should check if raw_folder + folder +"/" + file creates correct path and if you can open it in any other program. Maybe you forgot some / in path (ie. between raw_folder and folder) or forgot file extension or you create path to not existing file.

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)

Original Author furas Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment