本文介绍了如何使用imwrite从一个文件夹中拍摄图像,然后使用Opencv将其保存到另一个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想扩充文件夹中的图像.我还想在扩展后将图像的名称保留在不同的文件夹中.如何使用OpenCV做到这一点?
I want to augment images inside a folder. I also want to keep the names of images the same after augmentation in a different folder. How can I do this using 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)
此代码不适用于我.像这样抛出错误,
This code is not working for me. It is throwing error like this,
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'
推荐答案
替换:
cv2.imwrite(OUTPUT_AUG_DIR, image, image_aug)
具有:
cv2.imwrite(os.path.join( OUTPUT_AUG_DIR, image), image_aug)
这篇关于如何使用imwrite从一个文件夹中拍摄图像,然后使用Opencv将其保存到另一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!