【问题标题】:Integrating opencv 3.0.0 in ubuntu for python and c++ and building lib using cmake在 ubuntu 中为 python 和 c++ 集成 opencv 3.0.0 并使用 cmake 构建 lib
【发布时间】:2014-05-10 12:22:07
【问题描述】:

请帮助我在 ubuntu 14.04 中安装 opencv dev 版本 3.0.0 以及如何在 opencv 中制作 build 文件夹并创建库。我之前在 ubuntu 中使用了 2.4.9,一切正常,但我需要 3.0.0,因为我需要其中包含的新命令。那么如何整合opencv 3.0.0,彻底移除2.4.9呢?

如果此方法没有提供正确的构建/发布文件夹怎么办?

使用 CMake 从源代码构建 OpenCV,使用命令行 创建一个临时目录,我们将其记为 ,您要在其中放置生成的 Makefile、项目文件以及目标文件和输出二进制文件。

输入并键入

cmake [<some optional parameters>] <path to the OpenCV source directory>

例如

cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

进入创建的临时目录(),继续:

make -j8 # -j8 runs 8 jobs in parallel.
     # Change 8 to number of hardware threads available.
sudo make install

【问题讨论】:

  • 嘿,3.0.0 什么意思?在网站 (opencv.org) 上,今天没有关于自 2.4.9 以来的新版本的信息?
  • kebs,3.0 是 master 分支,2.4.9 是稳定分支。
  • user3623269,如果你分叉/克隆了 github 存储库,它所需要的只是一个 git checkout master(并且可能需要更新)和重建
  • @berak 我从 git 克隆了它,但是按照 opencv 页面 link 上的说明进行操作后,我的构建或发布目录没有任何可用于链接到我的代码块的 .lib 或 .so 文件链接器文件。所以请告诉我如何正确制作构建目录以及删除不必要的程序/文件的内容和方法。
  • 不可能,如果你不说,它在哪里(以及为什么)停止了(不,我不会为你重写教程)

标签: python c++ opencv ubuntu computer-vision


【解决方案1】:

在 Linux 中安装 这些步骤已针对 Ubuntu 10.04 进行了测试,但也应适用于其他发行版。

必需的包

GCC 4.4.x or later
CMake 2.8.7 or higher
Git
GTK+2.x or higher, including headers (libgtk2.0-dev)
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
[optional] libtbb2 libtbb-dev
[optional] libdc1394 2.x
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev

可以使用终端和以下命令或使用 Synaptic Manager 安装软件包:

[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

获取 OpenCV 源代码

您可以使用最新的稳定 OpenCV 版本,也可以从我们的 Git 存储库中获取最新的快照。

Getting the Latest Stable OpenCV Version
Go to our downloads page.
Download the source archive and unpack it.
Getting the Cutting-edge OpenCV from the Git Repository
Launch Git client and clone OpenCV repository. If you need modules from OpenCV contrib repository then clone it too.

例如

cd ~/<my_working_directory>
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
Building OpenCV from Source Using CMake

创建一个临时目录,我们记为 ,您要在其中放置生成的 Makefile、项目文件以及目标文件和输出二进制文件并进入那里。

例如

cd ~/opencv
mkdir build
cd build
Configuring. Run cmake [<some optional parameters>] <path to the OpenCV source directory>

例如

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
or cmake-gui





set full path to OpenCV source code, e.g. /home/user/opencv
set full path to <cmake_build_dir>, e.g. /home/user/opencv/build
set optional parameters
run: “Configure”
run: “Generate”

部分参数说明

build type: CMAKE_BUILD_TYPE=Release\Debug
to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to <path to opencv_contrib/modules/>
set BUILD_DOCS for building documents
set BUILD_EXAMPLES to build all examples

[可选] 构建 python。设置以下python参数:

PYTHON2(3)_EXECUTABLE = <path to python>
PYTHON_INCLUDE_DIR = /usr/include/python<version>
PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python<version>
PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython<version>.so
PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python<version>/dist-packages/numpy/core/include/
[optional] Building java.

未设置参数:BUILD_SHARED_LIBS

取消设置 BUILD_EXAMPLES、BUILD_TESTS、BUILD_PERF_TESTS 也很有用 - 因为它们都将与 OpenCV 静态链接,并且会占用大量内存。 建造。从build目录执行make,建议多线程执行

例如

make -j7 # runs 7 jobs in parallel
[optional] Building documents. Enter <cmake_build_dir/doc/> and run make with target “html_docs”

例如

cd ~/opencv/build/doc/
make -j7 html_docs

要安装库,从构建目录执行

sudo make install
[optional] Running tests

从 OpenCV 额外存储库中获取所需的测试数据。 例如

git clone https://github.com/Itseez/opencv_extra.git
set OPENCV_TEST_DATA_PATH environment variable to <path to opencv_extra/testdata>.
execute tests from build directory.

例如

&lt;cmake_build_dir&gt;/bin/opencv_test_core

致谢:OpenCV 安装页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 2020-06-20
    • 2015-06-05
    • 2020-08-12
    相关资源
    最近更新 更多