ubuntu安装opencv4.5.2
时间: 2023-10-09 10:11:02 浏览: 121
以下是在Ubuntu上安装OpenCV 4.5.2的步骤:
1. 更新软件包列表:
```
sudo apt update
```
2. 安装必要的依赖项:
```
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 libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
```
3. 下载OpenCV 4.5.2源代码:
```
cd ~
mkdir opencv_build && cd opencv_build
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.5.2
```
4. 创建一个目录来构建OpenCV:
```
cd ~/opencv_build
mkdir build && cd build
```
5. 配置CMake:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_CUDA=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=/usr/local/lib/python3.8/dist-packages \
-D BUILD_EXAMPLES=ON ..
```
这里需要注意的是,如果你使用的是Python 3.8,那么需要将上面的`OPENCV_PYTHON3_INSTALL_PATH`设置为`/usr/local/lib/python3.8/dist-packages`,如果你使用的是其他版本的Python,请相应地进行更改。
6. 编译OpenCV:
```
make -j$(nproc)
```
7. 安装OpenCV:
```
sudo make install
```
8. 配置动态链接库:
```
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
```
至此,你已经成功地在Ubuntu上安装了OpenCV 4.5.2。
阅读全文