Python Forum
Python openCV "img" is not defined error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python openCV "img" is not defined error
#1
I'm using openCV to write an image to a new file. I got the following method from an openCV textbook but I get an error that says "img" is not defined.

cv2.imwrite("myimage.png", img)
Reply
#2
Please, post your full code (minimal runnable script).
My guess is img is a variable, defined in the example code somewhere before that line and it is missing (i.e. it is not defined yet, or you are using different name) in your code.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Apr-23-2018, 12:15 PM)buran Wrote: Please, post your full code (minimal runnable script).
My guess is img is a variable, defined in the example code somewhere before that line and it is missing (i.e. it is not defined yet, or you are using different name) in your code.

You're right. img represented an image file that was read before writing. Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with using opencv in python Raunak1023984765 21 1,713 Feb-21-2024, 04:25 PM
Last Post: Pedroski55
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 586 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,131 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,357 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Screen capture opencv - grab error Kalman15 1 1,606 Jan-27-2022, 12:22 PM
Last Post: buran
  Help for the shortest way to install a suitable version of Python, Numpy, and OpenCV. Ezzat 2 2,288 Dec-23-2021, 12:34 PM
Last Post: snippsat
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,637 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Python OpenCV window not opening in fullscreen mode Zman350x 0 3,304 Apr-29-2021, 07:54 PM
Last Post: Zman350x
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,387 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 2,185 Dec-14-2020, 05:45 PM
Last Post: karabakh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020