Tag Archives: attributeError: ‘NoneType’ object has no attribute ‘shape’

attributeError: ‘NoneType’ object has no attribute ‘shape’

 

# 1 load 2 info 3 resize 4 check
import cv2

img = cv2.imread("image0.jpg", 1)
imgInfo = img.shape
print(imgInfo)

  

Attributeerror: ‘nonetype’ object has no attribute ‘shape’ error

The returned type may be none because the path is not set

The correct way is to write the path when reading the picture

import cv2

img = cv2.imread(r"D:\PythonCode\neuron\image0.jpg", 1)
imgInfo = img.shape
print(imgInfo)

  

attributeError: ‘NoneType’ object has no attribute ‘shape’

How did “people you might know” find you on social software>>>

In the original code

#read an image
    img = cv2.imread('image.jpg')
    
    #print the dimension of the image
    print img.shape

It may be that the path is not set, so the returned type is none

The correct way is to write the path when reading the picture

#Try changing the direction of the slashes

im = cv2.imread("D:/testdata/some.tif",CV_LOAD_IMAGE_COLOR)

#or add r to the begining of the string

im = cv2.imread(r"D:\testdata\some.tif",CV_LOAD_IMAGE_COLOR)