Skip to content

Commit

Permalink
Merge pull request #272 from stereolabs/dev-4.0.7
Browse files Browse the repository at this point in the history
Update to 4.0.7
  • Loading branch information
SLJLMacarit committed Sep 25, 2023
2 parents 264d44b + df50ce9 commit 9b50fb8
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 24 deletions.
10 changes: 10 additions & 0 deletions ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public class ZEDCameraEditor : Editor
SerializedProperty openTimeoutSecProperty;
SerializedProperty asyncGrabCameraRecoveryProperty;
SerializedProperty grabComputeCappingFPSProperty;
SerializedProperty enableImageValidityCheckProperty;

// Rendering Prop
private int arlayer;
Expand Down Expand Up @@ -364,6 +365,7 @@ private void OnEnable()
openTimeoutSecProperty = serializedObject.FindProperty("openTimeoutSec");
asyncGrabCameraRecoveryProperty = serializedObject.FindProperty("asyncGrabCameraRecovery");
grabComputeCappingFPSProperty = serializedObject.FindProperty("grabComputeCappingFPS");
enableImageValidityCheckProperty = serializedObject.FindProperty("enableImageValidityCheck");

//Video Settings Serialized Properties
videoSettingsInitModeProperty = serializedObject.FindProperty("videoSettingsInitMode");
Expand Down Expand Up @@ -1242,10 +1244,18 @@ public override void OnInspectorGUI()
"Default is 0, which means that the setting is not used.");
grabComputeCappingFPSProperty.floatValue = EditorGUILayout.FloatField(grabComputeCappingFPSLabel, grabComputeCappingFPSProperty.floatValue);

GUIContent enableImageValidityCheckLabel = new GUIContent("Enable Image Validity Check", "Enable or disable the image validity verification." +
"\nThis will perform additional verification on the image to identify corrupted data. This verification is done in the grab function and requires some computations." +
"\nIf an issue is found, the grab function will output a warning as sl::ERROR_CODE::CORRUPTED_FRAME." +
"This version currently doesn't detect frame tearing." +
"\nDefault: disabled");
enableImageValidityCheckProperty.boolValue = EditorGUILayout.Toggle(enableImageValidityCheckLabel, enableImageValidityCheckProperty.boolValue);

GUILayout.Space(12);

EditorGUI.indentLevel--;


