《python调试》 'NoneType' object has no attribute 'shape'; Expected 2D array, got 1D array instead解决办法

if __name__ =="__main__":
    img_path=r"./smoke/allsmoke/image_3.jpg"
    #img_path='./data/imagePart_train/smoke/allsmoke/image_3.jpg'
    img = cv2.imread(img_path)
    print(img.shape)
    f=getFeature(img, 5)
    print(f)

问题1: print(img.shape)
               AttributeError: 'NoneType' object has no attribute 'shape'

解决方案:把img_path的路径写全,或者好好检查该路径下是否有图像

 

问题2:ValueError: Expected 2D array, got 1D array instead:

《python调试》 'NoneType' object has no attribute 'shape'; Expected 2D array, got 1D array instead解决办法_第1张图片

解决方案:在下图所示的地方加上[ ]即可!

《python调试》 'NoneType' object has no attribute 'shape'; Expected 2D array, got 1D array instead解决办法_第2张图片

你可能感兴趣的:(python笔记)