AttributeError: 'NoneType' object has no attribute 'shape'

What is this error??


Traceback (most recent call last):
  File "code.py", line 1717, in shape
    height, width = input.shape
AttributeError: 'NoneType' object has no attribute 'shape'

This is the code:

        input = cv2.imread('IMAGES/UAV.tif') #, cv2.IMREAD_UNCHANGED)        
        height, width = input.shape
        print("HEIGHT:", height)
        print("WIDTH:", width)

At a guess imread has failed and input is a NoneType instead of a numpy array. As such it doesn’t have a shape attribute.

2 Likes

These are the pixels’ colors range from the QGIS where I tested the .tif file colors Can this be the problem?

even on read failure, you can avoid the exception:
height, width = np.shape(input)
# -> height == width == 0

but please, DO CHECK each imread() call, opencv does not throw , but returns invalid images(None) on failure (something, python noobs NEVER expect)

1 Like

Yes, indeed, print(input) returns “None”! Any ideas?

post the exact image file, no editing at all, none. then we can investigate.