C++ OpenCV GTK+2.x 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28776053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV GTK+2.x error
提问by Maxian Nicu
I had installed OpenCV following these steps (). After trying to compile one examples,i got this error :
我按照这些步骤安装了 OpenCV ()。尝试编译一个示例后,我收到此错误:
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
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?
如何解决?
回答by KiranCP
First check whether libgtk2.0-dev is installed properly. If you have installed aptitude package manager, run the following:
首先检查libgtk2.0-dev是否安装正确。如果您已经安装了 aptitude 包管理器,请运行以下命令:
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
您需要再次构建文件。找到您的 OpenCV 文件夹。创建一个新文件夹并将其命名为 release。进入这个文件夹。例如
cd /home/user_name/OpenCv
mkdir Release
cd Release
Now build using cmake with following command:
现在使用 cmake 和以下命令构建:
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,
记得WITH_GTK=ON
在 cmake 期间放置。在这一步输入命令后,
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.
这应该可以解决您的问题。如果您破坏了 libgtk2.0-dev 的依赖项,请使用 aptitude 安装 libgtk2.0-dev 的新副本。
sudo aptitude install libgtk2.0-dev
回答by Nic Szerman
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
如果您使用 opencv-python pip 包安装了 OpenCV,请注意以下注释,摘自https://pypi.python.org/pypi/opencv-python
IMPORTANT NOTEMacOS 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)
重要提示MacOS 和 Linux 轮子目前有一些限制:
- 不支持视频相关功能(未使用 FFmpeg 编译)
- 例如
cv2.imshow()
将不起作用(未使用 GTK+ 2.x 或 Carbon 支持编译)
Also note that to install from another source, first you must remove the opencv-python package
另请注意,要从其他来源安装,首先必须删除 opencv-python 包
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/
要在 Ubuntu 中安装 OpenCV,我遵循了本指南,它运行得非常好:http: //www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
回答by hris.to
In order to improve @Nic Szer'sanswer I want to explain how to fix this error on Mac OS in three simple steps.
为了改进@Nic Szer 的回答,我想通过三个简单的步骤解释如何在 Mac OS 上修复此错误。
Remove installed OpenCV version to avoid mess up later
pip3 uninstall opencv-python
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
Finally, use conda to install working version of OpenCV
conda install -c menpo opencv3
删除已安装的 OpenCV 版本以避免以后搞砸
pip3 uninstall opencv-python
将您的 python 版本降低到 3.5(当前版本 3.6 有 conda 问题,我们将用它来安装 OpenCV)
conda install python=3.5
最后,使用 conda 安装 OpenCV 的工作版本
conda install -c menpo opencv3
And then voila: OpenCV will start working on your Mac OS(Siera 10.12.4).
然后瞧:OpenCV 将开始在您的 Mac OS(Siera 10.12.4)上运行。
回答by SeCp
@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.
@oxydron/Elliott Miller:我有预装 gtk 3 的 Ubuntu 16.04 LTS 环境。对于 Caffe 构建(主分支),我遇到了同样的错误,请尝试以下步骤,可能对您有用。
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
宾果游戏错误消失了......在我的python caffe代码中
Please note:
请注意:
The CMAKE configuration should reflect GTK+ 3.x instead of GTK+ 2.x
CMAKE 配置应该反映 GTK+ 3.x 而不是 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
回答by MK HASAN
I have the solved using Anaconda 3 installing on Ubuntu 16.04.
我使用 Anaconda 3 安装在 Ubuntu 16.04 上解决了这个问题。
I have used pycharm editor for my python code.
我在我的 python 代码中使用了 pycharm 编辑器。
I am using python 3.6 version.
我正在使用 python 3.6 版本。
I solved the issue using these processes.
我使用这些过程解决了这个问题。
IDEA: we need to install the package opencv-contrib-python package from the pycharm.
IDEA:我们需要从pycharm安装包opencv-contrib-python包。
回答by mrk
I have had to deal with this issue a couple of times, this is what has worked consistently thus far:
我不得不多次处理这个问题,这是迄今为止一直有效的方法:
conda remove opencv
conda install -c menpo opencv
pip install --upgrade pip
pip install opencv-contrib-python
回答by Abhishek Thombre
I tried several of the answers mentioned above the one that worked for me in ubuntu is mentioned in the following steps:
我尝试了上面提到的几个答案,以下步骤中提到了在 ubuntu 中对我有用的答案:
- Firstly, remove the current opencv package that is installed in your system by typing in the following command in the terminal
conda remove opencv
. - 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
. - Later on install the opencv package again by giving the following input in terminal
conda install -c menpo opencv3
- 首先,通过在终端中键入以下命令来删除系统中安装的当前 opencv 包
conda remove opencv
。 - 如果你的 python 版本是 3.6 或更高版本,那么将其更改为稳定版本,可以通过键入
conda install python=3.5
. - 稍后通过在终端中提供以下输入再次安装 opencv 包
conda install -c menpo opencv3
回答by Ahmed J.
In case what they mentioned above doesn't work, try:
如果他们上面提到的不起作用,请尝试:
pip install opencv-python
for python2, or
对于python2,或
pip3 install opencv-python
for python3
对于python3
回答by Z Cao
I had the same problem, and fixed it by simply reinstalling opencv.
我遇到了同样的问题,只需重新安装 opencv 即可解决。
There is no need to uninstall it first.
无需先卸载它。
回答by F1iX
For me (Arch Linux, Anaconda with Python 3.6), installing from the suggested channels menpo
or loopbio
did not change anything. My solution was to
对我来说(Arch Linux、Anaconda 和 Python 3.6),从建议的渠道安装menpo
或loopbio
没有改变任何东西。我的解决方案是
- install pkg-config (
sudo pacman -Syu pkg-config
), - remove opencv from the environment (
conda remove opencv
) and - re-install opencv from the conda-forge channel (
conda install -c conda-forge opencv
)
- 安装 pkg-config (
sudo pacman -Syu pkg-config
), - 从环境中删除 opencv (
conda remove opencv
) 和 - 从 conda-forge 频道 (
conda install -c conda-forge opencv
)重新安装 opencv
conda list
now returns opencv 3.3.0 py36_blas_openblas_203 [blas_openblas] conda-forge
and all windows launched using cv2 are working fine.
conda list
现在返回opencv 3.3.0 py36_blas_openblas_203 [blas_openblas] conda-forge
并且所有使用 cv2 启动的窗口都工作正常。