The error message 'OpenCV(4.8.1) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4062: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'' indicates an assertion failure within the OpenCV resize function. This typically occurs when the input image has an empty size (width or height is zero).

To resolve this, first ensure the image path is correct and the file is accessible. Verify that the image was loaded correctly by checking if it's not None and its size is greater than zero.

Here's a code example to handle the situation where the image might be invalid:

image = cv2.imread(image_path)
if image is not None and image.size > 0:
    image = cv2.resize(image, (150, 150))
    # Rest of your code
else:
    print('Failed to load or resize the image.')

By incorporating this check, you can gracefully handle instances where the image cannot be loaded or has an invalid size, preventing the assertion failure and ensuring your code runs smoothly.

OpenCV Resize Function Error: Assertion Failed

原文地址: https://www.cveoy.top/t/topic/peSl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录