OpenCV 在 Linux 上的 python 与 anaconda 无法正常工作.收到未实现 cv2.imshow() 的错误 [英] OpenCV not working properly with python on Linux with anaconda. Getting error that cv2.imshow() is not implemented

查看:18
本文介绍了OpenCV 在 Linux 上的 python 与 anaconda 无法正常工作.收到未实现 cv2.imshow() 的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到的确切错误.我的操作系统是 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,然后重新运行 cmake 或配置脚本)在 cvShowImage,文件/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,然后我使用命令安装了opencv

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.如果你不想这样做,你可以尝试使用ma​​tplotlib.

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

我的 Ubuntu(18.04.1 LTS) 系统上的 openCV 3.4.2 出现此错误,因为对 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 在 Linux 上的 python 与 anaconda 无法正常工作.收到未实现 cv2.imshow() 的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