ubuntu 20.04 安装opencv4.7.0
时间: 2023-05-31 09:03:18 浏览: 411
以下是在Ubuntu 20.04上安装OpenCV 4.7.0的步骤:
1. 安装必要的依赖项:
```
sudo apt-get update
sudo apt-get upgrade
sudo apt-get 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 libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
```
2. 下载OpenCV 4.7.0源代码:
```
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.7.0
```
3. 创建并进入一个构建目录:
```
mkdir build
cd build
```
4. 使用CMake配置编译选项:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D WITH_TBB=ON \
-D WITH_CUDA=OFF \
-D BUILD_opencv_python3=TRUE \
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3) \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
```
5. 编译并安装OpenCV:
```
make -j$(nproc)
sudo make install
sudo ldconfig
```
6. 验证安装是否成功:
```
python3 -c "import cv2; print(cv2.__version__)"
```
这应该输出OpenCV版本号4.7.0。
阅读全文