June 2018
Beginner to intermediate
280 pages
6h 58m
English
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 ...