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 11,975 Feb-21-2024, 04:25 PM
Last Post: Pedroski55
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 1,774 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 3,794 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 4,005 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Screen capture opencv - grab error Kalman15 1 2,978 Jan-27-2022, 12:22 PM
Last Post: buran
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 5,493 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Python OpenCV window not opening in fullscreen mode Zman350x 0 4,783 Apr-29-2021, 07:54 PM
Last Post: Zman350x
  Error when refering to class defined in 'main' in an imported module HeRo 2 3,380 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 3,432 Dec-14-2020, 05:45 PM
Last Post: karabakh
  Python IDE doesn't see opencv-python package on my Jetson Nano sadhaonnisa 1 4,438 Oct-11-2020, 01:04 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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