4

Im trying to make a very minor 2d game engine, and I am trying to get the user to select a file. I am using pygame to write my code, but to choose a file you would need tkinter or make your own file opener and I am to lazy to. I have two problems but i am only going to write my first one here. I have the name and location of the file and when i do img.imwrite("background.jpg") it gives me an error, so I thought maybe I'll just run it in a seperate file to test if im writing it right, or it doesn't work, and i still get an error.

Code:

import cv2
img = cv2.imread("input.jpg")
img.imwrite("output.jpg")

Error:

Traceback (most recent call last):
  File "/Users/shauryapatel/Desktop/PythonPrograms/GameEngine/player.py", line 3, in <module>
    img.imwrite("output.jpg")
AttributeError: 'numpy.ndarray' object has no attribute 'imwrite'

Thank you!

2
  • 2
    Isn't that cv2.imwrite("output.jpg", img)? Commented Nov 1, 2020 at 1:38
  • @Timus ah sorry, my brain doesn't work. Commented Nov 1, 2020 at 1:57

1 Answer 1

3

imread returns a numpy array of the image data. imwrite(filename,image) (doc here) takes a name and image data, saving it in the specified format. You can't call imread as if it were a method of the image data.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, sorry... sometimes my brain doesn't work (it never works)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.