genx320_event_mode_calibration.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2025 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 此示例展示了如何使用Prophesee的GENX320事件相机,
# 使用事件流模式并校准相机。

import csi
import image
import time

# https://micropython-ulab.readthedocs.io/en/latest/index.html
from ulab import numpy as np

CAL_EVENT_COUNT = 10000  # 校准所需收集的事件数量。
CAL_SIGMA = 0.5  # 热像素检测的标准差。

# 用于绘制直方图图像的画布。
img = image.Image(320, 320, image.GRAYSCALE)

# 存储相机事件
# 形状:(EVT_res, 6),其中EVT_res是事件分辨率
# EVT_res:必须是1024到65536之间的2的幂。
# 各列含义:
# [0]  事件类型
# [1]  秒时间戳
# [2]  毫秒时间戳
# [3]  微秒时间戳
# [4]  X坐标,GENX320为0到319
# [5]  Y坐标,GENX320为0到319
events = np.zeros((2048, 6), dtype=np.uint16)

# 初始化传感器。
csi0 = csi.CSI(cid=csi.GENX320)
csi0.reset()
csi0.ioctl(csi.IOCTL_GENX320_SET_MODE, csi.GENX320_MODE_EVENT, events.shape[0])

clock = time.clock()

t = time.ticks_ms()
calibrated = False
while True:
    clock.tick()

    # 从相机读取2048个事件。
    # 返回有效事件数(0-2048)或负的错误码。
    event_count = csi0.ioctl(csi.IOCTL_GENX320_READ_EVENTS, events)

    # 将事件渲染成直方图图像。
    # 若clear=True,绘制前图像会被重置为“brightness”。
    # 每个PIX_ON_EVENT会给对应像素值加上“contrast”;
    # 每个PIX_OFF_EVENT则减去它,并钳制在[0, 255]。
    # 若clear=False,直方图会在多次调用间累积。
    img.draw_event_histogram(events[:event_count], clear=True, brightness=128, contrast=64)

    # 将图像推送到jpeg缓冲区,供IDE拉取并显示。
    # IDE从相机拉取帧的速率远低于下面打印的
    # 板载相机帧率。
    img.flush()

    # 先显示未校准的图像。
    if not calibrated and time.ticks_diff(time.ticks_ms(), t) > 5000:
        disabled_pixels = csi0.ioctl(csi.IOCTL_GENX320_CALIBRATE, CAL_EVENT_COUNT, CAL_SIGMA)
        print(f'Disabled {disabled_pixels} hot pixels.')
        calibrated = True

    print(event_count, clock.fps())

results matching ""

    No results matching ""