ubuntu 18.04 安装opencv4.6
时间: 2023-11-10 07:47:57 浏览: 193
opencv2.4.6
您可以按照以下步骤在Ubuntu 18.04上安装OpenCV 4.6:
1. 更新系统软件包:
```shell
sudo apt update
sudo apt upgrade
```
2. 安装依赖库:
```shell
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
```
3. 下载OpenCV源代码:
```shell
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.6.0.zip
unzip opencv.zip
```
4. 下载OpenCV贡献模块:
```shell
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.6.0.zip
unzip opencv_contrib.zip
```
5. 创建构建目录并进入:
```shell
mkdir -p ~/opencv_build && cd ~/opencv_build
```
6. 使用CMake进行配置:
```shell
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.6.0/modules \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_java=OFF \
-D WITH_CUDA=OFF \
../opencv-4.6.0
```
7. 编译和安装:
```shell
make -j$(nproc)
sudo make install
```
8. 配置动态链接库:
```shell
sudo /bin/bash -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
```
至此,您已成功安装OpenCV 4.6在Ubuntu 18.04上。您可以通过编写代码测试安装是否正常。
阅读全文