I took that script and modified it to 1) light up the red LED, 2) use a circle for the face (to differentiate it from the eyes) and 3) quit:
# Face Eye Detection Example
# This script uses the built-in frontalface detector to find a face and then
# the eyes within the face. If you want to determine the eye gaze please see the
# iris_detection script for an example on how to do that.
import sensor, time, image
from pyb import LED
red_led = LED(1)
# Reset sensor
# Sensor settings
# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=30)
eyes_cascade = image.HaarCascade("eye", stages=24)
# FPS clock
clock = time.clock()
x = round(rect / 2) + rect
y = round(rect / 2) + rect
r = round(rect / 2)
return (x, y, r)
notFound = True
# Capture snapshot
img = sensor.snapshot()
# Find a face !
# Note: Lower scale factor scales-down the image more and detects smaller objects.
# Higher threshold results in a higher detection rate, with more false positives.
objects = img.find_features(face_cascade, threshold=0.5, scale_factor=1.4)
# Draw faces
for face in objects:
(x,y, r) = circle_from_rect(face)
img.draw_circle(x, y, r)
# Now find eyes within each face.
# Note: Use a higher threshold here (more detections) and lower scale (to find small objects)
eyes = img.find_features(eyes_cascade, threshold=0.5, scale_factor=1.2, roi=face)
for e in eyes:
#(x, y, r) = circle_from_rect(e)
#img.draw_circle(x, y, r)
notFound = False
# Print FPS.
# Note: Actual FPS is higher, streaming the FB makes it slower.
It shows the last frame, always with a circle around my face even though it detected my eyes.
This isn’t a big deal since I don’t plan on using it long-term. I just was wondering if anyone else had this issue and they knew why.