OpenCV GTK+2.x error

2020-02-01 00:56发布

I had installed OpenCV following these steps (). After trying to compile one examples,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 cvNamedWindow, file /home/nick/.Apps/opencv/modules/highgui/src/window.cpp, line 516
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/nick/.Apps/opencv/modules/highgui/src/window.cpp:516: 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 cvNamedWindow

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4)
project(threadTest)

find_package( OpenCV REQUIRED )


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pthread")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "/home/nick/ClionProjects/threadTest")

set(SOURCE_FILES main.cpp)
add_executable(threadTest ${SOURCE_FILES})
target_link_libraries( threadTest ${OpenCV_LIBS} )

How to solve it?

12条回答
ゆ 、 Hurt°
2楼-- · 2020-02-01 01:16

I tried several of the answers mentioned above the one that worked for me in ubuntu is mentioned in the following steps:

  1. Firstly, remove the current opencv package that is installed in your system by typing in the following command in the terminal conda remove opencv.
  2. If your python version is 3.6 or above then change it into the stable version which can be done by typing in conda install python=3.5.
  3. Later on install the opencv package again by giving the following input in terminal conda install -c menpo opencv3
查看更多
虎瘦雄心在
3楼-- · 2020-02-01 01:16

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.

查看更多
欢心
4楼-- · 2020-02-01 01:17

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).

查看更多
祖国的老花朵
5楼-- · 2020-02-01 01:17

@oxydron/Elliott Miller: I have Ubuntu 16.04 LTS environment with gtk 3 pre installed. I got the same error for Caffe build (master branch), Try the following steps, may be it should work for you.

sudo apt-get install libgtk-3-dev
cmake .. (WITH_GTK=ON and other settings), 
make

And bingo the error was gone... in my python caffe code

Please note:

The CMAKE configuration should reflect GTK+ 3.x instead of GTK+ 2.x

       GUI: 
--     QT:                          NO
--     GTK+ 3.x:                    YES (ver 3.18.9)
--     GThread :                    YES (ver 2.48.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
查看更多
狗以群分
6楼-- · 2020-02-01 01:23

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/

查看更多
放荡不羁爱自由
7楼-- · 2020-02-01 01:23

I have the solved using Anaconda 3 installing on Ubuntu 16.04.

I have used pycharm editor for my python code.

I am using python 3.6 version.

I solved the issue using these processes.

IDEA: we need to install the package opencv-contrib-python package from the pycharm.

enter image description here

查看更多
登录 后发表回答