opencv 3.0 python imshow error

2019-03-02 10:55发布

问题:

I am using OpenCV 3.0 with python 2.7.6 and ROS Indigo. I installed it through and am attempting to do some ORB object detection. Ironically, all of the actual detection code seems to run without issue. The code that doesn't work is imshow. It gives 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 /tmp/buildd/ros-indigo-opencv3-2.9.6-1trusty-20150512-2345/modules/highgui/src/window.cpp, line 534

I haven't seen any of this during my googling. Any help?

回答1:

As the message says, you need to rebuild the library with gtk. Enter into your OpenCV folder and create a new folder with name Release.

cd ~/OpenCV
mkdir Release
cd Release

Now you need to rebuild OpenCV. Use the following command

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..

Remember to use WITH_GTK=ON while building. After this, enter these command

make
sudo make install

Now run your code. This should make it work. You can delete the old build folder.



回答2:

The complete process involves recompiling OpenCV 3 and copying those new compiled libraries with the correct options to the ROS environment.

I ran into the same issue while programming a Baxter robot and needed to solve it.

So the following needs to be done:

  • Download the latest stable release http://opencv.org/downloads.html

    • Extract it at some place and follow KiranCP's steps. This will take some time compiling depending on your machine.
    • After completion you need to copy the libraries which is shown in the next step.
    • The information is taken from this site -> https://sites.google.com/site/rameyarnaud/research/ros/latest-opencv-in-ros but I will post the information here:

      sudo chmod a+rw -R /opt/ros/`rosversion -d`/lib/
      mkdir /opt/ros/`rosversion -d`/lib/libopencv_backup
      mv /opt/ros/`rosversion -d`/lib/libopencv*.so* /opt/ros/`rosversion -d`/lib/libopencv_backup
      cp <OPENCV_BUILD_FOLDER>/lib/libopencv* /opt/ros/`rosversion -d`/lib/
      ls -hal /opt/ros/`rosversion -d`/lib/libopencv*
      

      Your ROS environment needs to be setup correctly otherwise rosversion will return .

After this you should be able to use OpenCV 3 and imshow properly.