-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdetect_eyes.py
35 lines (31 loc) · 1.03 KB
/
detect_eyes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import video, sensor, image, lcd, time
lcd.init()
# Reset sensor
sensor.reset()
# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.run(1)
sensor.skip_frames(30)
v = video.open("/sd/capture_eyes.avi", record=1, interval=200000, quality=50)
# 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)
tim = time.ticks_ms()
while(time.ticks_diff(time.ticks_ms(), tim)<30000):
# Capture snapshot
img = sensor.snapshot()
objects = img.find_features(face_cascade, threshold=0.5, scale_factor=1.5)
for face in objects:
img.draw_rectangle(face)
eyes = img.find_features(eyes_cascade, threshold=0.5, scale_factor=1.2, roi=face)
for e in eyes:
img.draw_rectangle(e)
img_len = v.record(img)
lcd.display(img)
print("finish")
v.record_finish()
lcd.clear()