Example: 05-Feature-Detection/lbp.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 局部二值模式(LBP)示例
#
# 本示例展示了如何在您的OpenMV Cam上使用局部二值模式特征描述符
# LBP描述符的工作原理类似于Freak特征描述符
#
# 警告:LBP支持功能需要重新设计!目前该功能尚需
# 大量改进才能变得实用。保留此脚本仅为展示
# 该功能存在,但当前状态尚不完善

import sensor
import time
import image

# 重置传感器
sensor.reset()

# 传感器设置
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

# 加载 Haar 级联
# 默认情况下,这将使用所有阶段,较低的阶段速度更快但准确性较低。
face_cascade = image.HaarCascade("frontalface", stages=25)
print(face_cascade)

# 跳过几帧以使传感器稳定下来
# 注意:从IDE执行时耗时更长
for i in range(0, 30):
    img = sensor.snapshot()
    img.draw_string(0, 0, "Please wait...")

d0 = None
# d0 = image.load_descriptor("/desc.lbp")
clock = time.clock()

while True:
    clock.tick()
    img = sensor.snapshot()

    objects = img.find_features(face_cascade, threshold=0.5, scale_factor=1.25)
    if objects:
        face = objects[0]
        d1 = img.find_lbp(face)
        if d0 is None:
            d0 = d1
        else:
            dist = image.match_descriptor(d0, d1)
            img.draw_string(0, 10, "Match %d%%" % (dist))

        img.draw_rectangle(face)
    # 绘制帧率(FPS)
    img.draw_string(0, 0, "FPS:%.2f" % (clock.fps()))

results matching ""

    No results matching ""