未分类

Ubuntu 安装OpenCV

Ubuntu 18安装opencv

运行下面的命令在Ubuntu
sudo apt install python3-opencv
查看版本

python3 -c "import cv2; print(cv2.__version__)"
3.2.0

从源码安装任意版本的opencv

安装依赖:

sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev

下载源码

mkdir ~/opencv_build && cd ~/opencv_build

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
  1. 在opencv 和 opencv_contrib 目录下运行git checkout <opencv-version>
    用cmake进行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 OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON ..
  1. make -j8
  2. sudo make install
  3. 检查OpenCV 版本
pkg-config --modversion opencv4
python3 -c "import cv2; print(cv2.__version__)"

发表评论

您的电子邮箱地址不会被公开。