内容
1.安装cmake及其依赖环境
2.下载opencv
3.安装
3.1 下载解压:
3.2 进入解压之后的文件夹下新建build文件夹:
3.3 进入build文件夹:
3.4 cmake
3.5 进行编译
3.6 进行安装
4. 配置环境
1.安装cmake及其依赖环境
sudo apt-get install cmake
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
配置完成后,可以在命令行输入
cmake -version
来检测cmake是否安装正确。
2.下载opencv
opencv安装包网址:https://opencv.org/releases/
点击Sources来进行下载
3.安装
3.1 下载解压:
3.2 进入解压之后的文件夹下新建build文件夹:
mkdir build
如下:
3.3 进入build文件夹:
cd build
3.4 cmake
该过程大概需要5分钟左右,根据计算机性能而定
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
3.5 进行编译
sudo make -j16
j 后面所跟数字为编译时所使用的线程数
3.6 进行安装
sudo make install
4. 配置环境
(1)执行
sudo gedit /etc/ld.so.conf
在ld.so.conf中加上 include /usr/local/lib
(2)执行
sudo ldconfig
sudo gedit /etc/bash.bashrc
在 bash.bashrc 最后加上
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
配置完成后将 bash.bashrc 文件source一下,执行
source /etc/bash.bashrc
(3)手动创建opencv.pc
cd /usr/local/lib
sudo mkdir pkgconfig && cd pkgconfig
sudo gedit opencv.pc
在opencv.pc 添加:
prefix=/usr/local
exec_prefix=${prefix}
includedir=/usr/local/include
libdir=/usr/local/lib
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.4.5
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}
保存退出,执行:
pkg-config --modversion opencv
查看 opencv 版本
至此,opencv c++版本配置完成。
文章出处登录后可见!
已经登录?立即刷新