Example: 01-Camera/06-Time-of-Flight/tof_overlay.py
import sensor
import image
import time
import tof
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_framerate(30)
sensor.set_windowing((400, 400))
tof.init()
clock = time.clock()
while True:
clock.tick()
img = sensor.snapshot()
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
)
print(clock.fps())