the default, binary python cv2 install (e.g. from pypi) does not have any CUDA support.
however, most opencv functions are opencl optimized, and you can access them using cv2.UMat
out of the box.
if you do need CUDA, you will have to build your cv2 from src
(this will ofc need nvidia hw and a CUDA sdk installed)
i’ve done this on colab
(low hanging fruit, everything you need is already there)
and it was as easy as:
!git clone https://github.com/opencv/opencv
!git clone https://github.com/opencv/opencv_contrib
!mkdir /content/build
%cd /content/build
!cmake -DOPENCV_EXTRA_MODULES_PATH=/content/opencv_contrib/modules \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_CUDA=ON \
-DWITH_CUBLAS=ON \
-DWITH_CUDNN=ON \
-DOPENCV_DNN_CUDA=ON \
/content/opencv
!make -j8 install