Skip to content

Commit

Permalink
fix memory leak, remove obselete parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bvallon-sl committed Jul 11, 2024
1 parent e73facd commit d142e4a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 44 deletions.
4 changes: 0 additions & 4 deletions ZEDCamera/Assets/Editor/Scripts/ZEDCameraEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public class ZEDCameraEditor : Editor
private SerializedProperty meshPath;

//Object Detection Prop
//private SerializedProperty OD_ImageSyncMode;
private SerializedProperty OD_ObjectTracking;
private SerializedProperty OD_2DMask;
private SerializedProperty OD_DetectionModel;
Expand All @@ -134,7 +133,6 @@ public class ZEDCameraEditor : Editor
private SerializedProperty OD_FruitVegetableFilter;
private SerializedProperty OD_SportFilter;
//Body Tracking
private SerializedProperty BT_ImageSyncMode;
private SerializedProperty BT_ObjectTracking;
private SerializedProperty BT_2DMask;
private SerializedProperty BT_DetectionModel;
Expand Down Expand Up @@ -283,7 +281,6 @@ private void OnEnable()
meshPath = serializedObject.FindProperty("meshPath");

///Object Detection Serialized Properties
//OD_ImageSyncMode = serializedObject.FindProperty("objectDetectionImageSyncMode");
OD_ObjectTracking = serializedObject.FindProperty("objectDetectionTracking");

OD_2DMask = serializedObject.FindProperty("objectDetection2DMask");
Expand Down Expand Up @@ -311,7 +308,6 @@ private void OnEnable()

// Body tracking serialied properties

