ubuntu18.04 安装opencv
时间: 2023-05-25 09:03:45 浏览: 150
1. 更新软件包
sudo apt update && sudo apt upgrade
2. 安装依赖项
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
3. 安装图像和视频 I/O 库
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libtbb-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils
4. 下载并安装 OpenCV:
4.1 前往OpenCV的官网:https://opencv.org/releases/
4.2 选择需要安装的版本,如4.4.0
4.3 下载源码至本地
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.4.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.4.0.zip
4.4 解压文件
unzip opencv.zip
unzip opencv_contrib.zip
4.5 将解压后的文件夹移动至 /usr/local/src 下
sudo mv opencv-4.4.0 /usr/local/src/opencv
sudo mv opencv_contrib-4.4.0 /usr/local/src/opencv_contrib
4.6 修改opencv的cmake文件
mkdir /usr/local/src/opencv/release
cd /usr/local/src/opencv/release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_EXTRA_MODULES_PATH=/usr/local/src/opencv_contrib/modules -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D ENABLE_NEON=ON -D WITH_OPENGL=ON -D WITH_V4L=ON -D WITH_TBB=ON -D WITH_FFMPEG=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..
4.7 编译安装
make -j8
sudo make install
5. 验证安装结果
5.1 在终端输入 python3
5.2 输入 import cv2
5.3 没有报错即安装成功。
阅读全文