openmv/usr/examples/08-Eye-Tracking/iris_detection.py
Kwabena W. Agyeman 4c88c110cf 60 Scripts.
Everything except the DAC script works. That has to be fixed. Anyway, we
have a ton of example for launch. So, hopefully, comments about how to
do stuff should be limited.

That said, the PYB module is in a poor state still. Stuff kinda works and
kinda doesn't from it.

One day... There won't be any fires to put out on this project and I can
stop working so hard.
2016-04-21 20:01:17 -04:00

52 lines
1.7 KiB
Python

# Iris Detection Example
#
# This example shows how to find the eye gaze (pupil detection) after finding
# the eyes in an image. This script uses the find_eyes function which determines
# the center point of roi that should contain a pupil. It does this by basically
# finding the center of the darkest area in the eye roi which is the pupil center.
import sensor, time, image
# Reset sensor
sensor.reset()
# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=25)
eyes_cascade = image.HaarCascade("eye", stages=24)
print(face_cascade, eyes_cascade)
# FPS clock
clock = time.clock()
while (True):
clock.tick()
# 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=1.5)
# Draw faces
for face in objects:
img.draw_rectangle(face)
# 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=1.2, roi=face)
for e in eyes:
iris = img.find_eyes(e)
img.draw_rectangle(e)
img.draw_cross(iris[0], iris[1])
# Print FPS.
# Note: Actual FPS is higher, streaming the FB makes it slower.
print(clock.fps())