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

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from

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.
Requires #439 to be merged first.

* @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 2 times, most recently from b2763e2 to 4eb90b2 Compare December 4, 2024 16:08
@TomaszTB TomaszTB force-pushed the feature/perception-autonomy-cleanup-2 branch from 4eb90b2 to 061aaba Compare December 4, 2024 18:13
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.

1 participant