opencv install

安装 opencv 版本为 4.2

一、前置条件

1. gcc安装
yum install gcc
2. 安装cmake

注意安装 opencv-4.2 版本,需要 cmake-3.5.1 及其以上,安装脚本如下:

#!/bin/bash

# 设置下载和安装目录
DOWNLOAD_DIR="/tmp/cmake_download"
INSTALL_DIR="/opt/cmake"

# 创建目录
mkdir -p $DOWNLOAD_DIR
mkdir -p $INSTALL_DIR

yum install -y gcc-c++ wget
# 下载 CMake 3.5.1 源码
cd $DOWNLOAD_DIR

wget http://www.cmake.org/files/v3.5/cmake-3.5.1.tar.gz
tar -zxvf cmake-3.5.1.tar.gz
cd cmake-3.5.1

# 编译和安装 CMake
./configure --prefix=$INSTALL_DIR
make
make install

# 设置环境变量
echo "export PATH=$INSTALL_DIR/bin:\$PATH" >> /etc/profile
echo "export MANPATH=$INSTALL_DIR/share/man:\$MANPATH" >> /etc/profile
source /etc/profile

# 清理临时文件
rm -rf $DOWNLOAD_DIR

二、安装opencv

1. 安装依赖
sudo yum install -y epel-release
sudo yum install -y gtk2-devel
sudo yum install -y libpng-devel
sudo yum install -y jasper-devel
sudo yum install -y openexr-devel
sudo yum install -y libwebp-devel
sudo yum install -y libjpeg-turbo-devel 
sudo yum install -y libtiff-devel 
sudo yum install -y tbb-devel eigen3-devel
sudo yum install -y boost boost-thread boost-devel
sudo yum install -y libv4l-devel
2. 下载 opencv

官网下载即可:https://opencv.org/

3. 编译opencv
cd opencv/
mkdir build && cd build

# 编译 opencv
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=/usr/local .. 

make

make -j 8
sudo make install
4. 环境变量配置

打开文件 /etc/ld.so.conf,在最后一行加上 include /usr/local/lib64

运行ldconfig,使添加的库路径生效

sudo ldconfig

编辑 /etc/profile,在文件末尾添加
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig

生效环境变量

source /etc/profile

在命令行中输入如下命令,检测opencv是否安装成功

pkg-config opencv4 --modversion

参考文件:
https://blog.csdn.net/qq_43571475/article/details/136329239
https://blog.csdn.net/weixin_44698673/article/details/127082446?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171030914316800188540039%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=171030914316800188540039&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-127082446-null-null.142v99pc_search_result_base8&utm_term=ubuntu%20%E5%AE%89%E8%A3%85opencv&spm=1018.2226.3001.4187

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值