step1:
bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
bash
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libcanberra-gtk-module
sudo apt-get install pkg-config
3.下载opencv源码:
bash
https://opencv.org/releases/
4.解压后创建新的文件夹build,然后进入build
bash
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j8
sudo make install
bash
/usr/local 可以替换为自己的路径
step2:进行文件配置
- 打开ld.so.conf文件(文件可能为空白,不用管他),并在文件末尾加上一行内容【/usr/local/lib】
bash
sudo gedit /etc/ld.so.conf
- 加载配置,使刚才添加的内容生效。
bash
sudo ldconfig
- 打开bash.bashrc文件,在文件末尾添加以下两行内容:
bash
sudo gedit /etc/bash.bashrc
添加的内容:
bash
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
- 运行bash.bashrc:
source /etc/bash.bashrc
- 更新系统的配置环境
sudo updatedb
- 创建并配置opencv.pc文件
执行以下命令创建并打开opencv.pc文件:
cd /usr/local/lib/pkgconfig
touch opencv.pc
sudo gedit opencv.pc
打开文件后,添加以下内容并保存关闭文件:
bash
prefix=/usr/local
exec_prefix=${prefix}
includedir=/usr/local/include
libdir=/usr/local/lib
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.7.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}
版本号4.7.0可以改为对应的别的版本号
- 检查opencv安装情况:
bash
pkg-config opencv --modversion
或者
bash
pkg-config opencv4 --modversion
如果安装成功,会有返回版本号:
参考链接:https://blog.csdn.net/wxyczhyza/article/details/128968849