欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CentOS7.8 安装 OpenCV

程序员文章站 2022-03-11 22:51:43
...

一、安装依赖

系统依赖:

sudo yum -y install epel-release
sudo yum -y install gcc gcc-c++
sudo yum -y install cmake cmake3
sudo yum -y install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
sudo yum -y install python-devel numpy gtk2-devel libdc1394-devel libv4l-devel gstreamer-plugins-base-devel

安装:FFmpeg(在线安装):

sudo su          # 使用超级权限
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum -y install ffmpeg ffmpeg-devel
ffmpeg           # 查看安装情况

安装参考:https://linoxide.com/linux-how-to/install-ffmpeg-centos-7/
或者参考:https://commandnotfound.cn/linux/1/171/ffmpeg-%E5%91%BD%E4%BB%A4

安装:FFmpeg(离线安装):https://www.cnblogs.com/blackhumour2018/p/9431393.html

二、安装OpenCV

2.1 下载安装

OpenCV官网下载:https://opencv.org/releases.html
或者命令下载:wget https://github.com/opencv/opencv/archive/3.4.4.zip
安装位置:path/to /install,根据自己路径设置。不指定时,默认安装路径在 /usr/local/

unzip opencv-3.4.12.zip
cd opencv-3.4.12
mkdir build && cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D BUILD_EXAMPLES=ON ..
'''
-- Configuring done
-- Generating done
-- Build files have been written to: /home/`username`/opencv-3.4.12/build
 
'''

make -j$(nproc)			#有几个CPU就用几个CPU
sudo make install

2.2 配置OpenCV

  1. 添加库路径–执行:
    sudo ln -s /usr/local/lib64/pkgconfig/opencv.pc /usr/share/pkgconfig/
    sudo ldconfig

  2. 添加环境变量:
    sudo vi /etc/profile     打开此文件,在文件末尾另起行加入如下两行:(保存,退出)
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
    source /etc/profile     立即生效

  3. pkg-config配置
    默认的pkg搜索链接路径/usr/lib/pkgconfig,需要将opencv.pc拷贝到pkg的默认路径下
    cp /usr/local/lib64/pkgconfig/opencv.pc /usr/lib/pkgconfig

  4. 测试

    cd samples/cpp/example_cmake/
    make
    
    '''
    g++ example.cpp -o example.o -c -Wall -I/usr/local/include/opencv -I/usr/local/include
    g++ example.o -o opencv_example -L/usr/local/lib64 -lopencv_dnn -lopencv_highgui -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core -ldl -lm -lpthread -lrt
    
    '''
    ./opencv_example         # 执行生成的程序
    Built with OpenCV 3.4.1   # 在这里会卡一阵
    

参考:
https://lvjianzhao.gitee.io/lvjianzhao/2020/07/03/Centos%207.6%E5%AE%89%E8%A3%85opencv/
https://linuxize.com/post/how-to-install-opencv-on-centos-8/

https://blog.csdn.net/whudee/article/details/93379780
https://blog.csdn.net/weixin_43470000/article/details/84962432

相关标签: linux opencv