BT_ImageSyncMode = serializedObject.FindProperty("bodyTrackingImageSyncMode");
BT_ObjectTracking = serializedObject.FindProperty("bodyTrackingTracking");
BT_2DMask = serializedObject.FindProperty("bodyTracking2DMask");
BT_DetectionModel = serializedObject.FindProperty("bodyTrackingModel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ public bool GetMaskTexture(out Texture2D masktex, bool fliponYaxis)
if (maskTexture == null)
{
IntPtr maskpointer = maskMat.GetPtr(sl.ZEDMat.MEM.MEM_CPU);
if (maskpointer != IntPtr.Zero)

if (maskpointer != IntPtr.Zero && maskMat.IsInit())
{
maskTexture = ZEDMatToTexture_CPU(maskMat, false);
}
Expand Down
27 changes: 2 additions & 25 deletions ZEDCamera/Assets/SDK/Helpers/Scripts/ZEDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,6 @@ public enum shaderType
[HideInInspector]
public uint objectDetectionInstanceID = 0;

/// <summary>
/// Sync the Object on the image.
/// </summary>
[HideInInspector]
public bool objectDetectionImageSyncMode = true;

/// <summary>
/// Whether to track objects across multiple frames using the ZED's position relative to the floor.
/// Requires tracking to be on. It's also recommended to enable Estimate Initial Position to find the floor.
Expand Down Expand Up @@ -654,12 +648,6 @@ public enum shaderType
[HideInInspector]
public uint bodyTrackingInstanceID = 1;

/// <summary>
/// Sync the Object on the image.
/// </summary>
[HideInInspector]
public bool bodyTrackingImageSyncMode = true;

/// <summary>
/// Whether to track objects across multiple frames using the ZED's position relative to the floor.
/// Requires tracking to be on. It's also recommended to enable Estimate Initial Position to find the floor.
Expand Down Expand Up @@ -2546,8 +2534,7 @@ private void AcquireImages()
float camera_fps = zedCamera.GetCameraFPS();
cameraFPS = camera_fps.ToString() + " FPS";
#endif
//Update object detection here if using object sync.
if (objectDetectionRunning && objectDetectionImageSyncMode && requestobjectsframe)
if (objectDetectionRunning && requestobjectsframe)
{
if (objectDetectionModel == sl.OBJECT_DETECTION_MODEL.CUSTOM_BOX_OBJECTS)
{
Expand All @@ -2557,8 +2544,7 @@ private void AcquireImages()
RetrieveObjectDetectionFrame();
}

//Update body tracking here if using object sync.
if (bodyTrackingRunning && bodyTrackingImageSyncMode && requestBodiesframe)
if (bodyTrackingRunning && requestBodiesframe)
{
RetrieveBodyTrackingFrame();
}
Expand Down Expand Up @@ -3124,10 +3110,8 @@ private IEnumerator startObjectDetection()
odIsStarting = true;
Debug.LogWarning("Starting Object Detection. This may take a moment.");

objectDetectionImageSyncMode = true;
sl.ObjectDetectionParameters od_param = new sl.ObjectDetectionParameters();
od_param.instanceModuleID = objectDetectionInstanceID;
od_param.imageSync = objectDetectionImageSyncMode;
od_param.enableTracking = objectDetectionTracking;
od_param.enableSegmentation = objectDetection2DMask;
od_param.detectionModel = objectDetectionModel;
Expand Down Expand Up @@ -3213,10 +3197,6 @@ public void UpdateObjectDetection()
objectDetectionRuntimeParameters.objectClassFilter[(int)sl.OBJECT_CLASS.FRUIT_VEGETABLE] = Convert.ToInt32(objectClassFruitVegetableFilter);
objectDetectionRuntimeParameters.objectClassFilter[(int)sl.OBJECT_CLASS.SPORT] = Convert.ToInt32(objectClassSportFilter);



if (objectDetectionImageSyncMode == false) RetrieveObjectDetectionFrame(); //If true, this is called in the AcquireImages function in the image acquisition thread.

if (newobjectsframeready)
{
lock (zedCamera.grabLock)
Expand Down Expand Up @@ -3368,7 +3348,6 @@ private IEnumerator startBodyTracking()

sl.BodyTrackingParameters bt_param = new sl.BodyTrackingParameters();
bt_param.instanceModuleID = bodyTrackingInstanceID;
bt_param.imageSync = bodyTrackingImageSyncMode;
bt_param.enableTracking = bodyTrackingTracking;
bt_param.enableSegmentation = bodyTracking2DMask;
bt_param.detectionModel = bodyTrackingModel;
Expand Down Expand Up @@ -3426,8 +3405,6 @@ public void UpdateBodiesTracking()
bodyTrackingRuntimeParams.minimumKeypointsThreshold = bodyTrackingMinimumKPThreshold;
bodyTrackingRuntimeParams.skeletonSmoothing = bodyTrackingSkeletonSmoothing;

if (bodyTrackingImageSyncMode == false) RetrieveBodyTrackingFrame(); //If true, this is called in the AcquireImages function in the image acquisition thread.

if (newbodiesframeready)
{
lock (zedCamera.grabLock)
Expand Down
10 changes: 0 additions & 10 deletions ZEDCamera/Assets/SDK/NativeInterface/ZEDCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2165,11 +2165,6 @@ public struct ObjectDetectionParameters
/// </summary>
public uint instanceModuleID;
/// <summary>
/// Defines if the object detection is synchronized to the image or runs in a separate thread.
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool imageSync;
/// <summary>
/// Defines if the object detection will track objects across multiple images, instead of an image-by-image basis.
/// </summary>
[MarshalAs(UnmanagedType.U1)]
Expand Down Expand Up @@ -2461,11 +2456,6 @@ public struct BodyTrackingParameters
/// </summary>
public uint instanceModuleID;
/// <summary>
/// Defines if the object detection is synchronized to the image or runs in a separate thread.
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool imageSync;
/// <summary>
/// Defines if the object detection will track objects across multiple images, instead of an image-by-image basis.
/// </summary>
[MarshalAs(UnmanagedType.U1)]
Expand Down
Binary file modified ZEDCamera/Assets/SDK/Plugins/win64/sl_unitywrapper.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ public void Visualize2DBoundingBoxes(ObjectDetectionFrame dframe)
bbox.sizeDelta = new Vector2(objrect.width, objrect.height);
bbox.anchoredPosition = new Vector2(objrect.x, objrect.y);


bool ShowMaskIsEnabled = detectionMode == DetectionMode.BodyTracking ? zedManager.bodyTracking2DMask : zedManager.objectDetection2DMask;
//Apply the mask.
if (showObjectMask)
if (showObjectMask && ShowMaskIsEnabled)
{
//Make a new image for this new mask.
Texture2D maskimage;
Expand Down Expand Up @@ -310,9 +310,11 @@ public void Visualize2DBoundingBoxes(BodyTrackingFrame dframe)
//Adjust the size of the RectTransform to encompass the object.
bbox.sizeDelta = new Vector2(objrect.width, objrect.height);
bbox.anchoredPosition = new Vector2(objrect.x, objrect.y);


bool ShowMaskIsEnabled = detectionMode == DetectionMode.BodyTracking ? zedManager.bodyTracking2DMask : zedManager.objectDetection2DMask;

//Apply the mask.
if (showObjectMask)
if (showObjectMask && ShowMaskIsEnabled)
{
//Make a new image for this new mask.
Texture2D maskimage;
Expand Down

0 comments on commit d142e4a

Please sign in to comment.