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

查看:495
本文介绍了在带有anaconda的Linux上,OpenCV无法与python一起正常使用.收到未实现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 ,然后在cvShowImage文件/feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp,第545行中重新运行cmake或配置脚本) 追溯(最近一次通话): 在第7行的文件"untitled.py"中 cv2.imshow('image',img) cv2.error:/feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545:错误:(-2)该功能未实现.在Windows,GTK + 2.x或Carbon支持下重建库.如果您使用的是Ubuntu或Debian,请安装libgtk2.0-dev和pkg-config,然后重新运行cmake或在函数cvShowImage中配置脚本

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 /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 545 Traceback (most recent call last): File "untitled.py", line 7, in cv2.imshow('image',img) cv2.error: /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: 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 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的方法调用失败.我正在使用水蟒.仅以下两个步骤就帮助我解决了问题:

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

这篇关于在带有anaconda的Linux上,OpenCV无法与python一起正常使用.收到未实现cv2.imshow()的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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