请帮助我在ubuntu 14.04中安装opencv dev版本3.0.0以及如何在opencv中构建文件夹并创建库。我之前在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
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=ReleaseDebug
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
[optional]构建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静态链接,并且会占用大量内存。构建。从构建目录执行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.
例如 <cmake_build_dir>/bin/opencv_test_core
OpenCV安装页面