这里写自定义目录标题
安装opencv3.4.5
在opencv安装前,要先安装一些依赖项目:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install ffmpeg #很重要,读视频,显示视频
1.创建文件夹opencv_cpp
mkdir opencv_cpp
cd opencv_cpp
2.下载opencv
git clone -b 3.4.5 https://gitee.com/mirrors/opencv.git
3.下载opencv_contrib
git clone -b 3.4.5 https://gitee.com/mirrors/opencv_contrib.git
4.boost等文件
将boos文件夹的所有文件放在 opencv_contrib/modules/xfeatures2d/src/ 路径下即可
5.打开~/opencv_cpp/opencv/modules/stitching/下的CMakeLists.txt
对应位置更改:INCLUDE_DIRECTORIES(“~/opencv_cpp/opencv_contrib/modules/xfeatures2d/include”)
ps:视安装的位置而定,可能要明确“~”是什么
可以解决错误:找不到cuda.hpp
fatal error: 'opencv2/xfeatures2d/cuda.hpp' file not found
6.新建文件夹build
make build
cd build
7.build:cmake
计算机没有安装GPU,加参数WITH_CUDA=OFF
cmake -D WITH_CUDA=OFF -D WITH_GTK=ON -D WITH_GTK_2_X=ON -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=Dir1 Dir2
参数CMAKE_INSTALL_PREFIX,视情况而定,可以是root,也可以是用户家目录
Dir1是opencv modules文件夹的位置,如:~/opencv_cpp/opencv_contrib/modules
Dir2是opencv文件夹的位置,如:~/opencv_cpp/opencv
8.make编译
build下:make -j8
9.安装
build下:sudo make install
如果不安装root路径下,也可以不用sudo
10.环境变量
如果是root
sudo vim /etc/ld.so.conf
在文件中加上一行: include /usr/loacal/lib
如果不是root,在系统bash文件中加环境变量,“~”是当前用户家目录
vim ~/.bashrc
export LD_LIBRARY_PATH= ~/lib:$LD_LIBRARY_PATH
source ~/.bashrc