OpenCV not working properly with python on Linux w

2020-01-30 03:48发布

This is the exact error that I am getting. My OS is Ubuntu 16.10.

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

my code is:

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 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

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.

12条回答
【Aperson】
2楼-- · 2020-01-30 04:23

I followed this tutorial (OpenCV GTK+2.x error) and did the following. It worked for me :

  1. install the packages : libgtk2.0-dev and pkg-config
  2. cd to your opencv directory
  3. mkdir Release
  4. cd Release
  5. Run the command : cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..
  6. make
  7. sudo make install
查看更多
叛逆
3楼-- · 2020-01-30 04:25

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

IMPORTANT NOTE MacOS 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)

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

查看更多
甜甜的少女心
4楼-- · 2020-01-30 04:25

For me (Arch Linux, Anaconda with Python 3.6), installing from the suggested channels menpo or loopbio did not change anything. My solution (see related question) was to

  1. install pkg-config (sudo pacman -Syu pkg-config),
  2. remove opencv from the environment (conda remove opencv) and
  3. re-install opencv from the conda-forge channel (conda install -c conda-forge opencv)

conda list now returns opencv 3.3.0 py36_blas_openblas_203 [blas_openblas] conda-forgeand all windows launched using cv2 are working fine.

查看更多
贪生不怕死
5楼-- · 2020-01-30 04:25

Remove opencv from anaconda=

conda remove opencv

Then, reinstall opencv using pip:

pip install opencv

This is working for me.

查看更多
Rolldiameter
6楼-- · 2020-01-30 04:25

My Envirment is Win10, and I added the anaconda path to the environment variables's PATH’,the cv2.imshow worked

C:\Users\user\Anaconda3
C:\Users\user\Anaconda3\Scripts

Then restart the windows

查看更多
倾城 Initia
7楼-- · 2020-01-30 04:34

If you are running inside docker then you may get this error.Solution uninstall current and install the headless one

pip install opencv-python==3.4.5.20

pip install opencv-contrib-python==3.4.5.20

If you are writing to the image and displaying it, you may need the following

apt-get update && apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender1

And if you are wondering how to get the display from Docker, it is possible via X11 in your host

查看更多
登录 后发表回答