Created
June 13, 2024 14:52
-
-
Save Erol444/14052a0f76b35e4b087345b14c06252a to your computer and use it in GitHub Desktop.
OAK-D Long Range Tractor pointcloud visualization with native Rerun (non-colorized pointclouds?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from depthai_sdk import OakCamera | |
import cv2 | |
import depthai as dai | |
import rerun as rr | |
# Run & initialize ReRun viewer | |
rr.init('Rerun Oak-D-LR', spawn=True) | |
# Download and run the tractor recording | |
with OakCamera(replay="tractor-oak-d-lr") as oak: | |
oak.replay.set_fps(10) | |
# cam_a = oak.create_camera('CAM_A') | |
cam_b = oak.create_camera('CAM_B') | |
cam_c = oak.create_camera('CAM_C') | |
# Downscale the 1920x1200 frames to 1280x800 | |
oak.replay.resize('cam_c', (1280, 800)) | |
oak.replay.resize('cam_b', (1280, 800)) | |
nn = oak.create_nn('mobilenet-ssd', cam_c) | |
stereo = oak.create_stereo(left=cam_b, right=cam_c) | |
stereo.node.setOutputSize(640, 400) | |
stereo.config_stereo(confidence=215, lr_check=True, extended=True, subpixel=True, subpixel_bits=5) | |
stereo.config_stereo(align=cam_c) | |
stereo.node.setDepthAlign(dai.CameraBoardSocket.CAM_C) | |
# On-device post processing for stereo depth | |
config = stereo.node.initialConfig.get() | |
stereo.node.setPostProcessingHardwareResources(4, 4) | |
config.postProcessing.speckleFilter.enable = True | |
config.postProcessing.speckleFilter.speckleRange = 50 | |
config.postProcessing.temporalFilter.enable = False | |
config.postProcessing.spatialFilter.enable = True | |
config.postProcessing.spatialFilter.holeFillingRadius = 1 | |
config.postProcessing.spatialFilter.numIterations = 1 | |
config.postProcessing.thresholdFilter.minRange = 400 | |
config.postProcessing.thresholdFilter.maxRange = 15000 | |
config.postProcessing.brightnessFilter.maxBrightness = 255 | |
stereo.node.initialConfig.set(config) | |
q = oak.queue([ | |
stereo.out.depth.set_name('depth'), | |
stereo.out.rectified_right.set_name('rr'), | |
nn.out.main.set_name('nn'), | |
]).configure_syncing(enable_sync=True, threshold_ms=250).get_queue() | |
# oak.show_graph() | |
oak.start() | |
calibData = oak.device.readCalibration() | |
intrinsics = calibData.getCameraIntrinsics(dai.CameraBoardSocket.CAM_C, dai.Size2f(640, 400)) | |
rr.log('LR', rr.ViewCoordinates.RDF, static=True) | |
rr.log("LR/Color", rr.Transform3D(translation=[0,0,0], rotation=[1,0,0,0], from_parent=True), static=True) | |
rr.log("LR/Color/Image", rr.Pinhole(width=640, height=400, image_from_camera=intrinsics), static=True) | |
while oak.running(): | |
packets = q.get() | |
depth = packets['depth'] | |
rr.log("Right", rr.Image(packets['rr'].frame)) | |
color = packets['nn'].frame | |
color = cv2.pyrDown(color) # Downscale to match 640x400 depth frame | |
rr.log("LR/Color/Image", rr.Image(color[:, :, ::-1])) # BGR to RGB | |
rr.log("LR/Color/Image/Depth", rr.DepthImage(depth.frame, meter=1e3)) | |
oak.poll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment