Opening web camera in Google Colab

I am trying to open a web camera in Google Colab. I've executed the following command:

cap = cv2.VideoCapture(0)

but this is not working: the web camera is not opening.

Is it possible to open a connection to my web camera on Google Colab?


  1. Go to Google Colaboratory

  2. Create a new notebook

  3. Click snippet panel

  4. Click Camera Capture. Click insert

  5. Run script: Shift + Enter

enter image description here


Since Colab is running in your browser, you'll want to use web APIs to access local hardware like a camera.

Here's an example showing how to capture an image from your local webcam in Colab: https://colab.research.google.com/notebooks/snippets/advanced_outputs.ipynb#scrollTo=2viqYx97hPMi