genx320_event_mode_calibration.py
import csi
import image
import time
from ulab import numpy as np
CAL_EVENT_COUNT = 10000
CAL_SIGMA = 0.5
img = image.Image(320, 320, image.GRAYSCALE)
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()
event_count = csi0.ioctl(csi.IOCTL_GENX320_READ_EVENTS, events)
img.draw_event_histogram(events[:event_count], clear=True, brightness=128, contrast=64)
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())