centos7.9安装opencv4.6.0
时间: 2023-09-02 17:07:49 浏览: 163
安装OpenCV 4.6.0的步骤如下:
1. 安装依赖包
```
sudo yum install epel-release
sudo yum install cmake gcc gcc-c++ kernel-devel kernel-headers python3 python3-devel python3-pip \
gtk2-devel libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel \
tbb-devel eigen3-devel gstreamer-plugins-base-devel ffmpeg-devel freeglut-devel mesa-libGL mesa-libGL-devel \
mesa-libGLU mesa-libGLU-devel libv4l-devel dc1394-devel libdc1394-devel libv4l2-devel libdc1394-22-devel
```
2. 下载OpenCV
```
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
unzip opencv.zip
unzip opencv_contrib.zip
mv opencv-4.6.0 opencv
mv opencv_contrib-4.6.0 opencv_contrib
```
3. 编译安装OpenCV
```
cd opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D BUILD_opencv_python3=yes \
-D BUILD_opencv_python_bindings_generator=no \
-D WITH_CUDA=OFF \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
../
make -j4
sudo make install
sudo ldconfig
```
安装完成后,您可以通过以下命令检查OpenCV是否正常安装:
```
pkg-config --modversion opencv4
```
注:以上命令适用于CentOS 7.9系统。
阅读全文