ubuntu下安装opencv4.6.0,安装后测试opencv
时间: 2023-11-08 15:55:08 浏览: 109
好的,下面是在Ubuntu下安装OpenCV 4.6.0的步骤:
1. 更新系统
在终端中输入以下命令,更新系统并安装必要的软件包:
```
sudo apt update
sudo apt upgrade
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
```
2. 下载OpenCV源码
在终端中输入以下命令,从OpenCV官网下载OpenCV 4.6.0源码:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.6.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.6.0.zip
```
3. 解压源码
在终端中输入以下命令,解压OpenCV源码:
```
unzip opencv.zip
unzip opencv_contrib.zip
```
4. 编译并安装OpenCV
在终端中输入以下命令,编译并安装OpenCV:
```
cd opencv-4.6.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.6.0/modules \
-D ENABLE_NEON=ON \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D WITH_QT=OFF \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D WITH_VTK=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_opencv_python3=TRUE \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..
make -j4
sudo make install
sudo ldconfig
```
5. 测试OpenCV
在终端中输入以下命令,测试OpenCV是否安装成功:
```
pkg-config --modversion opencv4
```
如果成功安装,终端输出的版本号应该为4.6.0。
现在,您可以在您的C++程序中使用OpenCV库了。祝您好运!
阅读全文