按照步骤来一步通过!!! 1. 环境准备
sudo apt-get update
sudo apt-get install build-essential -y
sudo apt-get install cmake git libavcodec-dev libavformat-dev -y
sudo apt-get update
sudo apt-get install libgtk2.0-dev libswscale-dev libopenexr-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install python-dev-is-python3 python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev
添加源:
sudo gedit /etc/apt/sources.list
(文件末尾添加)
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
sudo apt-get update
sudo apt-get install libjasper1 libjasper-dev libdc1394-22-dev
2. 下载opencv4.1.0\opencv_contrib4.1.0 可以直接下载添加了 .i 文件的压缩包 3. 编译
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.1.0 \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
make -j6
报错信息:
[ 94%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_features2d.cpp.o /home/firefly/opencv_build/opencv_contrib/modules/xfeatures2d/test/test_features2d.cpp:51:10: fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory 51 | #include “features2d/test/test_detectors_regression.impl.hpp” | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.
解决:
sudo cp -r ~/opencv_build/opencv/modules/features2d/ ~/opencv_build/opencv/build/
继续make
make -j6
sudo make install
4. 写入环境变量
sudo gedit ~/.bashrc
添加:
export PKG_CONFIG_PATH=/usr/local/opencv4.1.0/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv4.1.0/lib
source ~/.bashrc
5. 测试
pkg-config --modversion opencv4
$firefly@firefly:~/opencv_build/opencv/samples/cpp/example_cmake$
cmake .
make
./opencv_example
|