OpenCV Installation
The CV image operator relies on OpenCV. Before using this operator, compile OpenCV first.
- Set up the OpenCV environment.
Install OpenCV dependencies. The Python version must be 3.2 or later.
1yum install -y binutils cmake git pkgconfig gcc gcc-c++ lapack ffmpeg libjpeg-* python3-devel python3-numpy
- Apply the patch for the OpenCV 4.10.0 source code.
- Obtain the OpenCV source package.
https://github.com/opencv/opencv/archive/refs/tags/4.10.0.zip
- Decompress the BoostKit-kp_cv_***.zip package to obtain the kcv.patch and kcv_AIOP.patch files.
- Apply the patch files in the OpenCV source code directory based on the interfaces to be optimized.
1unzip /home/opencv-4.10.0.zip && cd /home/opencv-4.10.0
- kcv.patch is required for optimizing the cvtColor, dilate, GaussianBlur, merge, remap, and resize interfaces.
1git apply /home/kcv.patch
- kcv_AIOP.patch is required for optimizing the convertTo, threshold, warpAffine, contourArea, and countNonZero interfaces.
1git apply /home/kcv_AIOP.patch
- kcv.patch is required for optimizing the cvtColor, dilate, GaussianBlur, merge, remap, and resize interfaces.
- Obtain the OpenCV source package.
- In the opencv directory, run the cmake command to generate a makefile.
1 2 3 4 5 6 7 8 9
mkdir build cmake -S . -B build \ -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D CMAKE_CXX_FLAGS="-O3 -march=armv8-a" \ -D CMAKE_C_FLAGS="-O3 -march=armv8-a" \ -D BUILD_opencv_python3=ON\ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D PYTHON3_EXECUTABLE=$(which python3)
- Compile and install OpenCV.
1 2
cd build make -j && make install
The optimized OpenCV can be properly called.
Troubleshooting
- Problem 1: "Error: invalid shift amount at operand 3 -- 'shll v22.4s,v19.4h,#8'" is displayed after assembly instructions such as shll are executed.

Solution: Install the FFmpeg dependency and libjpeg-related packages.
1yum install ffmpeg libjpeg-*
- Problem 2: Python cannot find cv2 after the import cv2 command is run.
Solution: cv2 is not correctly installed in the site-packages directory of Python. After you specify the Python path in the cmake command and run this command, if the information shown in Figure 1 is displayed, the installation is successful. The information similar to Figure 2 is an example of incorrect installation.
- Problem 3: "typing_stubs_generation.nodes.type_node.TypeResolutionError: Failed to resolve alias 'GProtoArg' exposed as 'GProtoArg'" exposed as "GProtoArg"" is displayed during installation.

Solution: The ADE package cannot be downloaded from GitHub due to network issues.

The ADE package is used for automatic differentiation to enhance OpenCV functions in deep learning and machine learning, especially in scenarios where gradient calculation is required. This problem does not affect the use of KPCV.
- Problem 4: The DNN module displays the message "[modules/dnn/CMakeFiles/opencv_dnn.dir/build.make: 2530: lib/libopencv_dnn.so.4.10.0] Error 1."

Solution: KPCV does not involve the DNN module. Add the compilation option -DBUILD_opencv_dnn=OFF during compilation to mask the DNN module.

