版权声明: https://blog.csdn.net/ninnyyan/article/details/86507650
使用cv2.resize()函数时,出现一个错误:
代码
image = cv2.imread(input_folder + photo_file)
image = cv2.resize(image, (resize_width, resize_height), interpolation=cv2.INTER_NEAREST)
cv2.imwrite(output_folder + photo_file, image)
报错
OpenCV(3.4.1) Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize, file /feedstock_root/build_artefacts/opencv_1520722599420/work/opencv-3.4.1/modules/imgproc/src/resize.cpp, line 4044 ..... cv2.error: OpenCV(3.4.1) /feedstock_root/build_artefacts/opencv_1520722599420/work/opencv-3.4.1/modules/imgproc/src/resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize
出现该问题是由于image存在None值,增加一个判断即可,写代码时要考虑的全面一些
修改后代码如下:
image = cv2.imread(input_folder + photo_file)
if image is not None:
image = cv2.resize(image, (resize_width, resize_height), interpolation=cv2.INTER_NEAREST)
cv2.imwrite(output_folder + photo_file, image)