attributeError: 'NoneType' object has no attribute 'shape' 報錯


在最初的代碼中, 

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

可能是因為沒有設置路徑,所以返回的類型是None。

改正的方法是,讀取圖片時把路徑也寫上

#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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM