mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update eye detection Python script.
This commit is contained in:
parent
50e53c91bc
commit
baee885cd4
@ -6,38 +6,39 @@ sensor.reset()
|
|||||||
# Sensor settings
|
# Sensor settings
|
||||||
sensor.set_contrast(1)
|
sensor.set_contrast(1)
|
||||||
sensor.set_gainceiling(16)
|
sensor.set_gainceiling(16)
|
||||||
sensor.set_framesize(sensor.QCIF)
|
sensor.set_framesize(sensor.QVGA)
|
||||||
sensor.set_pixformat(sensor.GRAYSCALE)
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
|
||||||
# Load Haar Cascade
|
# Load Haar Cascade
|
||||||
# By default this will use all stages, lower satges is faster but less accurate.
|
# By default this will use all stages, lower satges is faster but less accurate.
|
||||||
face_cascade = image.HaarCascade("frontalface", stages=16)
|
face_cascade = image.HaarCascade("frontalface", stages=25)
|
||||||
print(face_cascade)
|
eyes_cascade = image.HaarCascade("eye", stages=24)
|
||||||
|
print(face_cascade, eyes_cascade)
|
||||||
|
|
||||||
# FPS clock
|
# FPS clock
|
||||||
clock = time.clock()
|
clock = time.clock()
|
||||||
|
|
||||||
while (True):
|
while (True):
|
||||||
clock.tick()
|
clock.tick()
|
||||||
|
|
||||||
# Capture snapshot
|
# Capture snapshot
|
||||||
img = sensor.snapshot()
|
img = sensor.snapshot()
|
||||||
|
# Find a face !
|
||||||
# Find objects.
|
# Note: Lower scale factor scales-down the image more and detects smaller objects.
|
||||||
# Note: Lower scale factor scales-down the img more and detects smaller objects.
|
|
||||||
# Higher threshold results in a higher detection rate, with more false positives.
|
# Higher threshold results in a higher detection rate, with more false positives.
|
||||||
objects = img.find_features(face_cascade, threshold=0.65, scale=1.65)
|
objects = img.find_features(face_cascade, threshold=0.5, scale=1.5)
|
||||||
|
|
||||||
# Draw objects
|
# Draw faces
|
||||||
for roi in objects:
|
for face in objects:
|
||||||
#img.histeq()
|
img.draw_rectangle(face)
|
||||||
eyes = img.find_eyes(roi)
|
# Now find eyes within each face.
|
||||||
img.draw_cross(eyes[0], eyes[1])
|
# Note: Use a higher threshold here (more detections) and lower scale (to find small objects)
|
||||||
img.draw_cross(eyes[2], eyes[3])
|
eyes = img.find_features(eyes_cascade, threshold=0.5, scale=1.25, roi=face)
|
||||||
img.draw_rectangle(roi)
|
for e in eyes:
|
||||||
|
e = [face[0]+e[0], face[1]+e[1], e[2], e[3]] # Add face offset
|
||||||
if (len(objects)):
|
iris = img.find_eyes(e)
|
||||||
# Add a small delay to see the drawing on the FB
|
img.draw_rectangle(e)
|
||||||
time.sleep(100)
|
img.draw_cross(iris[0], iris[1])
|
||||||
|
|
||||||
# Print FPS.
|
# Print FPS.
|
||||||
# Note: Actual FPS is higher, streaming the FB makes it slower.
|
# Note: Actual FPS is higher, streaming the FB makes it slower.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user