简体   繁体   中英

How to solve the "NameError: name 'frame' is not defined" error occured in OpenCV?

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.

The import was: from tkinter import Frame

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM