【发布时间】:2020-09-06 14:28:51
【问题描述】:
我想增加文件夹中的图像。我还想在不同文件夹中扩充后保持图像的名称相同。如何使用 OpenCV 做到这一点?
# Defining path
INPUT_IMG_DIR = 'NORMAL'
OUTPUT_AUG_DIR = 'AUGMENT'
seq = iaa.Sequential([iaa.Affine(rotate=5)
# iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5),
# iaa.Multiply((0.5, 1.5), per_channel=0.5),
# iaa.Add((-10, 10), per_channel=0.5)
])
for image in os.listdir(INPUT_IMG_DIR):
image = image
print(image)
print(len(image))
print(type(image))
image = cv2.imread(image)
seq_det = seq.to_deterministic()
image_aug = seq.augment_images(image)
print(image_aug)
cv2.imwrite(OUTPUT_AUG_DIR, image, image_aug)
此代码不适用于我。它正在抛出这样的错误,
NORMAL_IMG_0.jpeg
<class 'str'>
None
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-28-b6ca6f4c6834> in <module>
9 image_aug = seq.augment_images(image)
10 print(image_aug)
---> 11 cv2.imwrite(OUTPUT_AUG_DIR, image, image_aug)
error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
【问题讨论】:
标签: python opencv keras deep-learning computer-vision