18

I know there are many topics on how to install OpenCV-Python. I went over many of them and they helped me to go through some problems installing openCV-python on Ubuntu

I managed to install openCV but is not properly working. When I try to run:

import numpy
import cv2
img= cv2.imread('image.png',0)
cv2.imshow('image',img)

I get an error

error: /io/opencv/modules/highui/src/window.cpp:583: error: (-2) The function is not implemented. Rebuilt 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 cvSowImage

How do I do that? I suspect I should repeat cmake and somehow include these two libraries on it, but how?

EDIT March 19 2017 I followed instructions from:

http://milq.github.io/install-opencv-ubuntu-debian/

and

http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/

and from:

http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

Everytime my script include (I am running from IDLE):

cv2.imshow('image',img)

I got the same error message:

Traceback (most recent call last):

      File "/home/dcanals/Documents/test.py", line 5, in <module>
        cv2.imshow('image',img)
    error: /io/opencv/modules/highgui/src/window.cpp:583: 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

I rellay do not understand what is going on. I just want to have openCV to start learning this package. I have libgtk2 and pkg-config installed. I follow step by step the instructions. Why it is not working? What should I do now to get python-openCV working? Thank you

EDIT March 21 2017

I edit this post because I think I found very important documentation in: https://pypi.python.org/pypi/opencv-python

Where is written abouth the package 'opencv-python':

IMPORTANT NOTE:

MacOS and Linux wheels have some limitations:

video related functionality is not supported (not compiled with FFmpeg) for example cv.imshow() will not work (not compiled with GTK+ 2.x or Carbon support)


SOLVED

I managed to make it work.

The problem was I had a mix of packages, that probably were incompatible. First time I tried to install OpenCV I used opencv-python package. It didn't work, so I tried to build the official opencv with python. Nothing worked.

The solution was to re-install Ubuntu 16.10 and re-install opencv from the official site.

Cœur
  • 37,241
  • 25
  • 195
  • 267
daniel_hck
  • 1,100
  • 3
  • 19
  • 38
  • 1
    Follow this nice tutorial: http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/ – ZdaR Mar 17 '17 at 05:25
  • I followed the link instructions. Very clear and everything went as expected for the installation and configuration. However, when I tried the same script I got the same error message. I very lost what should I do. I am willing to reinstall what is need it, but don't know what – daniel_hck Mar 18 '17 at 16:55
  • Are you sure, you ran this command in particular ? `sudo apt-get install libgtk2.0-dev` – ZdaR Mar 18 '17 at 17:05
  • Yes, this is installed. I followed step by step the link (except for the virtual enviroment). So, if I want to start over (again), should I delete all I have installed so far? I am afraid I am installing so many times that something is wrong. How can I delete all opencv installation to start over? or any other idea what I can do? – daniel_hck Mar 18 '17 at 20:09

8 Answers8

6

I think that cmake is too complex in the scenario. I have solved the issue after removing OpenCV 3.4.2 and installing OpenCV 4.2 on Ubuntu 18.04

  1. Make the commands as follows.

    $ conda remove opencv $ conda install -c menpo opencv $ pip install --upgrade pip $ pip install opencv-contrib-python

  2. Check the version in the terminal.

Open the Python interface:

>>> import cv2

>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.2.0 ==============

Reference: https://pythonpedia.com/en/knowledge-base/40207011/opencv-not-working-properly-with-python-on-linux-with-anaconda--getting-error-that-cv2-imshow---is-not-implemented

Cheers

Jon.H
  • 794
  • 2
  • 9
  • 23
Mike Chen
  • 377
  • 3
  • 5
6

I've met this problem with the newest opencv-python. Downgrade opencv-python works for me.

pip install opencv-python==4.0.1.23

Or

pip install opencv-python==4.0.0.21
Luan Pham
  • 569
  • 1
  • 7
  • 13
5

conda install -c menpo opencv=2.4.11

The solution is in this thread: OpenCV error: the function is not implemented

solves my problem on Ubuntu 14.04. Although you will require to have an Anaconda2 to be able to use this. but once you have the include and libs, you can take them out and use them with your program.

Ashutosh Gupta
  • 670
  • 7
  • 15
5

Installing opencv with pip solved my problem:

pip install opencv-python
Scott
  • 4,974
  • 6
  • 35
  • 62
4

I ran into the same problem, spent few days scratching my head and finding a proper solution. I indeed found a solution but before let me answer your questions first.

How do I do that? I suspect I should repeat cmake and somehow include these two libraries on it, but how?

pkg-config: You don't have to include "pkg-config" in cmake.

[ In case if you are a newbie like me, "pkg-config" provides the necessary details for compiling and linking a program to a library. This metadata is stored in pkg-config files(files with *.pc suffix, in /usr/lib/pkgconfig directory for example). If the system doesn't have pkg-config, it can be installed from the terminal with sudo apt-get install pkg-config ]

libgtk2.0-dev: Configure with cmake -D WITH_GTK=ON .. while rerunning the cmake. In case if you don't have libgtk in your system, it can be installed with sudo apt-get install libgtk2.0-dev

My issue: The issue I had was, I configured with both -D WITH_QT = ON and -D WITH_GTK = ON. Although I had libgtk in the system, for some reason it was showing this error message:

install libgtk2.0-dev and pkg-config, then re-run cmake

My solution: I used QT instead of GTK while rerunning the cmake. Before rerunning, I removed libgtk2.0-dev with dpkg --purge libgtk2.0-dev and then uninstalled opencv from build directory with make uninstall.

Next, installed QT with sudo apt-get install libqt5-default reran cmake from opencv build directory with -D WITH_QT = ON and -D WITH_GTK = OFF and finally make install. Guess what! It's functioning back again!! but with a different GUI from QT.

In my opinion vice-versa is also possible, with -D WITH_GTK = ON, just make sure that you have libgtk2.0-dev installed properly in your system. [For some reason didn't work in my case though :( ]

  • 1
    +1 because this actually solves the source problem and not just "uninstalling and reinstalling" with a package manager. If you have to build your own OpenCV from source (like when needing CUDA support) QT worked perfectly, and GTK did not. Reinstalling with a package manager will remove CUDA support. I'm using Ubuntu 18.04 with OpenCV build 4.5.5. – Djinn Apr 11 '22 at 18:21
2

Installing libgtk2.0-dev and pkg-config file resolved the error. (Tested in Opencv4)

You have to rerun cmake from OpenCV build directory.

sudo apt-get install pkg-config
sudo apt-get install libgtk2.0-dev
AHL
  • 493
  • 5
  • 8
1

i just got here looking for the same the same answer... simple solution 1. install libgtk2.0-dev 2. recompile and reinstall opencv

i'm using opencv 3.4.6 and i'm building it from source. is important to uninstall it you use

sudo make uninstall

from the same build directory you did the make install. i didn't need to change anything in my cmake file.

1

I'm using Miniconda and have installed OpenCV-Python using pip. I encountered this issue, and then I resolved it by running:

sudo apt install libgtk2.0-dev pkg-config
pip install opencv-contrib-python
doneforaiur
  • 1,308
  • 7
  • 14
  • 21
Alicas
  • 11
  • 2