1. 安装cmake
sudo apt install cmake
2. 安装依赖环境
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
3.下载opencv
- 下载链接 https://opencv.org/releases/
下载 source 类型的版本
推荐下载 opencv-4.5.2.zip 验证成功安装
4.解压opencv 压缩包
unzip opencv-4.5.2.zip
5. 进入解压后的文件夹中
1. 创建build文件夹
mkdir build
2. cmake 编译
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
3. make
sudo make -j8
4. 进行安装
sudo make install
6. 配置环境
打开 /etc/ld.so.conf 在文件中加上 /usr/local/lib
sudo vim /etc/ld.so.conf
追加一行 /usr/local/lib or include /usr/local/lib
sudo ldconfig 使修改生效。
7.修改bash.bashrc 文件
1. sudo vim /etc/bash.bashrc 在文件尾部追加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
2. source /etc/bash.bashrc 使修改生效。
8.检验
pkg-config opencv --modversion
输出相应的 版本及成功 不输出的话问题也不大 解决此问题查看步骤九。
9. 添加 opencv.pc 文件
cd /usr/local/lib
sudo mkdir pkgconfig
cd pkgconfig
sudo touch opencv.pc
-
•
将下发内容添加到文件。
prefix=/usr/local exec_prefix={prefix}/include libdir=${exec_prefix}/lib
Name: opencv Description: The opencv library Version:4.5.2 Cflags: -I{libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
-
•
文件导入到环境变量 export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
标签:lopencv,编译,--,sudo,opencv,ubuntu,go,bash From: https://www.cnblogs.com/ryzemagic/p/16930615.html