Install OpenCV from source, with the full set of submodules configured. To build OpenCV from source on a Red Hat system with all submodules configured, follow these steps:

  1. Install the dependencies: first, install the libraries OpenCV needs to build. This usually includes (but is not limited to) 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. On Red Hat, install these with yum:

    yum install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python python-devel python-pip cmake python-devel numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel eigen3-devel gstreamer-plugins-base-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel libv4l-devel -y
  2. Download the OpenCV source: download the OpenCV source from its official GitHub repository, either with git clone or by downloading an archive directly:

    git clone https://github.com/opencv/opencv.git
    git clone https://github.com/opencv/opencv_contrib.git
  3. Create a build directory: create a build directory inside the OpenCV source directory and enter it:

    cd opencv
    mkdir build && cd build
  4. Configure CMake: use CMake to configure the build options, making sure to point at the opencv_contrib module path and enable the modules you need:

    cmake3 -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
  5. Compile OpenCV: compile OpenCV with make. Use the -j option to speed up the build; the number after it should match your processor’s core count:

    make -j$(nproc)
  6. Install OpenCV: once the build finishes, install OpenCV onto the system:

    sudo make install
  7. Set environment variables: to use OpenCV system-wide, you may need to set environment variables such as LD_LIBRARY_PATH so OpenCV’s library files can be found at runtime.

  8. Verify the installation: verify the installation by running a simple OpenCV program, or check it with pkg-config:

    pkg-config --modversion opencv4

Note that these steps may vary depending on your system configuration and OpenCV version. If you run into problems during the build, community tutorials and troubleshooting guides — for example CSDN blog posts — often walk through the detailed steps and common issues along with their fixes. The official OpenCV documentation also has a detailed guide for installing OpenCV on Linux.