Example: 01-Camera/06-Time-of-Flight/tof_overlay.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 此示例展示了如何将深度图叠加到主摄像头捕获的帧上。
# 从主摄像头捕获。
import sensor
import image
import time
import tof

sensor.reset()  # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565)  # 将像素格式设置为RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.VGA)  # 将帧大小设置为QVGA (320x240)
sensor.set_framerate(30)
sensor.set_windowing((400, 400))  # 将窗口大小设置为240x240

# 初始化ToF传感器
tof.init()

# FPS时钟
clock = time.clock()

while True:
    clock.tick()
    # 捕获图像
    img = sensor.snapshot()
    # 捕获TOF数据 [深度图, 最小距离, 最大距离]
    try:
        depth, dmin, dmax = tof.read_depth(vflip=True, hmirror=True)
    except RuntimeError:
        tof.reset()
        continue

    # 缩放图像并将其与帧缓冲区混合
    tof.draw_depth(
        img,
        depth,
        x_scale=img.width() / 8,
        y_scale=img.height() / 8,
        hint=image.BILINEAR,
        alpha=100,
        scale=(0, 4000),
        color_palette=image.PALETTE_DEPTH,
    )

    # 绘制最小和最大距离。
    img.draw_string(
        0, 0, f"Distance min: {int(dmin):4d}mm max: {int(dmax):4d}mm", color=(255, 0, 0), mono_space=False
    )

    # 打印FPS。
    print(clock.fps())

results matching ""

    No results matching ""