单色灰度色块跟踪示例

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 单色灰度色块跟踪示例
#
# 此示例展示了使用OpenMV Cam进行单色灰度跟踪。

import csi
import time
import math

# 颜色跟踪阈值(灰度最小值,灰度最大值)
# 下面的灰度阈值设置为仅找到极亮的白色区域。
thresholds = (245, 255)

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.VGA)
csi0.snapshot(time=2000)
csi0.auto_gain(False)  # 必须关闭以进行颜色跟踪
csi0.auto_whitebal(False)  # 必须关闭以进行颜色跟踪
clock = time.clock()

# 只有像素数超过“pixel_threshold”且面积超过“area_threshold”的blob才会被
# “find_blobs”返回。如果更改了“pixels_threshold”和“area_threshold”,请进行相应调整。
# 相机分辨率。"merge=True" 合并图像中所有重叠的斑点。

while True:
    clock.tick()
    img = csi0.snapshot()
    for blob in img.find_blobs(
        [thresholds], pixels_threshold=100, area_threshold=100, merge=True
    ):
        # 这些数值依赖于色块非圆形的特性——否则它们会变得不稳定。
        if blob.elongation > 0.5:
            img.draw_edges(blob.min_corners, color=0)
            img.draw_line(image.get_major_axis_line(blob), color=0)
            img.draw_line(image.get_minor_axis_line(blob), color=0)
        # 这些数值始终保持稳定。
        img.draw_detection(blob, color1=127)
        # 注意 - 色块旋转角度仅在0-180度范围内唯一。
        img.draw_keypoints(
            [(blob.cx, blob.cy, int(math.degrees(blob.rotation)))],
            size=40,
            color=127,
        )
    print(clock.fps())

results matching ""

    No results matching ""