Ububtu22.04安装opencv
时间: 2023-06-14 14:08:09 浏览: 164
ubuntu22.04离线安装gcc g++ make cmake opencv
安装 OpenCV 可以通过以下步骤进行:
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 libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
```
2. 下载 OpenCV 源代码:
```
git clone https://github.com/opencv/opencv.git
```
3. 创建 build 目录并进入:
```
cd opencv
mkdir build
cd build
```
4. 配置 OpenCV:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_CUDA=OFF \
-D WITH_CUDNN=OFF \
-D OPENCV_DNN_CUDA=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \
-D PYTHON_INCLUDE_DIR=/usr/include/python3.8 \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so \
-D BUILD_opencv_python_bindings_generator=ON \
-D BUILD_opencv_python_tests=ON \
-D BUILD_TESTS=ON \
-D WITH_GSTREAMER=ON \
-D WITH_LIBV4L=ON \
-D WITH_TBB=ON \
-D WITH_EIGEN=ON \
-D WITH_OPENEXR=ON \
-D WITH_WEBP=ON \
-D ENABLE_CXX11=ON \
-D CMAKE_INSTALL_PREFIX=/usr/local ..
```
5. 编译并安装 OpenCV:
```
make -j8
sudo make install
sudo ldconfig
```
这些步骤应该可以在 Ubuntu 22.04 上安装 OpenCV。
阅读全文