mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
examples: Add ToF examples.
This commit is contained in:
parent
c9f0d8e0d0
commit
5bb8545cf1
30
scripts/examples/OpenMV/38-Time-of-Flight/tof_camera.py
Normal file
30
scripts/examples/OpenMV/38-Time-of-Flight/tof_camera.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Time of Flight overlay Demo
|
||||||
|
#
|
||||||
|
# This example shows off how to overlay a depth map onto
|
||||||
|
# OpenMV Cam's live video output from the main camera.
|
||||||
|
|
||||||
|
import image, time, tof
|
||||||
|
|
||||||
|
IMAGE_SCALE = 10 # Higher scaling uses more memory.
|
||||||
|
drawing_hint = image.BILINEAR # or image.BILINEAR or 0 (nearest neighbor)
|
||||||
|
|
||||||
|
# Initialize the ToF sensor
|
||||||
|
tof.init() #Auto-detects the connected sensor.
|
||||||
|
w = tof.width() * IMAGE_SCALE
|
||||||
|
h = tof.height() * IMAGE_SCALE
|
||||||
|
|
||||||
|
# FPS clock
|
||||||
|
clock = time.clock()
|
||||||
|
|
||||||
|
while (True):
|
||||||
|
clock.tick()
|
||||||
|
|
||||||
|
try:
|
||||||
|
img = tof.snapshot(x_size=w, y_size=h,
|
||||||
|
color_palette=tof.PALETTE_IRONBOW,
|
||||||
|
hint=drawing_hint, copy_to_fb=True, scale=(0, 4000))
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Print FPS.
|
||||||
|
print(clock.fps())
|
||||||
42
scripts/examples/OpenMV/38-Time-of-Flight/tof_overlay.py
Normal file
42
scripts/examples/OpenMV/38-Time-of-Flight/tof_overlay.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Time of Flight overlay Demo
|
||||||
|
#
|
||||||
|
# This example shows off how to overlay a depth map onto
|
||||||
|
# OpenMV Cam's live video output from the main camera.
|
||||||
|
import sensor, image, time, tof
|
||||||
|
|
||||||
|
sensor.reset()
|
||||||
|
sensor.set_pixformat(sensor.RGB565)
|
||||||
|
sensor.set_framesize(sensor.QVGA)
|
||||||
|
sensor.set_windowing((0, 0, 240, 240))
|
||||||
|
|
||||||
|
# Initialize the ToF sensor
|
||||||
|
tof.init()
|
||||||
|
|
||||||
|
# FPS clock
|
||||||
|
clock = time.clock()
|
||||||
|
|
||||||
|
while (True):
|
||||||
|
clock.tick()
|
||||||
|
|
||||||
|
# Capture an image
|
||||||
|
img = sensor.snapshot()
|
||||||
|
|
||||||
|
# Capture TOF data [depth map, min distance, max distance]
|
||||||
|
try:
|
||||||
|
depth, dmin, dmax = tof.read_depth()
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Scale the image and belnd it with the framebuffer
|
||||||
|
tof.draw_depth(img, depth, hint=image.BILINEAR,
|
||||||
|
alpha=200, scale=(0, 4000), color_palette=tof.PALETTE_IRONBOW)
|
||||||
|
|
||||||
|
# Draw min and max distance.
|
||||||
|
img.draw_string(8, 0, "Min distance: %d mm" % dmin, color = (255, 0, 0), mono_space = False)
|
||||||
|
img.draw_string(8, 8, "Max distance: %d mm" % dmax, color = (255, 0, 0), mono_space = False)
|
||||||
|
|
||||||
|
# Force high quality streaming
|
||||||
|
img.compress(quality=90)
|
||||||
|
|
||||||
|
# Print FPS.
|
||||||
|
print(clock.fps())
|
||||||
Loading…
Reference in New Issue
Block a user