## >>> 星瞳科技-OpenMV中文教程网 <<<

# Iris Detection 2 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.
#
# Note: This script does not detect a face first, use it with the telephoto lens.

import sensor, time, image

# Reset sensor
sensor.reset()

# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)

# Set resolution to VGA.
sensor.set_framesize(sensor.VGA)

#拉近镜头，使眼睛的更多细节展现在摄像头中。
# Bin/Crop image to 200x100, which gives more details with less data to process
sensor.set_windowing((220, 190, 200, 100))

sensor.set_pixformat(sensor.GRAYSCALE)

# By default this will use all stages, lower satges is faster but less accurate.
#加载眼睛的haar算子

# FPS clock
clock = time.clock()

while (True):
clock.tick()
# Capture snapshot
img = sensor.snapshot()
# Find eyes !
# 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.

# Find iris
#在识别到的人眼中寻找瞳孔。
for e in eyes:
iris = img.find_eye(e)
#image.find_eye((x, y, w, h)),find_eye的参数是一个矩形区域，左上顶点为
#（x,y），宽w,高h，注意（x,y,w,h）是一个元组，不要漏掉括号（）。上行代码中
#的e即代表识别到的眼睛的矩形区域。
#find_eye的原理是找到区域中颜色最深处的中心。
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())