In this section, we try Haar Cascade to apply face detection on OpenMV. We load frontalface for data. Then, we call find_features() to find face objects. If found, we draw rectangles using draw_rectangle().
For demo, open OpenMV IDE and write the complete codes.
import sensor, image sensor.reset() sensor.set_contrast(1) sensor.set_gainceiling(16) sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) # Load Haar Cascade face_cascade = image.HaarCascade("frontalface", stages=25) print(face_cascade) while (True): img = sensor.snapshot() objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25) # Draw objects for r in objects: img.draw_rectangle(r)
Save this program as face_detection.py.
Run this program to OpenMV IDE. Shot your face or people picture.
Based on my experience, it's good performance to detect face detection even I have tested on picture on smartphone.