人物判別のために画像を水増ししたいのですがエラーが出てしまいます
python
1import os 2import numpy as np 3import matplotlib.pyplot as plt 4import cv2 5from os import listdir 6 7def make_image(input_img): 8 img_size = input_img.shape 9 filter_one = np.ones((3, 3)) 10 fake_method_array = np.array([ 11 lambda x: cv2.threshold(x, 100, 255, cv2.THRESH_TOZERO)[1], 12 lambda x: cv2.GaussianBlur(x, (5, 5), 0), 13 lambda x: cv2.resize(cv2.resize( x, (img_size[1] // 5, img_size[0] // 5)),(img_size[1], img_size[0])), 14 lambda x: cv2.erode(x, filter_one), 15 lambda x: cv2.flip(x, 1), 16 ]) 17 images = [] 18 for method in fake_method_array: 19 faked_img = method(input_img) 20 images.append(faked_img) 21 return images 22 23path = "人物判別/downloads/matsumoto hitoshi/" 24imagesList = listdir(path) 25i=1 26for file in imagesList: 27 target_img = cv2.imread(path+file) 28 fake_images = make_image(target_img) 29 if not os.path.exists("matsumoto_images"): 30 os.mkdir("matsumoto_images") 31 for number, img in enumerate(fake_images): 32 cv2.imwrite("matsumoto_images" + str(i)+str(number) + ".jpg" ,img) 33 i=i+1
error
1Traceback (most recent call last): 2 File "c:/Users/my174/programming/python/machine learning/5_04.py", line 28, in <module> 3 fake_images = make_image(target_img) 4 File "c:/Users/my174/programming/python/machine learning/5_04.py", line 8, in make_image 5 img_size = input_img.shape 6AttributeError: 'NoneType' object has no attribute 'shape'
環境はpython3.8.3 vscode ディレクトリ構成は 1人物判別 2downloads 3matsumoto hitoshi 3.5_04.py です。
回答4件
あなたの回答
tips
プレビュー