-
Notifications
You must be signed in to change notification settings - Fork 0
Combine pipeline #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samcyx
wants to merge
19
commits into
main
Choose a base branch
from
combine-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+257
−3
Open
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
dc4d984
setup
samcyx 07e12b7
combined two example scripts
samcyx e61849a
Merge branch 'main' into combine-pipeline
honzikschenk b6233fc
adding main loop
samcyx 95f03b1
helper function to pass along one camera instance
samcyx 5e7a8be
Functions now use helper functions
samcyx fc78a57
removed while loop
samcyx f5c1545
addressing comments
samcyx 0da04f6
removed uneccessary libraries
samcyx 44c7a61
moved slam and rerun node to pipeline-combine.py
samcyx 52eac6f
Merge branch 'main' into combine-pipeline
honzikschenk 281aa56
renaming files and passing in cameraBundle
samcyx ca1328e
Merge branch 'combine-pipeline' of https://github.com/UWARG/Auto-AEAC…
samcyx 9136669
import fix
samcyx cf08fe0
moved folders and linted
samcyx 9050c69
oops
samcyx a17da7e
...
samcyx 1bbef64
moved requirements
samcyx b7dd5fe
fix import
samcyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ venv/ | |
|
|
||
| # Logging | ||
| logs/ | ||
|
|
||
| notes.txt | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import depthai as dai | ||
| from cameraBundle import CameraBundle | ||
|
|
||
|
|
||
| # Create pipeline | ||
| def add_basalt_vio_rtab(p: dai.Pipeline, cameras: "CameraBundle" = None): | ||
| with p: | ||
| # Ensure we have a CameraBundle (created only if not provided) | ||
| cameras = cameras or CameraBundle(p) | ||
| fps = 60 | ||
| width = 640 | ||
| height = 400 | ||
| # Define sources and outputs | ||
|
|
||
| left = cameras.monoLeft | ||
| right = cameras.monoRight | ||
| imu = p.create(dai.node.IMU) | ||
| odom = p.create(dai.node.BasaltVIO) | ||
| slam = cameras.slam | ||
| stereo = cameras.stereo | ||
| params = { | ||
| "RGBD/CreateOccupancyGrid": "true", | ||
| "Grid/3D": "true", | ||
| "Rtabmap/SaveWMState": "true", | ||
| } | ||
| slam.setParams(params) | ||
|
|
||
| imu.enableIMUSensor( | ||
| [dai.IMUSensor.ACCELEROMETER_RAW, dai.IMUSensor.GYROSCOPE_RAW], 200 | ||
| ) | ||
| imu.setBatchReportThreshold(1) | ||
| imu.setMaxBatchReports(10) | ||
|
|
||
| stereo.setExtendedDisparity(False) | ||
| stereo.setLeftRightCheck(True) | ||
| stereo.setSubpixel(True) | ||
| stereo.setRectifyEdgeFillColor(0) | ||
| stereo.enableDistortionCorrection(True) | ||
| stereo.initialConfig.setLeftRightCheckThreshold(10) | ||
| stereo.setDepthAlign(dai.CameraBoardSocket.CAM_B) | ||
|
|
||
| left.requestOutput((width, height)).link(stereo.left) | ||
| right.requestOutput((width, height)).link(stereo.right) | ||
| stereo.syncedLeft.link(odom.left) | ||
| stereo.syncedRight.link(odom.right) | ||
| stereo.depth.link(slam.depth) | ||
| stereo.rectifiedLeft.link(slam.rect) | ||
| imu.out.link(odom.imu) | ||
|
|
||
| odom.transform.link(slam.odom) | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import depthai as dai | ||
|
|
||
|
|
||
| class CameraBundle: | ||
| """Helper to create and link camera nodes and stereo outputs.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| pipeline: dai.Pipeline, | ||
| rgb_socket=dai.CameraBoardSocket.CAM_A, | ||
| left_socket=dai.CameraBoardSocket.CAM_B, | ||
| right_socket=dai.CameraBoardSocket.CAM_C, | ||
| mono_resolution=(640, 400), | ||
| ): | ||
| self.pipeline = pipeline | ||
| self.camRgb = pipeline.create(dai.node.Camera).build(rgb_socket) | ||
| self.monoLeft = pipeline.create(dai.node.Camera).build(left_socket) | ||
| self.monoRight = pipeline.create(dai.node.Camera).build(right_socket) | ||
| self.slam = pipeline.create(dai.node.RTABMapSLAM) | ||
|
|
||
| self.stereo = pipeline.create(dai.node.StereoDepth) | ||
| self.leftOutput = self.monoLeft.requestOutput(mono_resolution) | ||
| self.rightOutput = self.monoRight.requestOutput(mono_resolution) | ||
| self.leftOutput.link(self.stereo.left) | ||
| self.rightOutput.link(self.stereo.right) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import depthai as dai | ||
| from cameraBundle import CameraBundle | ||
|
|
||
| fullFrameTracking = False | ||
|
|
||
| # Create pipeline | ||
|
|
||
|
|
||
| def add_object_tracker(p: dai.Pipeline, cameras: "CameraBundle" = None): | ||
| with p: | ||
| cameras = cameras or CameraBundle(p) | ||
| camRgb = cameras.camRgb | ||
| stereo = cameras.stereo | ||
|
|
||
| spatialDetectionNetwork = p.create( | ||
| dai.node.SpatialDetectionNetwork | ||
| ).build(camRgb, stereo, "yolov6-nano") | ||
| objectTracker = p.create(dai.node.ObjectTracker) | ||
|
|
||
| spatialDetectionNetwork.setConfidenceThreshold(0.6) | ||
| spatialDetectionNetwork.input.setBlocking(False) | ||
| spatialDetectionNetwork.setBoundingBoxScaleFactor(0.5) | ||
| spatialDetectionNetwork.setDepthLowerThreshold(100) | ||
| spatialDetectionNetwork.setDepthUpperThreshold(5000) | ||
|
|
||
| objectTracker.setDetectionLabelsToTrack([0]) # track only person | ||
| # possible tracking types: ZERO_TERM_COLOR_HISTOGRAM, ZERO_TERM_IMAGELESS, SHORT_TERM_IMAGELESS, SHORT_TERM_KCF | ||
| objectTracker.setTrackerType(dai.TrackerType.SHORT_TERM_IMAGELESS) | ||
| # take the smallest ID when new object is tracked, possible options: SMALLEST_ID, UNIQUE_ID | ||
| objectTracker.setTrackerIdAssignmentPolicy( | ||
| dai.TrackerIdAssignmentPolicy.SMALLEST_ID | ||
| ) | ||
|
|
||
| if fullFrameTracking: | ||
| camRgb.requestFullResolutionOutput().link(objectTracker.inputTrackerFrame) | ||
| # do not block the pipeline if it's too slow on full frame | ||
| objectTracker.inputTrackerFrame.setBlocking(False) | ||
| objectTracker.inputTrackerFrame.setMaxSize(1) | ||
| else: | ||
| spatialDetectionNetwork.passthrough.link(objectTracker.inputTrackerFrame) | ||
|
|
||
| spatialDetectionNetwork.passthrough.link(objectTracker.inputDetectionFrame) | ||
| spatialDetectionNetwork.out.link(objectTracker.inputDetections) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import Basalt_VIO_RTab | ||
| from rerun_node import RerunNode | ||
| import object_tracker | ||
| import depthai as dai | ||
| import time | ||
| from cameraBundle import CameraBundle | ||
| # This is the main pipeline-combine.py file that integrates Basalt VIO with RTAB-Map SLAM | ||
|
|
||
|
|
||
| with dai.Pipeline() as pipeline: | ||
| cameraBundle = CameraBundle(pipeline) | ||
| object_tracker.add_object_tracker(pipeline) | ||
|
||
| Basalt_VIO_RTab.add_basalt_vio_rtab(pipeline, cameraBundle) | ||
| rerunViewer = RerunNode() | ||
| slam = cameraBundle.slam | ||
| slam.transform.link(rerunViewer.inputTrans) | ||
| slam.passthroughRect.link(rerunViewer.inputImg) | ||
| slam.occupancyGridMap.link(rerunViewer.inputGrid) | ||
| slam.obstaclePCL.link(rerunViewer.inputObstaclePCL) | ||
| slam.groundPCL.link(rerunViewer.inputGroundPCL) | ||
| pipeline.start() | ||
| try: | ||
| while pipeline.isRunning(): | ||
| time.sleep(0.1) | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| pipeline.stop() | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import depthai as dai | ||
| import sys | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| installExamplesStr = ( | ||
| Path(__file__).absolute().parents[2] / "install_requirements.py --install_rerun" | ||
| ) | ||
| try: | ||
| import rerun as rr | ||
| except ImportError: | ||
| sys.exit( | ||
| "Critical dependency missing: Rerun. Please install it using the command: '{} {}' and then rerun the script.".format( | ||
| sys.executable, installExamplesStr | ||
| ) | ||
| ) | ||
|
|
||
| import cv2 | ||
|
|
||
|
|
||
| class RerunNode(dai.node.ThreadedHostNode): | ||
| def __init__(self): | ||
| dai.node.ThreadedHostNode.__init__(self) | ||
| self.inputTrans = dai.Node.Input(self) | ||
| self.inputImg = dai.Node.Input(self) | ||
| self.inputObstaclePCL = dai.Node.Input(self) | ||
| self.inputGroundPCL = dai.Node.Input(self) | ||
| self.inputGrid = dai.Node.Input(self) | ||
| self.positions = [] | ||
| self.fx = 400.0 | ||
| self.fy = 400.0 | ||
| self.intrinsicsSet = False | ||
|
|
||
| def getFocalLengthFromImage(self, imgFrame): | ||
| p = self.getParentPipeline() | ||
| calibHandler = p.getDefaultDevice().readCalibration() | ||
| intrinsics = calibHandler.getCameraIntrinsics( | ||
| dai.CameraBoardSocket(imgFrame.getInstanceNum()), | ||
| imgFrame.getWidth(), | ||
| imgFrame.getHeight(), | ||
| ) | ||
| self.fx = intrinsics[0][0] | ||
| self.fy = intrinsics[1][1] | ||
| self.intrinsicsSet = True | ||
|
|
||
| def run(self): | ||
| rr.init("", spawn=True) | ||
| rr.log("world", rr.ViewCoordinates.FLU) | ||
| rr.log("world/ground", rr.Boxes3D(half_sizes=[3.0, 3.0, 0.00001])) | ||
| while self.isRunning(): | ||
| transData = self.inputTrans.get() | ||
| imgFrame = self.inputImg.get() | ||
| if not self.intrinsicsSet: | ||
| self.getFocalLengthFromImage(imgFrame) | ||
| pclObstData = self.inputObstaclePCL.tryGet() | ||
| pclGrndData = self.inputGroundPCL.tryGet() | ||
| mapData = self.inputGrid.tryGet() | ||
| if transData is not None: | ||
| trans = transData.getTranslation() | ||
| quat = transData.getQuaternion() | ||
| position = rr.datatypes.Vec3D([trans.x, trans.y, trans.z]) | ||
| rr.log( | ||
| "world/camera", | ||
| rr.Transform3D( | ||
| translation=position, | ||
| rotation=rr.datatypes.Quaternion( | ||
| xyzw=[quat.qx, quat.qy, quat.qz, quat.qw] | ||
| ), | ||
| ), | ||
| ) | ||
| self.positions.append(position) | ||
| lineStrip = rr.components.LineStrip3D(self.positions) | ||
| rr.log("world/trajectory", rr.LineStrips3D(lineStrip)) | ||
| rr.log( | ||
| "world/camera/image", | ||
| rr.Pinhole( | ||
| resolution=[imgFrame.getWidth(), imgFrame.getHeight()], | ||
| focal_length=[self.fx, self.fy], | ||
| camera_xyz=rr.ViewCoordinates.FLU, | ||
| ), | ||
| ) | ||
| img = imgFrame.getCvFrame() | ||
| img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
| rr.log("world/camera/image/rgb", rr.Image(img)) | ||
| if pclObstData is not None: | ||
| points, colors = pclObstData.getPointsRGB() | ||
| rr.log( | ||
| "world/obstacle_pcl", | ||
| rr.Points3D(points, colors=colors, radii=[0.01]), | ||
| ) | ||
| if pclGrndData is not None: | ||
| points, colors = pclGrndData.getPointsRGB() | ||
| rr.log( | ||
| "world/ground_pcl", | ||
| rr.Points3D(points, colors=colors, radii=[0.01]), | ||
| ) | ||
| if mapData is not None: | ||
| rr.log("map", rr.Image(mapData.getCvFrame())) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very small nit but if you could make the two functions formatted the same, that'd be much appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this note, please rename all the files to be consistent with the
rerun_node.pyfile (snake case)