mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Finished going through imlib.c. -> Histeq uses fb_alloc now and has hook for RGB histeq when reserve YUV LUT is added (coming soon in next PR). Cleanuped py_helper.c/h -> No functional changes. Just added some header info. Finished going through py_image.c * 1 - Finished general code cleanup and updating everything to using new library functions. In particular, I updated the remaining find_* functions with the new roi clipping code when they accept rois. * 2 - Made blob stuff return a list when nothing is found so you don't have to do an if on the returned value anymore. * 3 - img subscr is more powerful now allowing image reading and writing. I updated this because I had to use it to find a previous bug with socket.send() for the WINC driver. * 4 - Renamed find_eyes to find_eye. Because it just finds one eye. * 5 - Other than that just general code cleanup to make functions look consistent. And yes, changes have been test. Face tracking, eye tracking, keypoints, etc. all work still. Future things todo before release: 1 - Change all LAB stuff to YUV. 2 - Add in reverse YUV->RGB LUT and update functions like Mode() to use this so they don't generate messed up outputs, also histeq() too. 3 - Add any remaining sensor control functions like agc control.
52 lines
1.7 KiB
Python
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_eye(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())
|