【问题标题】:openCV not working with python3openCV不适用于python3
【发布时间】:2018-01-21 21:00:18
【问题描述】:

在 ubuntu 16.10 上运行带有 opencv 程序的简单 Python3 时出现此错误。

OpenCV Error: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you
are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then
re-run cmake or configure script) in cvShowImage, file
/io/opencv/modules/highgui/src/window.cpp, line 583 Traceback (most
recent call last):   File "samplecv.py", line 3, in <module>
    cv2.imshow('image',img) cv2.error: /io/opencv/modules/highgui/src/window.cpp:583: error: (-2) The
function is not implemented. Rebuild the library with Windows, GTK+
2.x or Carbon 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('my.jpg',0)
    cv2.imshow('image',img)

我已经检查过类似的问题thisthis。并重新安装了opencv,但没有帮助。

【问题讨论】:

标签: python opencv ubuntu


【解决方案1】:

您尝试过的更适合python2。您正在使用 python3 (正如我从您的问题中看到的那样)。我猜你正在使用 pip3 install 命令安装 cv 模块。它可以工作,但为模块提供的功能减少了:正如您从 highgui 模块中看到的那样 功能未实现。'

解决方案:尝试第一个答案 from here 并按照说明手动安装 opencv 模块。

【讨论】:

  • cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON .. 出现错误。不管怎样,我把它整理出来了,谢谢!
【解决方案2】:

花了两个多小时,但现在完成了! 我去了this opencv 的文档,并按照步骤安装了 opencv 3.3.0-dev。 完成安装后它仍然无法正常工作,所以我卸载了 opencv-python 使用

sudo pip3 uninstall opencv-python

现在错误没有出现,但在我添加之前图像仍然没有显示

cv2.waitKey()

在程序结束时。 现在它工作正常!!!

【讨论】:

  • 是的,您必须使用waitKey。很多用户忘记了这样做。
猜你喜欢
  • 2018-05-24
  • 2014-04-08
  • 1970-01-01
  • 2017-05-25
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-22
相关资源
最近更新 更多