解决 OpenCV resize 函数中 "Assertion Failed" 错误
The error message indicates that there is an assertion failed in the resize function of OpenCV. This error occurs when the input image array is empty.
To resolve this issue, you can check if the image array is empty before resizing it. You can add a condition to skip empty image arrays in your code:
for img in os.listdir(cat_path):
img_array = cv2.imread(os.path.join(cat_path, img))
if img_array is not None: # Check if the image array is empty
img_array = cv2.resize(img_array, (img_width, img_height))
data.append(img_array)
labels.append(0) # 猫的标签为0
Similarly, you can add the same check for the dog images as well. This will ensure that only valid images are resized and added to the data array.
原文地址: https://www.cveoy.top/t/topic/o9t1 著作权归作者所有。请勿转载和采集!