OpenCV v1/v2 error: the function is not implemented

Question:

I’m trying to get OpenCV working with Python on my Ubuntu machine. I’ve downloaded and installed OpenCV, but when I attempt to run the following python code (which should capture images from a webcam and push them to the screen)

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
capture = cv.CaptureFromCAM(0)

def repeat():
    frame = cv.QueryFrame(capture)
    cv.ShowImage("w1", frame)
    time.sleep(10)

while True:
    repeat()

I get the following 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

So I do what they ask: install the packages, move to the folder from whence I installed OpenCV, and run

sudo make uninstall
make
sudo make install

But when I try to run the python, it gives me the same error. Am I missing something?

Asked By: Dan

||

Answers:

If it’s giving you errors with gtk, try qt.

sudo apt-get install libqt4-dev
cmake -D WITH_QT=ON ..
make
sudo make install

If this doesn’t work, there’s an easy way out.

sudo apt-get install libopencv-*

This will download all the required dependencies(although it seems that you have all the required libraries installed, but still you could try it once). This will probably install OpenCV 2.3.1 (Ubuntu 12.04). But since you have OpenCV 2.4.3 in /usr/local/lib include this path in /etc/ld.so.conf and do ldconfig. So now whenever you use OpenCV, you’d use the latest version. This is not the best way to do it but if you’re still having problems with qt or gtk, try this once. This should work.

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 (e.g., at the line of cv2.namedWindow(name) with error: cv2.error: OpenCV(3.4.2). The function is not implemented.). 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
Answered By: Froyo

I hope this answer is still useful, despite problem seems to be quite old.

If you have Anaconda installed, and your OpenCV does not support GTK+ (as in this case), you can simply type

conda install -c menpo opencv=2.4.11

It will install suitable OpenCV version that does not produce a mentioned error. Besides, it will reinstall previously installed OpenCV if there was one as a part of Anaconda.

Answered By: Artem S

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

Answered By: Nic Szerman

Before installing libgtk2.0-dev and
pkg-config or libqt4-dev. Make sure that you have uninstalled opencv. You can confirm this by running import cv2 on your python shell. If it fails, then install the needed packages and re-run cmake .

Answered By: user618677

Don’t waste your time trying to resolve this issue, this was made clear by the makers themselves. Instead of cv2.imshow() use this:

img = cv2.imread('path_to_image')
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic')
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
plt.show()
Answered By: purna15111

It’s because of ‘opencv-python-headless’. Uninstall it!

pip uninstall opencv-python-headless
Answered By: Ehsan Akbaritabar

This is due to some kind of overlap in opencv-python against opencv-contrib-python, opencv-python-headless packages. Simply uninstall both headless & contrib.

pip uninstall opencv-contrib-python

pip uninstall opencv-python-headless

Then uninstall opencv-python.

pip uninstall opencv-python

it’s a clean slate here.
Then install only OpenCV-python which will clear you out of this issue.

pip install opencv-python
Answered By: Sai Nishanth

This strange problem started to happen to me as well, in one virtual environment out of several that I’m using. What solved it is to uninstall opencv and then reinstall it:

pip uninstall opencv-python
pip install opencv-python
Answered By: TheTomer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.