ubuntu Opencv4及扩展模块编译安装过程
以下两个文件是1223从github下载的,网络好的可从github下载
opencv4下载
opencv_contrib-4.x下载
由于国内网络限制,还需要下载所需额外文件
包括了
ippicv__lnx_intel64_general_0723.tgz
face_landmark_model.dat
boostdesc_bgm.i系列
vgg_generated_48.i系列
1.将解压后boostdesc_bgm.i,vgg_generated_48.i等opencv4文件夹中的文件拷贝到opencv_contrib-4.x/modules/xfeatures2d/src目录中
2.将ippicv__lnx_intel64_general_0723.tgz 和face_landmark_model.dat 放到某个目录/xxx/download/中;打开opencv-4.x/3rdparty/ippicv/ippicv.cmake,修改/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/
为file:///xxx/download/
;打开opencv_contrib-4.x/modules/face/CMakeLists.txt,修改/opencv/opencv_3rdparty/${__commit_hash}/
为file:///xxx/download/
3.安装依赖
sudo apt-get updatesudo apt-get upgradesudo apt-get install build-essentialsudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-devsudo 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-devsudo apt-get install libxvidcore-dev libx264-dev sudo apt-get install libatlas-base-dev gfortran sudo apt-get install ffmpeg
可能出现libjasper-dev无法安装的问题,
如下操作解决:
sudo add-apt-repository "deb /ubuntu xenial-security main"sudo apt updatesudo apt install libjasper1 libjasper-dev
4.安装cmake-gui
sudo apt-get install cmake-gui
有需要省级cmake的可以升个级(升级最好不要卸载,直接覆盖升级) 链接
5.配置cmake-gui
在opencv-4.x中新建build文件夹
配置好文件夹路径
这里没有编译wechat_qrcode模块(需要下载额外文件),取消了这个的勾选
配置扩展模块路径
配置好后点击 Configure
6.转到build文件夹内,
cd opencv-4.x/buildsudo make -j8sudo make install
默认安装到了/usr/local,可在cmake-gui中更改
7.配置 添加环境变量
sudo gedit /etc/ld.so.conf.d/opencv.conf
添加如下内容,并保存:/usr/local/lib
配置库sudo ldconfig
sudo gedit /etc/bash.bashrc
在末尾添加如下内容
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
再更新一下
source bash.bashrc
8.创建opencv4.pc
sudo gedit /usr/local/lib/pkgconfig/opencv4.pc
添加如下内容
# Package Information for pkg-configprefix=/usr/localexec_prefix=${prefix}libdir=${exec_prefix}/libincludedir_old=${prefix}/include/opencv4/opencvincludedir_new=${prefix}/include/opencv4Name: OpenCVDescription: Open Source Computer Vision LibraryVersion: 4.2.0Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -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_video -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_coreLibs.private: -ldl -lm -lpthread -lrtCflags: -I${includedir_old} -I${includedir_new}
pkg测试
pkg-config --modversion opencv4pkg-config --cflags --libs opencv4
参考链接:
/weixin_41053564/article/details/81254410
/weixin_40854506/article/details/115289098
/zzyczzyc/article/details/87954858
/lwqldsyzx/article/details/105722488
/weixin_49353816/article/details/113785090
/wangxubo1988/article/details/114300683