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?
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 .
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
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()
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.
Source: Stackoverflow.com