EditorGUILayout.LabelField("AR Passthrough Settings", EditorStyles.boldLabel);
GUILayout.Space(5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class HeightOffsetter : MonoBehaviour

[Header("Main settings")]

ZEDBodyTrackingManager bodyTrackingManager;
public ZEDBodyTrackingManager bodyTrackingManager;

[SerializeField]
private float currentAutoHeightOffset = 0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ public const int

private GameObject humanoid;
public ZEDSkeletonAnimator zedSkeletonAnimator = null;
public ZEDBodyTrackingManager zedBodyTrackingManager = null;
private Animator animator;
private Dictionary<HumanBodyBones, RigBone> rigBone = null;
private Dictionary<HumanBodyBones, Quaternion> rigBoneTarget = null;
Expand Down Expand Up @@ -529,7 +530,7 @@ public Animator GetAnimator()
/// </summary>
/// <param name="h">The humanoid GameObject prefab.</param>
/// <param name="body_format">The Body model to apply (34 or 38 bones).</param>
public void Create(GameObject h, sl.BODY_FORMAT body_format)
public void Create(GameObject h, sl.BODY_FORMAT body_format, ZEDBodyTrackingManager btmanager)
{
humanoid = (GameObject)Instantiate(h, Vector3.zero, Quaternion.identity);
animator = humanoid.GetComponent<Animator>();
Expand All @@ -538,6 +539,7 @@ public void Create(GameObject h, sl.BODY_FORMAT body_format)

zedSkeletonAnimator = humanoid.GetComponent<ZEDSkeletonAnimator>();
zedSkeletonAnimator.Skhandler = this;
zedSkeletonAnimator.BodyTrackingManager = btmanager;

// Init list of bones that will be updated by the data retrieved from the ZED SDK
rigBone = new Dictionary<HumanBodyBones, RigBone>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void OnDestroy()
IEnumerator InstanciateAvatarWithDelay(float delay, DetectedBody dbody)
{
SkeletonHandler handler = ScriptableObject.CreateInstance<SkeletonHandler>();
handler.Create(avatar, bodyFormat);
handler.Create(avatar, bodyFormat, this);
handler.InitSkeleton(dbody.rawBodyData.id, new Material(skeletonBaseMaterial));

avatarControlList.Add(dbody.rawBodyData.id, handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,13 @@ public void TryShowAvatar(bool newVisibility)

private void Awake()
{
bodyTrackingManager = FindObjectOfType<ZEDBodyTrackingManager>();
if (bodyTrackingManager == null)
{
Debug.LogError("ZEDManagerIK: No body tracking manager loaded!");
}
heightOffsetter = GetComponent<HeightOffsetter>();
}

void Start()
{
animator = GetComponent<Animator>();
heightOffsetter.bodyTrackingManager = bodyTrackingManager;
}

private void Update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public Camera renderingCam
/// </summary>
Texture2D depth;

public Texture2D Depth { get { return depth; } }

/// <summary>
/// Normals generated by the ZEDCamera.
/// Once created, the ZED SDK automatically updates it whenever the ZED captures new frames/images.
Expand Down
32 changes: 24 additions & 8 deletions ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/ZEDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public static List<ZEDManager> GetInstances()
[HideInInspector]
public float grabComputeCappingFPS = 0f;

/// <summary>
/// Define a computation upper limit to the grab frequency. 0 means setting is ignored.
/// This can be useful to get a known constant fixed rate or limit the computation load while keeping a short exposure time by setting a high camera capture framerate.
/// The value should be inferior to the InitParameters::camera_fps and strictly positive.It has no effect when reading an SVO file.
/// This is an upper limit and won't make a difference if the computation is slower than the desired compute capping fps.
/// Internally the grab function always tries to get the latest available image while respecting the desired fps as much as possible.
/// default is 0.
/// </summary>
[HideInInspector]
public bool enableImageValidityCheck = false;

/// <summary>
/// SVO loop back option
/// </summary>
Expand Down Expand Up @@ -2068,6 +2079,7 @@ void Awake()
initParameters.openTimeoutSec = openTimeoutSec;
initParameters.asyncGrabCameraRecovery = asyncGrabCameraRecovery;
initParameters.grabComputeCappingFPS = grabComputeCappingFPS;
initParameters.enableImageValidityCheck = enableImageValidityCheck;

//Check if this rig is a stereo rig. Will set isStereoRig accordingly.
CheckStereoMode();
Expand Down Expand Up @@ -2186,7 +2198,6 @@ private void OpenZEDInBackground()
{
initQuittingHandle.WaitOne(0); //Makes sure we haven't been turned off early, which only happens in Destroy() from OnApplicationQuit().
if (forceCloseInit) break;

lastInitStatus = zedCamera.Open(ref initParameters);
timeout++;
numberTriesOpening++;
Expand Down Expand Up @@ -3562,17 +3573,12 @@ void CreateMirror()
}
#endregion

/// <summary>
/// Closes out the current stream, then starts it up again while maintaining tracking data.
/// Used when the zed becomes unplugged, or you want to change a setting at runtime that
/// requires re-initializing the camera.
/// </summary>
public void Reset()
public void Close()
{
//Save tracking
if (enableTracking && isTrackingEnable)
{
zedCamera.GetPosition(ref zedOrientation, ref zedPosition);
if (zedCamera != null) zedCamera.GetPosition(ref zedOrientation, ref zedPosition);
}

CloseManager();
Expand All @@ -3581,6 +3587,16 @@ public void Reset()
running = false;
numberTriesOpening = 0;
forceCloseInit = false;
}

/// <summary>
/// Closes out the current stream, then starts it up again while maintaining tracking data.
/// Used when the zed becomes unplugged, or you want to change a setting at runtime that
/// requires re-initializing the camera.
/// </summary>
public void Reset()
{
Close();

Awake();
}
Expand Down
53 changes: 45 additions & 8 deletions ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public int TagInvisibleToZED
/// <summary>
/// Current Plugin Version.
/// </summary>
public static readonly System.Version PluginVersion = new System.Version(4, 0, 6);
public static readonly System.Version PluginVersion = new System.Version(4, 0, 7);

/******** DLL members ***********/
[DllImport(nameDll, EntryPoint = "GetRenderEventFunc")]
Expand Down Expand Up @@ -413,6 +413,9 @@ public int TagInvisibleToZED
* Camera control functions.
*/

[DllImport(nameDll, EntryPoint = "sl_is_camera_setting_supported")]
private static extern bool dllz_is_video_setting_supported(int id, int setting);

[DllImport(nameDll, EntryPoint = "sl_set_video_settings")]
private static extern void dllz_set_video_settings(int id, int mode, int value);

Expand Down Expand Up @@ -499,16 +502,18 @@ public int TagInvisibleToZED
[DllImport(nameDll, EntryPoint = "sl_get_svo_position")]
private static extern int dllz_get_svo_position(int cameraID);

[DllImport(nameDll, EntryPoint = "sl_get_svo_position_at_timestamp")]
private static extern int dllz_get_svo_position_at_timestamp(int cameraID, ulong timestamp);

/*
* Depth Sensing utils functions.
*/
/* Removed as of ZED SDK v3.0.
[DllImport(nameDll, EntryPoint = "set_confidence_threshold")]
private static extern void dllz_set_confidence_threshold(int cameraID, int threshold);
[DllImport(nameDll, EntryPoint = "set_depth_max_range_value")]
private static extern void dllz_set_depth_max_range_value(int cameraID, float distanceMax);
*/
/* Removed as of ZED SDK v3.0.
[DllImport(nameDll, EntryPoint = "set_confidence_threshold")]
private static extern void dllz_set_confidence_threshold(int cameraID, int threshold);
[DllImport(nameDll, EntryPoint = "set_depth_max_range_value")]
private static extern void dllz_set_depth_max_range_value(int cameraID, float distanceMax);
*/

[DllImport(nameDll, EntryPoint = "sl_get_confidence_threshold")]
private static extern int dllz_get_confidence_threshold(int cameraID);
Expand Down Expand Up @@ -1083,6 +1088,16 @@ public struct dll_initParameters
/// </summary>
public float grabComputeCappingFPS;

/// <summary>
/// Enable or disable the image validity verification.
/// This will perform additional verification on the image to identify corrupted data. This verification is done in the grab function and requires some computations.
/// If an issue is found, the grab function will output a warning as sl::ERROR_CODE::CORRUPTED_FRAME.
/// This version doesn't detect frame tearing currently.
/// \n default: disabled
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public bool enableImageValidityCheck;

/// <summary>
/// Copy constructor. Takes values from Unity-suited InitParameters class.
/// </summary>
Expand Down Expand Up @@ -1110,6 +1125,7 @@ public dll_initParameters(InitParameters init)
openTimeoutSec = init.openTimeoutSec;
asyncGrabRecovery = init.asyncGrabCameraRecovery;
grabComputeCappingFPS = init.grabComputeCappingFPS;
enableImageValidityCheck = init.enableImageValidityCheck;
}
}

Expand All @@ -1130,7 +1146,8 @@ public ERROR_CODE Open(ref InitParameters initParameters)
initParameters.cameraFPS = (int)fpsMax;
}
dll_initParameters initP = new dll_initParameters(initParameters); //DLL-friendly version of InitParameters.
initP.coordinateSystem = COORDINATE_SYSTEM.LEFT_HANDED_Y_UP; //Left-hand, Y-up is Unity's coordinate system, so we match that.
initP.coordinateSystem = COORDINATE_SYSTEM.LEFT_HANDED_Y_UP; //Left-hand, Y-up is Unity's coordinate system, so we match that

int v = dllz_open(CameraID, ref initP, initParameters.serialNumber,
new System.Text.StringBuilder(initParameters.pathSVO, initParameters.pathSVO.Length),
new System.Text.StringBuilder(initParameters.ipStream, initParameters.ipStream.Length),
Expand Down Expand Up @@ -1322,6 +1339,16 @@ public int GetSVOPosition()
return dllz_get_svo_position(CameraID);
}

/// <summary>
/// Retrieves the frame index within the SVO file corresponding to the provided timestamp.
/// </summary>
/// <param name="timestamp">The target timestamp for which the frame index is to be determined.</param>
/// <returns>The frame index within the SVO file that aligns with the given timestamp. Returns -1 if the timestamp falls outside the bounds of the SVO file.</returns>
public int GetSVOPositionAtTimestamp(ulong timestamp)
{
return dllz_get_svo_position_at_timestamp(CameraID, timestamp);
}

/// <summary>
/// Gets the total number of frames in the loaded SVO file.
/// </summary>
Expand Down Expand Up @@ -1981,6 +2008,16 @@ static public void Float2Matrix(ref Matrix4x4 m, float[] f)
}
}

