openmv/usr/examples/08-Eye-Tracking/iris_detection.py
Kwabena W. Agyeman 0abd5d3688 Working on scripts...
Moved feature detection scripts into their own folders and added explict
frame_skip value per Ibrahim's request.

Finished working on snapshot and video recording scripts for next
release.

... From CMUcam4 work I learned that people will just want examples that
do "X" thing. So, in general, our examples should include a simple
script showing off a feature and then a more complex script that does "X"
where "X" is some app that a person would want. For example, we'll get
reuqests for face tracking with servos, and movement detection with
servos. So, instead of answering this question a million times with an
example script we'll just have examples for all kinds of things people
will want.

Gotta automate dealing with help support at the end of the day...
2016-04-02 11:18:20 -04:00

45 lines
1.3 KiB
Python

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())