OpenCV GTK+2.x error

前端 未结 14 2099
轮回少年
轮回少年 2020-12-03 07:16

I had installed OpenCV following these steps (). After trying to compile one examples,i got this error :

OpenCV Error: Unspecified error (The function is no         


        
相关标签:
14条回答
  • 2020-12-03 07:46

    In order to improve @Nic Szer's answer I want to explain how to fix this error on Mac OS in three simple steps.

    1. Remove installed OpenCV version to avoid mess up later

      pip3 uninstall opencv-python 
      
    2. Lower your python version to 3.5 (current version 3.6 has problems with conda which we will use to install OpenCV)

      conda install python=3.5
      
    3. Finally, use conda to install working version of OpenCV

      conda install -c menpo opencv3 
      

    And then voila: OpenCV will start working on your Mac OS(Siera 10.12.4).

    0 讨论(0)
  • 2020-12-03 07:47

    If someone else ends up here like I did after installing OpenCV using vcpkg on Ubuntu, there is a known issue with vcpkg where you'll end up with the exact same error message as the top of this post with no access to highgui:

    OpenCV(4.3.0) Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support.
    If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow,
    file .../vcpkg/buildtrees/opencv4/src/4.3.0-0c6047baf6.clean/modules/highgui/src/window.cpp, line 634
    Caught exception: OpenCV(4.3.0) .../vcpkg/buildtrees/opencv4/src/4.3.0-0c6047baf6.clean/modules/highgui/src/window.cpp:634:
    error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support.
    If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
    

    The problem is vcpkg passes in the build option -DWITH_GTK=OFF when building OpenCV. The open issue: https://github.com/microsoft/vcpkg/issues/12621

    The workaround is the following:

    • edit the file vcpkg/ports/opencv4/portfile.cmake
    • find the line that says -DWITH_GTK=OFF and change it to say -DWITH_GTK=ON
    • run ./vcpkg remove opencv4
    • run sudo apt-get install libgtk2.0-dev pkg-config
    • re-install OpenCV with ./vcpkg install opencv4 or whichever vcpkg command you used
    0 讨论(0)
  • 2020-12-03 07:48

    First check whether libgtk2.0-dev is installed properly. If you have installed aptitude package manager, run the following:

    sudo aptitude search libgtk2.0-dev
    

    It should return like this:

    i  libgtk2.0-dev              - development files for the GTK+ library 
    p  libgtk2.0-dev:i386         - development files for the GTK+ library
    

    You need to build the files once again.Locate your OpenCV folder. Create a new folder and name it as release. Enter into this folder. For example

    cd /home/user_name/OpenCv
    mkdir Release
    cd Release
    

    Now build using cmake with 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 put WITH_GTK=ON during cmake. After this step enter the command,

    make
    sudo make install
    

    This should resolve your problem.If you have broken dependencies for libgtk2.0-dev, then install a fresh copy of libgtk2.0-dev using aptitude.

    sudo aptitude install libgtk2.0-dev
    
    0 讨论(0)
  • 2020-12-03 07:51

    If you installed OpenCV using the opencv-python pip package, 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

    To install OpenCV in Ubuntu I followed this guide, and it worked perfectly fine: http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/

    0 讨论(0)
  • 2020-12-03 07:59

    I have fixed this issue by replacing

    cvDestroyWindow("showImage");
    

    by

    cvDestroyWindow("ShowImage");
    
    0 讨论(0)
  • 2020-12-03 08:00

    I was using windows OS . I have gone through many stuffs in order to sort this problem . At last i just reinstall the opencv and cmake and it worked without any error.

    0 讨论(0)
提交回复
热议问题