centos7安装opencv
时间: 2023-07-12 13:02:42 浏览: 197
下面是在 CentOS 7 系统上安装 OpenCV 的一些步骤:
1. 更新系统软件包:
```
sudo yum update
```
2. 安装必要的软件包:
```
sudo yum install cmake gcc gcc-c++ gtk2-devel pkgconfig python-devel python-numpy python3-devel python3-numpy ffmpeg-devel libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel tbb-devel eigen3-devel
```
3. 下载 OpenCV 源代码:
```
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.1.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.1.zip
unzip opencv.zip
unzip opencv_contrib.zip
```
4. 创建并进入一个 build 目录:
```
mkdir -p ~/opencv_build && cd ~/opencv_build
```
5. 使用 CMake 进行编译:
```
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.5.1/modules \
-D PYTHON_EXECUTABLE=/usr/bin/python3 \
-D BUILD_opencv_python3=yes \
-D BUILD_opencv_python2=no \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_CUDA=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python_bindings_generator=OFF \
-D BUILD_opencv_python_tests=OFF \
../opencv-4.5.1/
```
6. 编译和安装:
```
make -j$(nproc)
sudo make install
```
7. 验证 OpenCV 安装:
```
pkg-config --modversion opencv4
```
如果一切正常,应该会输出 OpenCV 的版本号。
阅读全文