Skip to Content
Learning Robotics using Python - Second Edition
book

Learning Robotics using Python - Second Edition

by Lentin Joseph
June 2018
Beginner to intermediate
280 pages
6h 58m
English
Packt Publishing
Content preview from Learning Robotics using Python - Second Edition

Capturing from the web camera

The following code will capture an image using the webcam with the device name /dev/video0 or /dev/video1.

We need to import the numpy and cv2 modules for capturing an image from a camera:

#!/usr/bin/env python 
import numpy as np 
import cv2

The following function will create a VideoCapture object. The VideoCapture class is used to capture videos from video files or cameras. The initialization argument of the VideoCapture class is the index of a camera or the name of a video file. The device index is just a number that is used to specify the camera. The first camera index is 0, and has the device name /dev/video0-that's why we will put 0 in the following code:

cap = cv2.VideoCapture(0) 

The following section of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Robotics using Python

Learning Robotics using Python

Lentin Joseph
Python Robotics Projects

Python Robotics Projects

Prof. Diwakar Vaish

Publisher Resources

ISBN: 9781788623315Supplemental Content