manjaro linux源码安装opencv4.5
一、安装部分
1、由于学习需要,需要安装opencv4.5,只能源码安装,环境为manjaro linux, 2020年11月2日最新升级到testing版本
sudo pacman -S cmake sudo pacman -S git sudo pacman -S base-devel sudo pacman -S gtk2 sudo pacman -S pkg-config sudo pacman -S python sudo pacman -S ffmpeg sudo pacman -S intel-tbb (intel 高性能抽象线程库) sudo pacman -S libdc1394 (以控制基于ieee1394的摄像机的高级编程接口) sudo pacman -S jasper (在新兴的JPEG-2000 Part-1标准中指定的编解码器的基于软件的实现) sudo pacman -S libjpeg-turbo libjpeg6-turbo (带有加速基线压缩和解压缩的JPEG图像编解码器) sudo pacman -S libtiff
2、下载文件:git clone https://github.com/opencv/opencv.git或者https://github.com/opencv/opencv/archive/4.5.0.zip压缩包都可以,如果时zip文件,记得先解压
可能要安装依赖:
FFmpeg-4.3.1, gst-plugins-base-1.18.1, GTK+-3.24.23, JasPer-2.0.14, libjpeg-turbo-2.0.5, libpng-1.6.37, LibTIFF-4.1.0, libwebp-1.1.0, v4l-utils-1.20.0, and xine-lib-1.2.10 apache-ant-1.10.9, Doxygen-1.8.20, Java-14.0.1, Python-2.7.18, Cuda, Eigen, OpenEXR, GCD, GDAL, GigEVisionSDK, JACK, libdc1394, libgphoto2, NumPy, OpenNI, PlanetUML, PvAPI, Threading Building Blocks (TBB), UniCap, VTK - The Visualization Toolkit, and XIMEA
3、进入下载或解压后的目录,例如:cd ~/opencv4.5, 新建目录build编译目录,进入编译目录:cd build
4、cmake -DCMAKE_EXE_LINKER_FLAGS=-lcblas -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local OPENCV_EXTRA_MODULES_PATH .. 很快就会生成cmake文件
5、编译安装:
make -j8
sudo make install
二、配置部分:
1、创建一个内容为/usr/local/lib 的文件,文件名为:opencv4.conf,放置路径为:/etc/ld.so.conf.d/
1 touch opencv4.conf 2 sh -c 'echo "/usr/local/lib" > opencv4.conf' 3 sudo opencv4.conf /etc/ld.so.conf.d/
2、更新包信息:
sudo ldconfig
3、复制pc文件到对应目录:
sudo cp -f /usr/local/lib/pkgconfig/opencv4.pc /usr/lib/pkgconfig/ 我这里无需复制
4、添加环境变量:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
export PKG_CONFIG_PATH
5、测试
pkg-config --libs opencv4
结果:
1 -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_viz -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
pkg-config --cflags opencv4 结果:
1 -I/usr/include/opencv4
pkg-config --modversion opencv4
查看版本号,结果:
1 4.5.0
三、不想要,可以卸载,命令为:
1、删掉opencv4.conf文件,
2、在编译的文件夹(我的是~/opencv4.5)下运行命令sudo make uninstall
3、删除build文件夹:cd .. && rm -rf build
4、删除源码目录:cd .. && rm -rf opencv4.5
5、删除系统安装的文件:
sudo rm -r /usr/local/include/opencv2
/usr/local/include/opencv
/usr/include/opencv
/usr/include/opencv2
/usr/local/share/opencv
/usr/local/share/OpenCV
/usr/share/opencv
/usr/share/OpenCV
/usr/local/bin/opencv*
/usr/local/lib/libopencv
也可以参考:
http://www.linuxfromscratch.org/blfs/view/svn/general/opencv.html
https://docs.opencv.org/4.5.0/
https://opencv.org/releases/
https://www.cnblogs.com/geoffreyone/p/10819397.html
https://github.com/opencv/opencv/issues/14323
https://blog.csdn.net/weixin_30627381/article/details/99882185
https://www.cnblogs.com/zbqhc/p/11550307.html