Example: 02-Image-Processing/02-Color-Tracking/ir_beacon_grayscale_tracking.py

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

import sensor
import time

thresholds = (255, 255)  # 来自 IR 的明亮白光的阈值。

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((240, 240))  # VGA 的 240x240 中心像素
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)  # 必须关闭以进行颜色跟踪
sensor.set_auto_whitebal(False)  # 必须关闭以进行颜色跟踪
clock = time.clock()

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

while True:
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs(
        [thresholds], pixels_threshold=200, area_threshold=200, merge=True
    ):
        ratio = blob.w() / blob.h()
        if (ratio >= 0.5) and (ratio <= 1.5):  # 过滤掉非方形斑点
            img.draw_rectangle(blob.rect())
            img.draw_cross(blob.cx(), blob.cy())
    print(clock.fps())

results matching ""

    No results matching ""