Example: 05-Feature-Detection/linear_regression.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Linear Regression Example
#
# 这个示例展示了如何在您的OpenMV Cam上使用get_regression()方法
# 来获取感兴趣区域的线性回归。使用此方法,您可以轻松构建
# 一个能够跟踪指向同一方向的线条的机器人
# 但这些线条实际上并未连接。对于连接良好的线条,使用find_blobs()
# 以获得更好的过滤选项和控制。
#
# get_regression() runs in O(N^2) time on the image. To keep this manageable it
# area-scales the source ROI down to a temporary buffer before fitting the line;
# the buffer size is configurable via the target_size=(w, h) keyword argument
# (default (80, 60)). Pass a larger tuple to operate at higher resolution.

import csi
import time

THRESHOLD = (0, 100)  # 用于暗色物体的灰度阈值。
BINARY_VISIBLE = True  # 首先进行二值化处理,以查看线性回归的运行情况。

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)

clock = time.clock()  # 可能需要几秒钟。

while True:
    clock.tick()
    img = csi0.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else csi0.snapshot()

    # 返回一个类似于find_lines()和find_line_segments()返回的线条对象
    # find_line_segments(). You have x1, y1, x2, y2, length,
    # theta (rotation in degrees), rho, and magnitude attributes.
    #
    # magnitude represents how well the linear regression worked. In general,
    # the larger the value the better...
    line = img.get_regression([(255, 255) if BINARY_VISIBLE else THRESHOLD])

    if line:
        img.draw_line(line, color=127)
    print(
        "FPS %f, mag = %s" % (clock.fps(), str(line.magnitude) if (line) else "N/A")
    )

# 关于负 rho 值:
#
# 一个 [theta+0:-rho] 元组与 [theta+180:+rho] 相同。

results matching ""

    No results matching ""