OpenCV not working properly with python on Linux with anaconda. Getting error that cv2.imshow() is n

错误提示
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

参考
https://stackoverflow.com/questions/40207011/opencv-not-working-properly-with-python-on-linux-with-anaconda-getting-error-th?rq=1
解决办法(我使用第一种办法解决的)

1.The easiest way:

conda remove opencv
conda update conda
conda install --channel menpo opencv

or (for OpenCV 3.1) :

conda install -c menpo opencv3

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.Or try to build library by your own with option WITH_GTK=ON , or smth like that.

Update - 18th Jun 2019

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

If you are using pip, you can try

pip install opencv-contrib-python

问题汇总

cv2.VideoCapture not working

参考https://stackoverflow.com/questions/47112642/permanent-fix-for-opencv-videocapture
OpenCV FFMPEG support:
By default OpenCV uses ffmpeg to read video files. OpenCV may not have been built with FFMPEG support. To find out if OpenCV was built with FFMPEG support, in terminal enter:

python -c “import cv2; print(cv2.getBuildInformation())” | grep -i ffmpeg
The output should be something like:

FFMPEG: YES

If the output is No then follow an online guide to build OpenCV from source with ffmpeg support.
py36环境下的opencv版本是3.1.0
用anaconda-navigator卸载老版本将其升级到3.4.2版本
出现下面错误

error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/highgui/src/window.cpp:626: error: (-2: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 function ‘cvDestroyAllWindows’

根据博客:https://blog.csdn.net/fdd096030079/article/details/81156811
通过这个网站——https://pypi.org/project/opencv-python/3.4.2.17/

pip install opencv-python==3.4.2.17

安装opencv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值