Skip to Content
Python: Real World Machine Learning
book

Python: Real World Machine Learning

by Prateek Joshi, John Hearty, Bastiaan Sjardin, Luca Massaron, Alberto Boschetti
November 2016
Beginner to intermediate
941 pages
21h 55m
English
Packt Publishing
Content preview from Python: Real World Machine Learning

Capturing and processing video from a webcam

We will use a webcam in this chapter to capture video data. Let's see how to capture the video from the webcam using OpenCV-Python.

How to do it…

  1. Create a new Python file, and import the following packages:
    import cv2
  2. OpenCV provides a video capture object that we can use to capture images from the webcam. The 0 input argument specifies the ID of the webcam. If you connect a USB camera, then it will have a different ID:
    # Initialize video capture object
    cap = cv2.VideoCapture(0)
  3. Define the scaling factor for the frames captured using the webcam:
    # Define the image size scaling factor
    scaling_factor = 0.5
  4. Start an infinite loop and keep capturing frames until you press the Esc key. Read the frame from the webcam: ...
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

Interpretable Machine Learning with Python

Interpretable Machine Learning with Python

Serg Masís
Large Scale Machine Learning with Python

Large Scale Machine Learning with Python

Luca Massaron, Alberto Boschetti, Bastiaan Sjardin

Publisher Resources

ISBN: 9781787123212Supplemental ContentPurchase Link