我試圖使用的OpenCV裁剪圖像以下的代碼:類型錯誤: 'NoneType' 對象沒有屬性 '__getitem__' 的OpenCV蟒
import cv2
import numpy as np
import csv
path_image= '/home/'
img=cv2.imread(path_image+"image1.png")
img1=img[40:102,2442:2448]
但升得到執行一個錯誤:
img1=img[40:102,2442:2448]
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object has no attribute '__getitem__'
@DeepSpace它必須是''/ home/image1.png'' ...我猜 –
請參閱imread'的文檔。它解釋了何時以及爲什麼'imread'可能返回'None':http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#Mat%20imread(const%20string&%20filename,%20int%20flags )。找不到您嘗試打開的文件,或者文件格式不受支持。 – DeepSpace