import imgaug.augmenters as iaa
import cv2
import glob
from tkinter import Frame
from tkinter import Text
from tkinter import Label
# 1. Load Dataset
images = []
images_path = glob.glob("images/*.jpg")
for img_path in images_path:
img = cv2.imread(img_path)
images.append(img)
# 2. Image Augmentation
augmentation = iaa.Sequential([
# 1. Flip
iaa.Fliplr(0.5),
iaa.Flipud(0.5),
# 2. Affine
iaa.Affine(translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
rotate=(-30, 30),
scale=(0.5, 1.5)),
# 3. Multiply
iaa.Multiply((0.8, 1.2)),
# 4. Linearcontrast
iaa.LinearContrast((0.6, 1.4)),
# Perform methods below only sometimes
iaa.Sometimes(0.5,
# 5. GaussianBlur
iaa.GaussianBlur((0.0, 3.0))
)
])
# 3. Show Images
counter = 0
while True:
augmented_images = augmentation(images=images)
for img in augmented_images:
counter += 1
cv2.imwrite(str(counter) + ".jpg", frame)
cv2.imwrite('Desktop/images/dog.jpg', img) # desired save location
cv2.waitKey(0)
“回溯(最后一次调用):文件“C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py”,第 48 行,在 cv2.imwrite(str(counter) +“.jpg”,frame) NameError: name “框架”未定义”
图像增强代码运行良好,但是当我尝试保存增强图像时出现此错误。我还使用了大写的“F”而不是“f”(框架),但我遇到了另一个错误。
“回溯(最近一次调用最后):文件“C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py”,第 49 行,在 cv2.imwrite(str(counter) +“.jpg”,Frame) cv2.error :OpenCV(4.5.4-dev):-1:错误:(-5:错误参数)在函数'imwrite'中
重载解析失败:
- img 不是 numpy 数组,也不是标量
- 参数 'img' 的预期 Ptr<cv::UMat>"
任何类型的帮助都是值得赞赏的。提前致谢。