繁体   English   中英

使用python在opencv中显示图像

[英]display image in opencv with python

我正在使用python.i学习openCv,我想显示图像,但是代码不起作用..它没有显示任何内容,而不是我搜索的错误,但问题仍然相同。

OpenCV-Python不显示图像

  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)

但这并不能解决我的问题..请指出我在哪里做错了,将不胜感激

错误: 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' 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'

只要确保您的文件确实存在。 尝试这个:

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)

注意imread中的第二个论点。 0是灰度。 看看: https : //docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_image_display/py_image_display.html#read-an-image

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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