ubuntu配置多个版本的opencv
解压压缩包后,进入对应文件夹
mkdir build
cd build
执行:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=~/opencv-4.4.0 ..
make
sudo make install
cd ~/
sudo chmod 777 opencv-4.4.0 -R
然后配置 opencv 变量,编辑文件 /etc/ld.so.conf.d/opencv.conf(如果没有就会自动创建):
sudo gedit /etc/ld.so.conf.d/opencv.conf
然后添加 opencv4.4.0 的 lib 路径:
~/opencv-4.4.0/lib
保存退出,执行:
sudo ldconfig
进入~/opencv-4.4.0/lib:
sudo mkdir pkgconfig && cd pkgconfig
sudo gedit opencv.pc
# 在 opencv.pc 文件里添加如下内容
prefix=~/opencv-4.4.0
exec_prefix=${prefix}
includedir=~/opencv-4.4.0/include
libdir=~/opencv-4.4.0/lib
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.4.0 Libs: -L${exec_prefix}/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir}
编辑 sudo gedit ~/.bashrc ,最后添加:
#opencv-4.4.0
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:~/opencv-4.4.0/lib/pkgconfig
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:~/opencv-4.4.0/lib
保存退出,执行:
source ~/.bashrc
如果是使用python,要安装对应的插件:pip install python-opencv ==4.4.0