I think I’m almost there. I finally backed up my CMakeVars.txt too. I’m using Python 3.10 via Conda, and I disabled a bunch of flags for stuff I didn’t need. That all led to a successful build, but with no Python package. After more help from ChatGPT, I went into Visual Studio 2022, searched for ‘python’ in the Solution Explorer, right clicked opencv_python3, and hit build. Hopefully this works. At least this way I have a progress indicator. For reference, here’s my ChatGPT convo.

Also, for reference, more CMake config stuff from this reddit post:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_TBB=ON \
-D ENABLE_FAST_MATH=1 \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_CUDA=ON \
-D BUILD_opencv_cudacodec=OFF \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D CUDA_ARCH_BIN=8.9 \
-D CMAKE_C_COMPILER=gcc-11 \
-D CMAKE_CXX_COMPILER=g++-11 \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_GSTREAMER=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_FORCE_PYTHON_LIBS=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=~/virtualenvs/cv_opencv_cuda/lib/python3.10/site-packages \
-D PYTHON_EXECUTABLE=../../../virtualenvs/cv_opencv_cuda/bin/python \
-D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.9.0/modules \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..

This is mostly everything, but in my case I turned GStreamer off, didn’t change the PC file name, and linked CUDA Toolkit 12.8, cuDNN 8.9, NVIDIA Video Codec SDK 12.2, OpenBlas 0.3.29, and probably some other stuff (who cares, I finally backed up my CMakeVars!).


Tags: python cuda opencv cmake build programming debugging