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.
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 :( ]
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
Make the commands as follows.
$ conda remove opencv $ conda install -c menpo opencv $ pip install --upgrade pip $ pip install opencv-contrib-python
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
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.
Installing opencv
with pip
solved my problem:
pip install opencv-python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With