How to do it...

  1. Import the necessary packages:
import cv2 
import numpy as np 
  1. Load the face cascade file:
frontalface_cascade= cv2.CascadeClassifier('haarcascade_frontalface_alt.xml') 
  1. Check whether the face cascade file has been loaded:
if frontalface_cascade.empty(): 
  raiseIOError('Unable to load the face cascade classifier xml file') 
  1. Initialize the video capture object:
capture = cv2.VideoCapture(0) 
  1. Define the scaling factor:
scale_factor = 0.5 
  1. Perform the operation until the Esc key is pressed:
# Loop until you hit the Esc key 
while True: 
  1. Capture the current frame and resize it:
  ret, frame = capture.read() 
  frame = cv2.resize(frame, None, fx=scale_factor, fy=scale_factor,  
            interpolation=cv2.INTER_AREA) 
  1. Convert the image ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.