Example: 05-Feature-Detection/find_circles.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Find Circles Example
#
# This example shows off how to find circles in the image using the Hough
# 变换。https://zh.wikipedia.org/wiki/霍夫变换#圆形霍夫变换
#
# 注意,find_circles()方法仅能检测完全位于图像内部的圆。
# 超出图像或感兴趣区域(ROI)边界的圆将被忽略...

import sensor
import time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)  # 灰度处理速度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=2000)
clock = time.clock()

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

    # 圆形对象包含四个参数:x坐标、y坐标、r(半径)和幅度值。
    # 幅度值代表圆形检测的置信度,数值越高
    # 表示结果越可靠...

    # `threshold`参数控制检测到的圆数量,增大该值
    # 可减少被识别的圆形数量...

    # `x_margin`、`y_margin` 和 `r_margin` 控制相似圆的合并
    # 在 x、y 和 r(半径)方向上合并圆。

    # r_min、r_max和r_step参数用于设定待检测圆的半径范围。
    # 缩小待检测半径范围可显著提升算法性能。

    for c in img.find_circles(
        threshold=2000,
        x_margin=10,
        y_margin=10,
        r_margin=10,
        r_min=2,
        r_max=100,
        r_step=2,
    ):
        img.draw_circle(c.x(), c.y(), c.r(), color=(255, 0, 0))
        print(c)

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

results matching ""

    No results matching ""