Python OpenCV 错误:该函数未实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14655969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:03:49  来源:igfitidea点击:

OpenCV error: the function is not implemented

pythonopencv

提问by Dan

I'm trying to get OpenCV working with Python on my Ubuntu machine. I've downloaded and installed OpenCV, but when I attempt to run the following python code (which should capture images from a webcam and push them to the screen)

我正在尝试让 OpenCV 在我的 Ubuntu 机器上使用 Python。我已经下载并安装了 OpenCV,但是当我尝试运行以下 python 代码时(它应该从网络摄像头捕获图像并将它们推送到屏幕上)

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)

def repeat():
    frame = cv.QueryFrame(capture)
    cv.ShowImage("w1", frame)
    time.sleep(10)

while True:
    repeat()

I get the following 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

So I do what they ask: install the packages, move to the folder from whence I installed OpenCV, and run

所以我按照他们的要求去做:安装软件包,移动到我安装 OpenCV 的文件夹,然后运行

sudo make uninstall
make
sudo make install

But when I try to run the python, it gives me the same error. Am I missing something?

但是当我尝试运行 python 时,它给了我同样的错误。我错过了什么吗?

采纳答案by Froyo

If it's giving you errors with gtk, try qt.

如果它给你 gtk 错误,试试 qt。

sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install

If this doesn't work, there's an easy way out.

如果这不起作用,有一个简单的方法。

sudo apt-get install libopencv-*

This will download all the required dependencies(although it seems that you have all the required libraries installed, but still you could try it once). This will probably install OpenCV 2.3.1 (Ubuntu 12.04). But since you have OpenCV 2.4.3 in /usr/local/libinclude this path in /etc/ld.so.confand do ldconfig. So now whenever you use OpenCV, you'd use the latest version. This is not the best way to do it but if you're still having problems with qt or gtk, try this once. This should work.

这将下载所有必需的依赖项(尽管您似乎已经安装了所有必需的库,但您仍然可以尝试一次)。这可能会安装 OpenCV 2.3.1 (Ubuntu 12.04)。但是由于您在 OpenCV 2.4.3 中/usr/local/lib包含此路径/etc/ld.so.conf并执行ldconfig. 所以现在每当你使用 OpenCV 时,你都会使用最新版本。这不是最好的方法,但如果您仍然遇到 qt 或 gtk 问题,请尝试一次。这应该有效。

Update- 18th Jun 2019

更新- 2019 年 6 月 18 日

I got this error on my Ubuntu(18.04.1 LTS) system for openCV 3.4.2, as the method call to cv2.imshowwas failing (e.g., at the line of cv2.namedWindow(name) with error: cv2.error: OpenCV(3.4.2). The function is not implemented.). I am using anaconda. Just the below 2 steps helped me resolve:

我在用于 openCV 3.4.2 的 Ubuntu(18.04.1 LTS) 系统上遇到此错误,因为方法调用cv2.imshow失败(例如,在 cv2.namedWindow(name) 行,错误为:cv2.error: OpenCV(3.4 .2).该功能没有实现。)。我正在使用蟒蛇。只是以下两个步骤帮助我解决:

conda remove opencv
conda install -c conda-forge opencv=4.1.0

If you are using pip, you can try

如果您正在使用 pip,您可以尝试

pip install opencv-contrib-python

回答by Artem S

I hope this answer is still useful, despite problem seems to be quite old.

我希望这个答案仍然有用,尽管问题似乎已经很老了。

If you have Anaconda installed, and your OpenCV does not support GTK+ (as in this case), you can simply type

如果您安装了 Anaconda,并且您的 OpenCV 不支持 GTK+(在这种情况下),您可以简单地输入

conda install -c menpo opencv=2.4.11

It will install suitable OpenCV version that does not produce a mentioned error. Besides, it will reinstall previously installed OpenCV if there was one as a part of Anaconda.

它将安装不会产生上述错误的合适 OpenCV 版本。此外,如果有一个作为 Anaconda 的一部分,它将重新安装以前安装的 OpenCV。

回答by Nic Szerman

If you installed OpenCV using the opencv-python pip package at any point in time, be aware of the following note, taken from https://pypi.python.org/pypi/opencv-python

如果您在任何时间点使用 opencv-python pip 包安装了 OpenCV,请注意以下注释,摘自https://pypi.python.org/pypi/opencv-python

IMPORTANT NOTEMacOS and Linux wheels have currently some limitations:

  • video related functionality is not supported (not compiled with FFmpeg)
  • for example cv2.imshow()will not work (not compiled with GTK+ 2.x or Carbon support)

重要提示MacOS 和 Linux 轮子目前有一些限制:

  • 不支持视频相关功能(未使用 FFmpeg 编译)
  • 例如cv2.imshow()将无法工作(未使用 GTK+ 2.x 或 Carbon 支持编译)

Also note that to install from another source, first you must remove the opencv-python package

另请注意,要从其他来源安装,首先必须删除 opencv-python 包

回答by user618677

Before installing libgtk2.0-dev and pkg-config or libqt4-dev. Make sure that you have uninstalled opencv. You can confirm this by running import cv2 on your python shell. If it fails, then install the needed packages and re-run cmake .

在安装 libgtk2.0-dev 和 pkg-config 或 libqt4-dev 之前。确保您已卸载 opencv。您可以通过在 python shell 上运行 import cv2 来确认这一点。如果失败,则安装所需的软件包并重新运行 cmake 。

回答by purna15111

Don't waste your time trying to resolve this issue, this was made clear by the makers themselves. Instead of cv2.imshow()use this:

不要浪费你的时间试图解决这个问题,这是由制造商自己明确的。而不是cv2.imshow()使用这个:

img = cv2.imread('path_to_image')
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
plt.show()