主要是cmake编译选项需要修改
以下两个选项按照自己情况修改
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.2 \
其中/home/lixin/anaconda3/envs/stereo 改成你自己的conda环境
cmake -D CMAKE_BUILD_TYPE=RELEASE \-D CMAKE_INSTALL_PREFIX=/home/lixin/anaconda3/envs/stereo \-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \-D PYTHON_DEFAULT_EXECUTABLE=/home/lixin/anaconda3/envs/stereo/bin/python \-D PYTHON3_EXECUTABLE=/home/lixin/anaconda3/envs/stereo/bin/python \-D PYTHON3_INCLUDE_DIR=/home/lixin/anaconda3/envs/stereo/include/python3.9 \-D PYTHON3_PACKAGES_PATH=/home/lixin/anaconda3/envs/stereo/lib/python3.9/site-packages \-D PYTHON3_LIBRARY=/home/lixin/anaconda3/envs/stereo/lib/libpython3.9.so \-D BUILD_opencv_java=OFF \-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-12.2 \-D WITH_OPENGL=ON \-D WITH_OPENCL=ON \-D WITH_OPENMP=OFF \-D INSTALL_C_EXAMPLES=OFF -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_ARCH_BIN=8.9 -D WITH_CUBLAS=1 -D BUILD_EXAMPLES=ON -D HAVE_opencv_python3=ON -D BUILD_opencv_python2=OFF -D BUILD_TIFF=ON ..
cmake之后看下一下是否都正确
然后正常编译就行