Example: 05-Feature-Detection/find_rects.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 查找矩形示例
#
# 此示例展示了如何使用 April Tags 代码中的四边形阈值检测
# 在图像中查找矩形。四边形阈值检测算法
# 以极其稳健的方式检测矩形,远优于基于霍夫变换
# 的方法。例如,即使镜头失真,它仍然可以检测到矩形。
# 失真导致这些矩形看起来弯曲。圆角矩形没有问题!
# (但是,考虑到这一点,代码也会检测到小半径的圆)...

import sensor
import time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)  # 灰度处理速度更快 (160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=2000)
clock = time.clock()

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

    # 下面的 `threshold` 应设置为足够高的值以过滤掉噪声
    # 图像中检测到的矩形具有较低的边缘幅度。矩形
    # 边缘幅度越大,它们越大且对比度越高...

    for r in img.find_rects(threshold=10000):
        img.draw_rectangle(r.rect(), color=(255, 0, 0))
        for p in r.corners():
            img.draw_circle(p[0], p[1], 5, color=(0, 255, 0))
        print(r)

    print("FPS %f" % clock.fps())

results matching ""

    No results matching ""