Error using cv2.imshow (Unspecified error)

I am following this tutorial to do angle detection and I need to use cv2.imshow. Here is my code:

import cv2 import numpy as np filename = '1.jpg' img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) #result is dilated for marking the corners, not important dst = cv2.dilate(dst,None) # Threshold for an optimal value, it may vary depending on the image. img[dst>0.01*dst.max()]=[0,0,255] cv2.imshow('dst',img) 

I got 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 /root/mc-x86-2.7/conda-bld/opencv-3_1482254836916/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 545 Traceback (most recent call last): File "<stdin>", line 1, in <module> cv2.error: /root/mc-x86-2.7/conda-bld/opencv-3_1482254836916/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: 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 

So, I installed libgtk2.0-dev and pkg-config, but this did not solve the problem. The error message says it starts cmake, but where? There is no CMakeLists.txt file in my drive.

Then I follow some answers on this website, like this one : first, I downloaded OpenCV directly to the website, and I run cmake, make and make install. Everything is fine, but I still have the same error when I use Anaconda, but received a different message when I open Python from / usr / bin / python:

 init done opengl support available 

At the moment, I can’t show my image. What should I do?

+5
source share
1 answer

In my question, I had two problems:

  • From / usr / lib / python, I could not show the image, but did not have an error;

  • In the Anaconda Framework, the imshow function has not been implemented.

For the first problem, it was very simple because I did not read the documentation correctly. It talks about the cv2.waitKey() function:

In addition to binding keyboard events, this function also handles many other GUI events, so you MUST use it to actually display the image.

So, I just need to call cv2.waitKey (1) after cv.imshow () to show the image.

For the second problem,

  • I used a manual method to solve it (I'm not sure if this is better, but it works). I replaced all the libopencv* files in the /home/user/anaconda3/lib folder with the libopencv* files in the /usr/local/lib/ folder.

  • After that I had to update the file `/home/user/anaconda3/lib/libstdc++.so 'with the file' / usr / lib / i386-linux-gnu / libstdc ++. So '.


There is also a cleaner alternative, but you must restart the installation process to do this. When you run the cmake command, the -D CMAKE_INSTALL_PREFIX parameter -D CMAKE_INSTALL_PREFIX should refer to your anaconda folder (for me it is /home/pierre/anaconda3/ ). After that, you just need to continue the installation, as usual:

 make sudo make install 

Now you can use OpenCV with Anacaonda (but only with Anaconda, it does not work if you load /usr/bin/python ).

+2
source

Source: https://habr.com/ru/post/1261955/


All Articles