opencv4.2安装(linux)
1. 下载代码
mkdir /tmp/opencv cd /tmp/opencv curl -Lo opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip unzip -q opencv.zip curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip unzip -q opencv_contrib.zip
如果网络不好下载一直要断开请用git单个文件下载
mkdir opencv-4.2.0 cd opencv-4.2.0 git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git
切换到指定标签
cd opencv git checkout -b 4.2.0 4.2.0 cd ../opencv_contrib git checkout -b 4.2.0 4.2.0
2. 依赖库安装
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 yum -y install pkgconfig cmake curl git gtk2-devel libpng-devel libjpeg-devel libtiff-devel tbb tbb-devel libdc1394-devel unzip
3. 用cmake编译安装
cd /tmp/opencv/opencv-4.2.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv/opencv_contrib-4.2.0/modules -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_opencv_java=NO -D BUILD_opencv_python=NO -D BUILD_opencv_python2=NO -D BUILD_opencv_python3=NO -D WITH_JASPER=OFF -DOPENCV_GENERATE_PKGCONFIG=ON .. make -j 1 make preinstall
也可以直接用下面命令, 不用太多参数
使用此行 cmake -D WITH_IPP=OFF -D WITH_TBB=ON -D WITH_EIGEN=ON ..(正确)
-D WITH_IPP=OFF 的意思是不再下载了
不用这行cmake -D WITH_TBB=ON -D WITH_EIGEN=ON .. (错误, 还是要重下ipp)
安装
make -j8 make install
4.动态库配置
/bin/bash -c 'echo "/usr/local/lib64" > /etc/ld.so.conf.d/opencv.conf' ldconfig
5.测试