tof_overlay.py
import csi
import image
import time
import tof
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.framerate(30)
csi0.window((400, 400))
tof.init()
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
try:
depth, dmin, dmax = tof.read_depth(vflip=True, hmirror=True)
except RuntimeError:
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
)
print(clock.fps())