Skip to content

Instantly share code, notes, and snippets.

@berak
Last active July 20, 2021 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berak/c920052a80a51d8513affe325e8909d1 to your computer and use it in GitHub Desktop.
Save berak/c920052a80a51d8513affe325e8909d1 to your computer and use it in GitHub Desktop.
cv2 cuda colab
!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
## the new cv2.so is now in /content/build/lib/python3/
## you are not allowed a normal install on colab, (not root)
## but you can copy it into your work folder and restart the runtime, so it forgets about the old version !
import cv2
cv2.__version__
!ls -l
## save for later use:
!cp /content/build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so "/content/drive/My Drive/cv2_cuda"
## next time, load it into your work folder:
## dont forget to restart the runtime, so it forgets about the old version !
!cp "/content/drive/My Drive/cv2_cuda/cv2.cpython-37m-x86_64-linux-gnu.so" .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment