用python在opencv中显示图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用python在opencv中显示图像相关的知识,希望对你有一定的参考价值。
我正在学习openCv与python.i希望显示图像,但代码不工作..它没有显示任何东西而不是我搜索的错误但问题仍然相同..我按照这里提到的解决方案
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)
但它并没有解决我的问题..明确指出我在做错误的地方会感激不尽
错误: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:projectsopencv-pythonopencvmoduleshighguisrcwindow.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
希望能帮助到你
以上是关于用python在opencv中显示图像的主要内容,如果未能解决你的问题,请参考以下文章