Example: 03-Machine-Learning/02-Haar-Cascade/iris_detection.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 虹膜检测示例2
#
# 本示例展示了如何在图像中定位眼睛后,进一步检测视线(瞳孔定位)
# 该脚本使用find_eyes函数,通过确定ROI区域内最暗区域的中心点
# (即瞳孔中心)来实现。其原理本质上是
# 在眼睛ROI中寻找最暗区域的中心作为瞳孔位置。
#
# 注意:本脚本不预先进行面部检测,需配合长焦镜头使用。

import sensor
import time
import image

# 重置传感器
sensor.reset()

# 传感器设置
sensor.set_contrast(3)
sensor.set_gainceiling(16)

# 将分辨率设置为VGA。
sensor.set_framesize(sensor.VGA)

# 将图像裁剪/分档为200x100分辨率,以更少数据量处理更多细节
sensor.set_windowing((220, 190, 200, 100))

sensor.set_pixformat(sensor.GRAYSCALE)

# 加载 Haar 级联
# 默认使用全阶段检测,降低阶段数速度更快但精度下降。
eyes_cascade = image.HaarCascade("eye", stages=24)
print(eyes_cascade)

# FPS时钟
clock = time.clock()

while True:
    clock.tick()
    # 捕获快照
    img = sensor.snapshot()
    # 寻找眼睛!
    # 注意:较低的缩放因子会更多地缩小图像并检测较小的对象。
    # 较高的阈值会导致更高的检测率,但也会产生更多的误报。
    eyes = img.find_features(eyes_cascade, threshold=0.5, scale_factor=1.5)

    # 检测虹膜
    for e in eyes:
        iris = img.find_eye(e)
        img.draw_rectangle(e)
        img.draw_cross(iris[0], iris[1])

    # 打印FPS。
    # 注意:实际帧率更高,流式传输帧缓冲区会使其变慢。
    print(clock.fps())

results matching ""

    No results matching ""