OpenCV 无法在带有 anaconda 的 Linux 上与 python 正常工作.获取未实现 cv2.imshow() 的错误 [英] OpenCV not working properly with python on Linux with anaconda. Getting error that cv2.imshow() is not implemented
问题描述
这是我得到的确切错误.我的操作系统是 Ubuntu 16.10.
This is the exact error that I am getting. My OS is Ubuntu 16.10.
OpenCV 错误:未指定的错误(该函数未实现.使用 Windows、GTK+ 2.x 或 Carbon 支持重建库.如果您使用的是 Ubuntu 或 Debian,请安装 libgtk2.0-dev 和 pkg-config,然后在 cvShowImage 中重新运行 cmake 或配置脚本),文件/feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp,第 545 行回溯(最近一次调用最后一次):文件untitled.py",第 7 行,在cv2.imshow('图像',img)cv2.error:/feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: error: (-2) 该函数未实现.使用 Windows、GTK+ 2.x 或 Carbon 支持重建库.如果你使用的是 Ubuntu 或 Debian,请安装 libgtk2.0-dev 和 pkg-config,然后重新运行 cmake 或在函数 cvShowImage 中配置脚本
我的代码是:
import numpy as np
import cv2
# Load an color image in grayscale
img = cv2.imread('0002.png',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
0002.png 是与程序在同一目录中的图像.我首先用python 3.5安装了anaconda,然后使用命令
0002.png is an image in the same directory as the program. I first installed anaconda with python 3.5, then I installed opencv by using the command
conda install -c conda-forge opencv
我按照错误提示安装了 libgtk2.0-dev,但我仍然遇到相同的错误.任何帮助将非常感激.我已经尝试解决这个问题好几个小时了.
I installed libgtk2.0-dev just as the error said to but I still get the same error. Any help would be much appreciated. I've been trying to solve this for several hours.
推荐答案
1.最简单的方法:
conda remove opencv
conda update conda
conda install --channel menpo opencv
或(对于 OpenCV 3.1):
or (for OpenCV 3.1) :
conda install -c menpo opencv3
2.如果你不想这样做,你可以尝试使用matplotlib.
2.And if u don't want to do this, you can try to use matplotlib .
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('img.jpg',0)
plt.imshow(img, cmap='gray')
plt.show()
3.或者尝试使用选项 WITH_GTK=ON
或类似的方式自行构建库.
3.Or try to build library by your own with option WITH_GTK=ON
, or smth like that.
更新 - 2019 年 6 月 18 日
Update - 18th Jun 2019
我在用于 openCV 3.4.2 的 Ubuntu(18.04.1 LTS) 系统上遇到此错误,因为对 cv2.imshow 的方法调用失败.我正在使用蟒蛇.只是以下 2 个步骤帮助我解决了:
I got this error on my Ubuntu(18.04.1 LTS) system for openCV 3.4.2, as the method call to cv2.imshow was failing. I am using anaconda. Just the below 2 steps helped me resolve:
conda remove opencv
conda install -c conda-forge opencv=4.1.0
如果你正在使用pip,你可以试试
If you are using pip, you can try
pip install opencv-contrib-python
这篇关于OpenCV 无法在带有 anaconda 的 Linux 上与 python 正常工作.获取未实现 cv2.imshow() 的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!