0

my code:

import cv2
img = cv2.imread("dU4fHDw-Ho.jpg", cv2.IMREAD_GRAYSCALE)

cv2.imshow('image', img)
k = cv2.waitKey(0)
if k == 27:
    cv2.destroyWindow()

And i get this error:

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 /io/opencv/modules/highgui/src/window.cpp, line 583
Traceback (most recent call last):
  File "simpleopencv.py", line 4, in <module>
    cv2.imshow('image', img)
cv2.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'm using linux mint KDE What might be the problem?

Update1: Opencv works fine with python2.7 but not working for python3.5

Update2: As it turns out running the script as Jack Gold suggested actually worked but since i already had cv2 folder in my /usr/local/lib/python3.5/dist-packages/ (which was installed using PIP i think) conflicted with the one install using the script and python3 kept using the PIP version so, I deleted that cv2 folder and restarted and everything worked fine.

3
  • You're missing some libraries, please refer to my answer here - stackoverflow.com/a/44263478/7220609 Commented Jun 8, 2017 at 11:11
  • i stil get the same error Commented Jun 8, 2017 at 12:34
  • well, actually it did fixed it, thanks Commented Jun 9, 2017 at 14:42

5 Answers 5

2

Nothing to worry buddy,I suffered the same and this is how I got rid of this error, see if you have installed opencv via pip or pip3 or apt-get, first you gotta uninstall it

sudo pip3 uninstall (what you wrote while installing)

or sudo pip uninstall (what you wrote while installing)

or sudo apt-get remove (what you wrote while installing)

and afterwards build the opencv package from source code from github.

git clone https://github.com/opencv/opencv.git

cd ~/opencv

mkdir release

cd release

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

make

sudo make install

This will solve the problem. All the best.

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure about the problem since it works fine for me. But just as an alternative, use plt.imshow() from Matplotlib, it also works fine.

4 Comments

just tried, but matplotlib's image is quite different than opencv's(using python 2.7). It's displaying grayscale image but matplotlibs's image looks green
plt.imshow() also accepts another parameter "cmap", try plt.imshow(img, cmap="gray") to show image in gray scale
does that means I don't have to pass cv2.IMREAD_GRAYSCALE in cv2.imread() ?
Yes, it can take an array of shape (n, m, 3) and show it in gray scale.
0

Did you install OpenCV using pip? If you did, note that as mentioned here, this is the unofficial package for OpenCV and does not have support for GUI windows (cv2.imshow(), etc)

I would recommend using Anaconda to install opencv using conda install -c conda-forge opencv=3.2.0 or conda install -c menpo opencv3=3.2.0

Comments

0

Easier solution is provided by conda

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

You may see the following error after conda install

Traceback (most recent call last):
    File "./test.py", line 21, in <module>
      import cv2
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

Just install openblas library would solve

yum install openblas-devel -y

Reference

[sdvillal | github] https://github.com/conda-forge/opencv-feedstock/issues/43

Comments

0

You should use absolute path to read your image.

For me on Mac OS:

img = cv2.imread('/Users/nicholasleung/Documents/after effect/AL.png')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.