fedora 编译安装opencv 4.5.2 —— 筑梦之路

#安装依赖包

dnf install cmake gcc libpng-devel gtk2-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel tbb-devel eigen3-devel boost boost-thread boost-devel libv4l-devel


#拉取代码

#https://github.com/opencv/opencv.git

git clone https://gitee.com/binghai228/opencv.git

cd opencv && git checkout 4.5.2

#https://github.com/opencv/opencv_contrib.git

git clone https://gitee.com/binghai228/opencv_contrib

cd opencv_contrib && git checkout 4.5.2

cd ..

#整合目录

mv opencv_contrib opencv/

cd opencv && mkdir build && cd build

---
[可选]
cd opencv/3rdparty/ippicv/ippicv.cmake

找到"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
修改为下载的文件路径ippicv_2020_lnx_intel64_20191018_general.tgz
---

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local  -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ -D WITH_TBB=OFF  -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D OPENCV_GENERATE_PKGCONFIG=ON .. 

#编译
make 

#安装
make install

#我这里直接安装后就可以使用了,如果出现问题可以参考下面的步骤进行配置

#配置环境变量

vim /etc/profile

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64

#让环境变量生效
source /etc/profile

#拷贝
cp /usr/local/lib64/pkgconfig/opencv4.pc /usr/lib/pkgconfig

#配置
ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/

ldconfig

#验证版本
pkg-config --modversion opencv4

#在python中验证(两种方式)

##交互式
python

import cv2
print(cv2.__version__)

##一条命令
python -c "import cv2; print(cv2.__version__)"
#编译安装4.5.5,不包括contrib库

git checkout 4.5.5

mkdir build

cd build

cmake ..

make

make install

你可能感兴趣的:(linux系统运维,opencv,图像处理)