Python 在 Ubuntu 16 上安装 openCV 时如何在 cmake 中包含 libgtk2.0-dev 和 pkg-config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42843316/
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
How to include libgtk2.0-dev and pkg-config in cmake when installing openCV on Ubuntu 16
提问by daniel
I know there are many topics on how to install OpenCV-Python. I went over many of them and they helped me to go through some problems installing openCV-python on Ubuntu
我知道有很多关于如何安装 OpenCV-Python 的主题。我浏览了其中的许多,他们帮助我解决了在 Ubuntu 上安装 openCV-python 的一些问题
I managed to install openCV but is not properly working. When I try to run:
我设法安装了 openCV,但无法正常工作。当我尝试运行时:
import numpy
import cv2
img= cv2.imread('image.png',0)
cv2.imshow('image',img)
I get an error
我收到一个错误
error: /io/opencv/modules/highui/src/window.cpp:583: error: (-2) The function is not implemented. Rebuilt 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 cvSowImage
错误:/io/opencv/modules/highui/src/window.cpp:583:错误:(-2)该功能未实现。使用 Windows、GTK+ 2.x 或 Carbon 支持重建库。如果您使用的是 Ubuntu 或 Debian,请安装 libgtk2.0-dev 和 pkg-config,然后重新运行 cmake 或在函数 cvSowImage 中配置脚本
How do I do that? I suspect I should repeat cmake and somehow include these two libraries on it, but how?
我怎么做?我怀疑我应该重复 cmake 并以某种方式在其中包含这两个库,但是如何?
EDIT March 19 2017I followed instructions from:
编辑 2017 年 3 月 19 日我遵循了以下指示:
and
和
http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
and from:
来自:
http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html
http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html
Everytime my script include (I am running from IDLE):
每次我的脚本包括(我从 IDLE 运行):
cv2.imshow('image',img
)
cv2.imshow('image',img
)
I got the same error message:
我收到了同样的错误信息:
Traceback (most recent call last):
File "/home/dcanals/Documents/test.py", line 5, in <module>
cv2.imshow('image',img)
error: /io/opencv/modules/highgui/src/window.cpp:583: 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
I rellay do not understand what is going on. I just want to have openCV to start learning this package. I have libgtk2 and pkg-config installed. I follow step by step the instructions. Why it is not working? What should I do now to get python-openCV working? Thank you
我不明白这是怎么回事。我只是想让 openCV 开始学习这个包。我已经安装了 libgtk2 和 pkg-config。我按照说明一步一步来。为什么它不起作用?我现在应该怎么做才能让 python-openCV 工作?谢谢
EDIT March 21 2017
编辑 2017 年 3 月 21 日
I edit this post because I think I found very important documentation in: https://pypi.python.org/pypi/opencv-python
我编辑这篇文章是因为我认为我在以下位置找到了非常重要的文档:https: //pypi.python.org/pypi/opencv-python
Where is written abouth the package 'opencv-python':
哪里写了关于包“opencv-python”的:
IMPORTANT NOTE:
重要的提示:
MacOS and Linux wheels have some limitations:
video related functionality is not supported (not compiled with FFmpeg) for example cv.imshow() will not work (not compiled with GTK+ 2.x or Carbon support)
MacOS 和 Linux 轮子有一些限制:
不支持与视频相关的功能(未使用 FFmpeg 编译)例如 cv.imshow() 将不起作用(未使用 GTK+ 2.x 或 Carbon 支持编译)
SOLVED
解决了
I managed to make it work.
我设法让它工作。
The problem was I had a mix of packages, that probably were incompatible. First time I tried to install OpenCV I used opencv-python package. It didn't work, so I tried to build the official opencv with python. Nothing worked.
问题是我有一个混合的包,这可能是不兼容的。我第一次尝试安装 OpenCV 时,我使用了 opencv-python 包。它没有用,所以我尝试用python构建官方的opencv。没有任何效果。
The solution was to re-install Ubuntu 16.10 and re-install opencv from the official site.
解决方案是重新安装 Ubuntu 16.10 并从官方站点重新安装 opencv。
回答by Ashutosh Gupta
conda install -c menpo opencv=2.4.11
conda install -c menpo opencv=2.4.11
The solution is in this thread: OpenCV error: the function is not implemented
解决方法在这个线程:OpenCV error: the function is not implementation
solves my problem on Ubuntu 14.04. Although you will require to have an Anaconda2 to be able to use this. but once you have the include and libs, you can take them out and use them with your program.
解决了我在 Ubuntu 14.04 上的问题。尽管您需要有 Anaconda2 才能使用它。但是一旦你有了包含和库,你就可以把它们取出来并在你的程序中使用它们。
回答by Sherzod
Installing opencv
with pip
solved my problem:
安装opencv
与pip
解决我的问题:
pip install opencv-python
But actually it's preferred to install it with conda
但实际上最好安装它 conda
回答by Yordan Atanasoff
i just got here looking for the same the same answer... simple solution 1. install libgtk2.0-dev 2. recompile and reinstall opencv
我刚到这里寻找相同的答案...简单的解决方案 1. 安装 libgtk2.0-dev 2. 重新编译并重新安装 opencv
i'm using opencv 3.4.6 and i'm building it from source. is important to uninstall it you use
我正在使用 opencv 3.4.6 并且我正在从源代码构建它。重要的是卸载它你使用
sudo make uninstall
须藤使卸载
from the same build directory you did the make install. i didn't need to change anything in my cmake file.
来自您执行 make install 的同一构建目录。我不需要更改我的 cmake 文件中的任何内容。
回答by Raisul Islam Zaeem
I ran into the same problem, spent few days scratching my head and finding a proper solution. I indeed found a solution but before let me answer your questions first.
我遇到了同样的问题,花了几天时间摸索着找到了合适的解决方案。我确实找到了解决方案,但在此之前让我先回答您的问题。
How do I do that? I suspect I should repeat cmake and somehow include these two libraries on it, but how?
我怎么做?我怀疑我应该重复 cmake 并以某种方式在其中包含这两个库,但是如何?
pkg-config:You don't have to include "pkg-config" in cmake.
pkg-config:您不必在 cmake 中包含“pkg-config”。
[ In case if you are a newbie like me, "pkg-config" provides the necessary details for compiling and linking a program to a library. This metadata is stored in pkg-config files(files with *.pc suffix, in /usr/lib/pkgconfig
directory for example). If the system doesn't have pkg-config, it can be installed from the terminal with sudo apt-get install pkg-config
]
[ 如果您是像我这样的新手,“pkg-config”提供了编译程序并将程序链接到库所需的详细信息。此元数据存储在 pkg-config 文件中(/usr/lib/pkgconfig
例如,目录中带有 *.pc 后缀的文件)。如果系统没有 pkg-config,它可以从终端安装sudo apt-get install pkg-config
]
libgtk2.0-dev:Configure with cmake -D WITH_GTK=ON ..
while rerunning the cmake. In case if you don't have libgtk in your system, it can be installed with sudo apt-get install libgtk2.0-dev
libgtk2.0-dev:cmake -D WITH_GTK=ON ..
在重新运行 cmake 时配置。如果您的系统中没有 libgtk,可以安装它sudo apt-get install libgtk2.0-dev
My issue:The issue I had was, I configured with both -D WITH_QT = ON
and -D WITH_GTK = ON
. Although I had libgtk
in the system, for some reason it was showing this error message:
我的问题:我遇到的问题是,我同时配置了-D WITH_QT = ON
和-D WITH_GTK = ON
. 虽然我libgtk
在系统中,但出于某种原因,它显示了此错误消息:
install libgtk2.0-dev and pkg-config, then re-run cmake
安装 libgtk2.0-dev 和 pkg-config,然后重新运行 cmake
My solution:I used QT instead of GTK while rerunning the cmake.
Before rerunning, I removed libgtk2.0-dev with dpkg --purge libgtk2.0-dev
and then uninstalled opencv from build directory with make uninstall
.
我的解决方案:我在重新运行 cmake 时使用 QT 而不是 GTK。在重新运行之前,我删除了 libgtk2.0-dev ,dpkg --purge libgtk2.0-dev
然后从构建目录中卸载了 opencv make uninstall
。
Next, installed QT with sudo apt-get install libqt5-default
reran cmake from opencv build directory with -D WITH_QT = ON
and -D WITH_GTK = OFF
and finally make install
. Guess what! It's functioning back again!! but with a different GUI from QT.
接下来,安装QT与sudo apt-get install libqt5-default
来自OpenCV的构建目录中重新运行cmake的-D WITH_QT = ON
和-D WITH_GTK = OFF
最后make install
。你猜怎么着!又恢复运行了!!但使用与 QT 不同的 GUI。
In my opinion vice-versa is also possible, with -D WITH_GTK = ON
, just make sure that you have libgtk2.0-dev
installed properly in your system. [For some reason didn't work in my case though :( ]
在我看来,反之亦然也是可能的,-D WITH_GTK = ON
只需确保您已libgtk2.0-dev
在系统中正确安装。[由于某种原因在我的情况下不起作用:(]