Skip to content
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

Perception Autonomy Cleanup #450

Merged
merged 24 commits into from
Dec 18, 2024
Merged

Conversation

TomaszTB
Copy link
Contributor

@TomaszTB TomaszTB commented Nov 7, 2024

Added abstract ImageSensor + new NadiaPerceptionAutonomyProcess which can be used with real or simulated sensors.

* @param newPixelFormat the PixelFormat of the new image.
* @return A new {@link RawImage} with the same intrinsics & metadata, but with a different image.
*/
public RawImage replaceImage(Mat newCpuImageMat, PixelFormat newPixelFormat)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized this was missing

@@ -222,22 +246,12 @@ public Instant getAcquisitionTime()

public int getWidth()
{
if (hasCpuImage())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks became unnecessary when CameraIntrinsics were added

* @param depthImage 16UC1 depth image, used to get points of detected objects
*/
public void runYOLODetection(YOLOv8ObjectDetector yoloDetector, RawImage colorImage, RawImage depthImage)
{
if (yoloDetector.isReady() && !yoloExecutorService.isShutdown())
{
// Acquire the images
if (colorImage.get() == null || depthImage.get() == null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved calls to get here so it guarantees you "get" the images before they're deallocated.

if (yoloDetectionResults.containsKey(lastRunDetectorIndex))
yoloDetectionResults.remove(lastRunDetectorIndex).destroy();
yoloDetectionResults.put(lastRunDetectorIndex, yoloResults);
synchronized (yoloDetectionResults)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the detection results may have been getting deallocated while the annotated image thread was using them, so I put think synchronized block for now.

Really, this class needs an overhaul.

@@ -23,7 +23,7 @@ public class YOLOv8DetectionResults
private final MatVector outputBlobs;
private final RawImage detectionImage;
private final FloatIndexer outputMasksIndexer;
private final Map<YOLOv8DetectionOutput, Mat> objectMasks = new HashMap<>();
private final Map<YOLOv8DetectionOutput, RawImage> objectMasks = new HashMap<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using RawImage instead of Mat just to be extra safe about memory allocation/deallocation here

@@ -127,19 +127,22 @@ public boolean encodeNextFrame(Consumer<AVPacket> packetConsumer)
return error != AVERROR_EOF();
}

public boolean flush(Consumer<AVPacket> packetConsumer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we should be flushing out the encoders once all the frames are sent (a few packets might've stayed in the encoder, waiting to be grouped together)

@@ -139,6 +136,10 @@ private String getDeviceInfo(rs2_device rs2Device, int deviceInfoEnum)

private int updateDeviceCount()
{
realsense2.rs2_delete_device_list(devices);
devices = realsense2.rs2_query_devices(context, error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this is correct (performing another query when we want to update the device count). Seems to have solved an issue I was having

import java.time.Instant;
import java.util.function.Supplier;

public class RealsenseImageSensor extends ImageSensor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tempted to name it RealSenseImageSensor to be consistent with the brand name

@TomaszTB TomaszTB requested review from ds58 and calvertdw November 7, 2024 18:56
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch 2 times, most recently from 79a1355 to 188efc7 Compare November 19, 2024 17:51
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch from 188efc7 to 0f4c80a Compare November 22, 2024 16:07
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch 3 times, most recently from 4eb90b2 to 061aaba Compare December 4, 2024 18:13
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch from 061aaba to 3d898b3 Compare December 16, 2024 16:13
@TomaszTB TomaszTB marked this pull request as ready for review December 16, 2024 17:58
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch from 3d898b3 to 3bdc53b Compare December 18, 2024 15:25
@TomaszTB TomaszTB merged commit fa4de94 into develop Dec 18, 2024
67 of 69 checks passed
@TomaszTB TomaszTB deleted the feature/perception-autonomy-cleanup-2 branch December 18, 2024 16:21
rjgriffin42 pushed a commit that referenced this pull request Jan 8, 2025
* Added basic Perception Autonomy Process with ZED

* WIP - added ImageSensor + YOLO

* Added RealsenseImageSensor

* Reset ROS2DemandGraphNode to develop

* Created ImageSensorPublishThread

* Minor ImageSensor cleanup

* Use PausableLoopingThread, add YOLO

* Cleanup

* Correct YOLO input to BGR

* Add scene graph update thread, fix YOLO null pointer issue

* WIP - Adding planar regions

* WIP - adding ZEDSVOPlayback

* Fixes

* Improve planar regions extraction

* Working planar regions

* Added ArUco detection thread

* Added ArUco to SceneGraph update

* Added Height Map

* Added ICP

* Added Behavior Tree Update Thread

* Cleanup

* Remove old perception autonomy process

* Allow specifying ZED input type

* Polishing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants