-1

i am learning openCv with python.i want to display image but the code is not working.. it is not displaying anything rather than errors i searched but problem still same.. i followed solution mentioned here

OpenCV-Python not displaying image

  import cv2
img = cv2.imread("D:\\iki\\images.png", 0)
if img is None:
  print ("The file does not exist")
else:
  cv2.imshow("image", img)

but it didnt solve my problem..kindly point out where i am doing mistake would be grateful

error: Traceback (most recent call last): File "C:/Users/ATech/AppData/Local/Programs/Python/Python37-32/cc task/FYP_OpenCv/read_show_img.py", line 7, in <module> cv2.imshow("image", img) cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:625: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

11
  • Always check if img is None. Try to use the absolute path. Commented Apr 14, 2019 at 12:27
  • Did you make sure the image path is correct? Commented Apr 14, 2019 at 12:27
  • how could i check that ? Commented Apr 14, 2019 at 12:27
  • @DylanRiley yh path is correct Commented Apr 14, 2019 at 12:28
  • I wrote... if img is None. Also, I said: try to use the absolute path; did you try? Commented Apr 14, 2019 at 12:29

1 Answer 1

1

Just make sure your file does exist. Try this:

import cv2
img = cv2.imread("./Downloads/2nd-color.png", 0)
if img is None:
  print ("The file does not exist")
else:
  cv2.imshow("image", img)

Be aware of the second argument in imread. 0 is for grayscale. Have a look at: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html#read-an-image

Hope it helps

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

1 Comment

You are welcome. If it answers your question, please mark as answered. Otherwise, comment what is still wrong and we can try to figure that out :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.