EasyManua.ls Logo

SunFounder picar-x - Page 74

Default Icon
153 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder picar-x
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
Object Detection using Haar feature-based cascade classifiers is an effective object detection method proposed by
Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features”
in 2001.
This is a machine learning based approach, where a cascade function is trained from a large quantity of positive and
negative images, and then used to detect objects in other images.
When working with face detection, the algorithm will initially need a large quantity of positive images (images of
faces) and negative images (images without faces) to train the classifier. From there, the facial features will then need
to be extracted. For this, Haar features shown in the below image are used, similar to the convolutional kernel. Each
feature is a single value obtained by subtracting the sum of pixels under the white rectangle, from the sum of pixels
under the black rectangle.
Cascade Classifier
Cascade Classifier Training
The human_human face_detect() function processes pictures in three steps:
1. Convert picture to grayscale.
2. Detect the human face on the grayscale image to obtain the bounding rectangle of the detected face.
3. Draws a frame for the recognized object on the image.
def human_face_detect(img):
resize_img = cv2.resize(img, (320,240), interpolation=cv2.INTER_LINEAR) # To
˓reduce the amount of calculation, the image size is reduced.
gray = cv2.cvtColor(resize_img, cv2.COLOR_BGR2GRAY) # Convert picture to
˓grayscale.
faces = face_cascade.detectMultiScale(gray, 1.3, 2) # Obtain the bounding
˓rectangle of the detected face.
(continues on next page)
70 Chapter 4. Play with Python

Related product manuals