/// <summary>
/// Test if the video setting is supported by the camera
/// setting : The video setting to test
/// true if the \ref SL_VIDEO_SETTINGS is supported by the camera, false otherwise
/// </summary>
public bool IsCameraSettingSupported(CAMERA_SETTINGS setting)
{
return dllz_is_video_setting_supported(CameraID, (int)setting);
}

/// <summary>
/// Sets a value in the ZED's camera settings.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,13 @@ public enum VIEW_MODE
/// </remarks>
public enum ERROR_CODE
{
/// <summary>
/// The image could be corrupted, Enabled with the parameter InitParameters::enableImageValidityCheck.
/// </summary>
CORRUPTED_FRAME = -2,
/// <summary>
/// The camera is currently rebooting.
/// </summary>
CAMERA_REBOOTING = -1,
/// <summary>
/// Operation was successful.
Expand Down Expand Up @@ -1131,6 +1138,7 @@ public enum VIEW

/// <summary>
/// Lists available camera settings for the ZED camera (contrast, hue, saturation, gain, etc.)
/// The settings specific for GMSL cameras are currently not supported.
/// </summary>
public enum CAMERA_SETTINGS
{
Expand Down Expand Up @@ -1364,6 +1372,25 @@ public enum POSTIONAL_TRACKING_MODE
QUALITY
}

/// <summary>
/// Lists the mode of positional tracking that can be used.
/// </summary>
public enum REGION_OF_INTEREST_AUTO_DETECTION_STATE
{
/// <summary>
/// The region of interest auto detection is initializing.
/// </summary>
RUNNING,
/// <summary>
/// The region of interest mask is ready, if auto_apply was enabled, the region of interest mask is being used.
/// </summary>
READY,
/// <summary>
/// The region of interest auto detection is not enabled.
/// </summary>
ENABLED,
}

/// <summary>
/// SVO compression modes.
/// </summary>
Expand Down Expand Up @@ -1660,6 +1687,15 @@ public class InitParameters
/// </summary>
public float grabComputeCappingFPS = 0f;

/// <summary>
/// Enable or disable the image validity verification.
/// This will perform additional verification on the image to identify corrupted data. This verification is done in the grab function and requires some computations.
/// If an issue is found, the grab function will output a warning as sl::ERROR_CODE::CORRUPTED_FRAME.
/// This version doesn't detect frame tearing currently.
/// \n default: disabled
/// </summary>
public bool enableImageValidityCheck = false;

/// <summary>
/// Constructor. Sets default initialization parameters recommended for Unity.
/// </summary>
Expand Down Expand Up @@ -1693,6 +1729,7 @@ public InitParameters()
this.openTimeoutSec = 5.0f;
this.asyncGrabCameraRecovery = false;
this.grabComputeCappingFPS = 0f;
this.enableImageValidityCheck = false;
}
}

Expand Down
Binary file modified ZEDCamera/Assets/ZED/SDK/Plugins/linux/libsl_unitywrapper.so
Binary file not shown.
Binary file modified ZEDCamera/Assets/ZED/SDK/Plugins/win64/sl_unitywrapper.dll
Binary file not shown.

0 comments on commit 9b50fb8

Please sign in to comment.