O'Reilly logo

Smart Internet of Things Projects by Agus Kurniawan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a tracking vision system for moving objects

In this section, we build a simple tacking vision system. We already learned how to detect a face in an image. Now we try to detect faces on video.

The idea is simple. We change a still image as source to a frame image from a camera. After calling read() from the VideoCapture object, we pass the frame image into face_cascade.detectMultiScale(). Then, we show it a picture dialog. That's it.

For implementation, type these scripts:

import numpy as np import cv2 face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') cap = cv2.VideoCapture(0) while True: # Capture frame-by-frame ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required