1. 程式人生 > >python各種問題:'NoneType' object has no attribute 'shape';Expected 2D array, got 1D array instead:

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:

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