import os import glob from PIL import Image files = glob.glob('/content/drive/MyDrive/images/*.jpg') for f in files: img = Image.open(f) plt.imshow(img) plt.show() target = cv2.imread(str(files)) target = target[x1 : x2, y1: y2] plt.imshow(target) plt.show()
ここの、target = target[x1 : x2, y1: y2] で'NoneType' object is not subscriptable というエラーが出てしまいました。
対処法を教えていただきたいです。
コードは過度に簡略化せず、第三者が検証、実行可能な状態で提示ください。
私の環境では「NameError: name 'plt' is not defined」が発生します。
また、たとえこのエラーを回避してもcv2, x1, など未定義なのでエラーが発生しそうです。
(まあtarget = cv2.imread(str(files))の時点でtargetがNoneなんでしょうが)
質問のコードは「NameError: name 'x1' is not defined」のエラーが出ます。x1とは何ですか?
target = cv2.imread(str(files))
のすぐ下に下記を追加して実行したら、何て表示されますでしょうか?
print(target.shape)
あなたの回答
tips
プレビュー