-1
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)

"Traceback (most recent call last): File "C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py", line 48, in cv2.imwrite(str(counter) + ".jpg", frame) NameError: name 'frame' is not defined"

The image augmentation code ran well, but when I tried to save the augmented images this error occurred. I also used capital 'F' instead of 'f' (frame), but I got another error.

"Traceback (most recent call last): File "C:/Users/MC/PycharmProjects/pythonProject/Python_Augmentation.py", line 49, in cv2.imwrite(str(counter) + ".jpg", Frame) cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'imwrite'

Overload resolution failed:

  • img is not a numpy array, neither a scalar
  • Expected Ptr<cv::UMat> for argument 'img'"

Any type of help is appreciatable. Thanks in advance.

Milon
  • 19
  • 1
  • 5

1 Answers1

-1

The import was: from tkinter import Frame

but you using, in line 48: frame (lower 'f').

Avner Cohen
  • 80
  • 1
  • 5
  • What exactly do you expect to achieve by passing a Python **class object** to a function designed to **save images** to disk? – Dan Mašek Nov 18 '21 at 15:10
  • Actually, I am learning python and OpenCV. I want to save the augmented images and use those separately for other purposes. – Milon Nov 18 '21 at 15:18