Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 703
Shobhit Srivastava Avatar asked Jan 27 '19 15:01

Shobhit Srivastava


People also ask

Can we open Webcam in Colab?

Webcam In Google Colab Accessing your webcam within a Google Colab notebook is not as straightforward as you may think. When you use a Google Colab Runtime you are connecting to a cloud VM hosted by Google. In order to utilize your local machine's webcam within the VM we can utilize JavaScript code.

Can I use GUI in Google Colab?

Visual Python is a GUI-based Python code generator for Google Colab as an extension. Visual Python is an open source project started for students who struggle with coding during Python classes for data science.

Can I use cv2 in Google Colab?

In colab and jupyter notebook we cannot use cv. imshow() or cv2.


2 Answers

  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

like image 50
Vighnesh Bhat Chanila Avatar answered Sep 19 '22 12:09

Vighnesh Bhat Chanila


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

like image 45
Bob Smith Avatar answered Sep 21 '22 12:09

Bob Smith