opencv安装

1.1 安装依赖

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

1.2 下载并解压opencv及对应版本opencv_contrib源码包,以opencv4.5.2为例

wget https://github.com/opencv/opencv/archive/4.5.2.zip -O opencv-4.5.2.zip
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.zip -O opencv_contrib-4.5.2.zip
unzip opencv-4.5.2.zip
unzip opencv_contrib-4.5.2.zip

1.3 编译安装

mkdir opencv-4.5.2/build && cd opencv-4.5.2/build

cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_opencv_world=ON -D OPENCV_DOWNLOAD_MIRROR_ID=gitcode \
          -D OPENCV_ENABLE_NONFREE=ON -D BUILD_TIFF=ON -D OPENCV_GENERATE_PKGCONFIG=ON \
          -D CMAKE_INSTALL_PREFIX=~/opencv_200dk/opencv_install \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.2/modules ..

make -j8

make install

关键编译选项:

  • BUILD_opencv_world # 如果为ON,编译只会生成一个整体的链接库,如果为OFF会生成各个模块的链接库
  • CMAKE_INSTALL_PREFIX # 编译安装的路径,执行make install后opencv会被安装到CMAKE_INSTALL_PREFIX路径下
  • OPENCV_ENABLE_NONFREE # 如需编译xfeatures2d等不受专利保护的算法,需要将其置为ON
  • OPENCV_EXTRA_MODULES_PATH # 扩展算法包模块的路径,需指定为解压后opencv_contrib包的modules目录
    在编译目录下执行cmake -LH可查看所有编译选项说明和其默认设置
 posted on 2023-02-23 10:38  快乐的大李  阅读(228)  评论(0编辑  收藏  举报