error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

If you are working with several images (for example, 1000 images), it may be difficult for you to identify which image is giving you problems. It may also be that, there are several others that are corrupt. In such a case, the code below can be useful.

for file in filenames:
    try:
        image = cv2.resize(cv2.imread(file), (size, size))
    except:
        print(file)

where filenames is a list which contains names of the images.


Make sure the input_img's resolution is not zero, i.e, (0,0,number_of_channels) which means it is not finding any image. So add the following checking before performing operations on it:

if input_img.shape[0]!=0 and input_img.shape[1]!=0:
    #operations on input_img

Well, obviously this line input_img=cv2.imread(data_path + '/'+ dataset + '/'+ img ) returns an empty array.

You should check whether the image exists first before reading. And it is better not to use string combination to join file paths, use python os.path.join instead.

image_path = os.path.join(data_path, dataset, img)
if os.path.exist():
    # Do stuff

It is because of one image.

To find the image I added a line of code that prints the name of the image before it enters the cv2.resize and another line that prints the name after it is resized. It will automatically stop at the image with fault.