Skip to content

Commit

Permalink
Merge pull request #37 from stereolabs/v4.1
Browse files Browse the repository at this point in the history
Update to SDK 4.1
  • Loading branch information
SLJLMacarit authored Apr 4, 2024
2 parents e5fa2e1 + da92944 commit 15fdfcc
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 134 deletions.
Binary file modified Content/ZED/Levels/L_PointCloud.umap
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void USlCameraProxy::Internal_OpenCamera(const FSlInitParameters& InitParameters
sl_init_parameters.camera_disable_self_calib = InitParameters.bDisableSelfCalibration;
sl_init_parameters.camera_fps = InitParameters.FPS;
sl_init_parameters.camera_image_flip = (SL_FLIP_MODE)InitParameters.VerticalFlipImage;
sl_init_parameters.resolution = (SL_RESOLUTION)InitParameters.Resolution;
sl_init_parameters.resolution = sl::unreal::ToSlType2(InitParameters.Resolution);
sl_init_parameters.coordinate_system = SL_COORDINATE_SYSTEM_LEFT_HANDED_Z_UP;
sl_init_parameters.coordinate_unit = SL_UNIT_CENTIMETER;
sl_init_parameters.depth_minimum_distance = InitParameters.DepthMinimumDistance;
Expand Down Expand Up @@ -570,25 +570,47 @@ ESlTrackingState USlCameraProxy::GetPosition(FSlPose& Pose, ESlReferenceFrame Re
SL_SCOPE_UNLOCK
}

ESlErrorCode USlCameraProxy::SetRegionOfInterest(FSlMat& Mat)
ESlErrorCode USlCameraProxy::SetRegionOfInterest(FSlMat& Mat, TSet<ESlModule> module)
{
SL_ERROR_CODE err = (SL_ERROR_CODE)sl_set_region_of_interest(CameraID, Mat.Mat);
TArray<bool> modules_array;
modules_array.Init(false, SL_MODULE_LAST);

for (int i = 0; i < SL_MODULE_ALL; i++)
{
if (module.Contains((ESlModule)i))
{
modules_array[i] = true;
}
}

SL_ERROR_CODE err = (SL_ERROR_CODE)sl_set_region_of_interest(CameraID, Mat.Mat, modules_array.GetData());
return sl::unreal::ToUnrealType(err);
}

ESlErrorCode USlCameraProxy::GetRegionOfInterest(FSlMat& Mat, FIntPoint& resolution)
ESlErrorCode USlCameraProxy::GetRegionOfInterest(FSlMat& Mat, FIntPoint& resolution, ESlModule module)
{
if (!Mat.Mat) {
Mat.Mat = sl_mat_create_new(resolution.X, resolution.Y, SL_MAT_TYPE_U8_C1, SL_MEM_CPU);
}
SL_ERROR_CODE err = (SL_ERROR_CODE)sl_get_region_of_interest(CameraID, Mat.Mat, resolution.X, resolution.Y);
SL_ERROR_CODE err = (SL_ERROR_CODE)sl_get_region_of_interest(CameraID, Mat.Mat, resolution.X, resolution.Y, (SL_MODULE)module);
return sl::unreal::ToUnrealType(err);
}

ESlErrorCode USlCameraProxy::StartRegionOfInterestAutoDetection(FSlRegionOfInterestParameters& roiParams)
{
SL_RegionOfInterestParameters params;
params.auto_apply = roiParams.bAutoApply;

TArray<bool> modules_array;
modules_array.Init(false, SL_MODULE_LAST);

for (int i = 0; i < SL_MODULE_ALL; i++)
{
if (roiParams.autoApplyModule.Contains((ESlModule)i))
{
params.auto_apply_module[i] = true;
}
}

params.depth_far_threshold_meters = roiParams.depthFarThresholdMeters;
params.image_height_ratio_cutoff = roiParams.imageHeightRatioCutoff;

Expand Down Expand Up @@ -726,6 +748,11 @@ SL_POSITIONAL_TRACKING_STATE USlCameraProxy::GetCameraPosition(SL_PoseData* pose
return SL_POSITIONAL_TRACKING_STATE_OFF;
}

SL_PositionalTrackingStatus* USlCameraProxy::GetPositionalTrackingStatus()
{
return sl_get_positional_tracking_status(CameraID);
}

SL_ERROR_CODE USlCameraProxy::GetCameraIMURotationAtImage(sl::Rotation& pose)
{
if (sl_is_opened(CameraID)) {
Expand Down Expand Up @@ -1760,6 +1787,63 @@ void USlCameraProxy::DisableSVORecording()
SL_SCOPE_UNLOCK
}

int USlCameraProxy::IngestDataIntoSVO(const FSlSVOData& svoData)
{
SL_ERROR_CODE err;
SL_SCOPE_LOCK(Lock, GrabSection)
auto SvoData = sl::unreal::ToSlType(svoData);
err = sl_ingest_data_into_svo(CameraID, &SvoData);
SL_SCOPE_UNLOCK

if (err != SL_ERROR_CODE::SL_ERROR_CODE_SUCCESS) {
SL_CAMERA_PROXY_LOG_E("IngestDataIntoSVO: Error:\"%s\"", *EnumToString(sl::unreal::ToUnrealType(err)));
}

return (int)err;
}

int USlCameraProxy::RetrieveSVOData(const FString& key, TArray<FSlSVOData>& resSVOData, FString ts_nano_begin, FString ts_nano_end)
{
SL_ERROR_CODE err = SL_ERROR_CODE_FAILURE;
uint64 tsb = FCString::Strtoui64(*ts_nano_begin, NULL, 10);
uint64 tse = FCString::Strtoui64(*ts_nano_end, NULL, 10);
auto ckey = std::make_unique<char[]>(128);

strcpy(ckey.get(), TCHAR_TO_ANSI(*key));

resSVOData.Empty();

SL_SCOPE_LOCK(Lock, GrabSection)
int nb_data = sl_get_svo_data_size(CameraID, ckey.get(), tsb, tse);
if (nb_data > 0) {
auto cdata = std::make_unique<SL_SVOData[]>(nb_data);
err = sl_retrieve_svo_data(CameraID, ckey.get(), nb_data, cdata.get(), tsb, tse);
for (int i = 0; i < nb_data; ++i) {
resSVOData.Add(sl::unreal::ToUnrealType(cdata[i]));
}
}
SL_SCOPE_UNLOCK

return (int)err;
}

TArray<FString> USlCameraProxy::GetSVODataKeys()
{
TArray<FString> res;

SL_SCOPE_LOCK(Lock, GrabSection)
int nbkeys = sl_get_svo_data_keys_size(CameraID);
auto cdata = std::make_unique<char*[]>(nbkeys);
sl_get_svo_data_keys(CameraID, nbkeys, cdata.get());
for (int i = 0; i < nbkeys; ++i) {
res.Add(FString(cdata[i]));
}
SL_SCOPE_UNLOCK

return res;
}


void USlCameraProxy::SetSVOPlaybackPosition(int Position)
{
SL_SCOPE_LOCK(Lock, GrabSection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ enum class ESlDepthMode : uint8
DM_None UMETA(DisplayName = "None"),
DM_Performance UMETA(DisplayName = "Performance"),
DM_Quality UMETA(DisplayName = "Quality"),
//DM_NeuralFast UMETA(DisplayName = "NeuralFast"),
DM_Ultra UMETA(DisplayName = "Ultra"),
DM_Neural UMETA(DisplayName = "Neural")
DM_Neural UMETA(DisplayName = "Neural"),
DM_NeuralPlus UMETA(DisplayName = "Neural+")
};

/*
Expand Down Expand Up @@ -544,6 +544,20 @@ enum class ESlPositionalTrackingMode : uint8
PTM_Quality UMETA(DisplayName = "Quality")
};

/*
* Lists available modules.
*/
UENUM(BlueprintType, Category = "Stereolabs|Enum")
enum class ESlModule : uint8
{
M_All UMETA(DisplayName = "All"),
M_Depth UMETA(DisplayName = "Depth"),
M_PositionalTracking UMETA(DisplayName = "Positional Tracking"),
M_ObjectDetection UMETA(DisplayName = "Object Detection"),
M_BodyTracking UMETA(DisplayName = "Body Tracking"),
M_SpatialMapping UMETA(DisplayName = "Spatial Mapping")
};

/**
\brief Lists the different states of region of interest auto detection.
*/
Expand Down Expand Up @@ -623,13 +637,11 @@ enum class ESlAIModels : uint8
AIM_HumanBody38FastDetection UMETA(DisplayName = "Human body 38 fast Detection"),
AIM_HumanBody38MediumDetection UMETA(DisplayName = "Human body 38 medium Detection"),
AIM_HumanBody38AccurateDetection UMETA(DisplayName = "Human body 38 accurate Detection"),
//AIM_HumanBody70FastDetection UMETA(DisplayName = "Human body 70 fast Detection"),
//AIM_HumanBody70MediumDetection UMETA(DisplayName = "Human body 70 medium Detection"),
//AIM_HumanBody70AccurateDetection UMETA(DisplayName = "Human body 70 accurate Detection"),
AIM_PersonHeadFastDetection UMETA(DisplayName = "Person head fast Detection"),
AIM_PersonHeadAccurateDetection UMETA(DisplayName = "Person head accurate Detection"),
AIM_REIDAssociation UMETA(DisplayName = "REID Association"),
AIM_NeuralDepth UMETA(DisplayName = "Neural Depth"),
AIM_NeuralPlusDepth UMETA(DisplayName = "Neural Plus Depth")
};

/*
Expand All @@ -640,8 +652,7 @@ enum class ESlBodyFormat : uint8
{
BF_BODY_18 UMETA(DisplayName = "Body 18"),
BF_BODY_34 UMETA(DisplayName = "Body 34"),
BF_BODY_38 UMETA(DisplayName = "Body 38"),
// BF_BODY_70 UMETA(DisplayName = "Body 70")
BF_BODY_38 UMETA(DisplayName = "Body 38")
};

/*
Expand All @@ -651,8 +662,7 @@ UENUM(BlueprintType, Category = "Stereolabs|Enum")
enum class ESlBodyKeypointsSelection : uint8
{
BKS_FULL UMETA(DisplayName = "Full"),
BKS_UPPER_BODY UMETA(DisplayName = "Upper body"),
//BKS_HAND UMETA(DisplayName = "Hand"),
BKS_UPPER_BODY UMETA(DisplayName = "Upper body")
};

/*
Expand Down Expand Up @@ -1775,7 +1785,7 @@ struct STEREOLABS_API FSlRuntimeParameters
:
bEnableDepth(true),
bEnableFillMode(false),
ConfidenceThreshold(100),
ConfidenceThreshold(95),
TextureConfidenceThreshold(100),
ReferenceFrame(ESlReferenceFrame::RF_World),
bRemoveSaturatedAreas(true)
Expand Down Expand Up @@ -2291,7 +2301,7 @@ struct STEREOLABS_API FSlRegionOfInterestParameters
:
depthFarThresholdMeters(2.5f),
imageHeightRatioCutoff(0.5f),
bAutoApply(false)
autoApplyModule({ESlModule::M_All })
{}

/**
Expand All @@ -2313,7 +2323,7 @@ struct STEREOLABS_API FSlRegionOfInterestParameters
Default: Enabled
*/
bool bAutoApply = true;
TSet<ESlModule> autoApplyModule;
};

/*
Expand Down Expand Up @@ -2927,11 +2937,6 @@ struct STEREOLABS_API FSlObjectDetectionParameters
GENERATED_BODY()

const TCHAR* Section = TEXT("ObjectDetection");

/* Defines if the object detection is synchronized to the image or runs in a separate thread. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bImageSync;

/* Defines if the object detection will track objects across images flow. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bEnableTracking;
Expand Down Expand Up @@ -2974,7 +2979,6 @@ struct STEREOLABS_API FSlObjectDetectionParameters
bool bAllowReducedPrecisionInference;

FSlObjectDetectionParameters() :
bImageSync(true),
bEnableTracking(true),
bEnableSegmentation(false),
DetectionModel(ESlObjectDetectionModel::ODM_MultiClassBoxFast),
Expand Down Expand Up @@ -3172,11 +3176,6 @@ struct STEREOLABS_API FSlBodyTrackingParameters
GENERATED_BODY()

const TCHAR* Section = TEXT("BodyTracking");

/* Defines if the object detection is synchronized to the image or runs in a separate thread. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bImageSync;

/* Defines if the object detection will track objects across images flow. */
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bEnableTracking;
Expand Down Expand Up @@ -3222,7 +3221,6 @@ struct STEREOLABS_API FSlBodyTrackingParameters
bool bAllowReducedPrecisionInference;

FSlBodyTrackingParameters() :
bImageSync(true),
bEnableTracking(true),
bEnableSegmentation(false),
DetectionModel(ESlBodyTrackingModel::BTM_HumanBodyMedium),
Expand Down Expand Up @@ -3424,6 +3422,40 @@ struct STEREOLABS_API FSlBodies
{}
};

USTRUCT(BlueprintType, Category = "Stereolabs|Struct")
struct STEREOLABS_API FSlSVOData
{
GENERATED_BODY()

/// <summary>
/// Key used to retrieve the data stored into SVOData's content.
/// WARNING: Length must not exceed 128.
/// </summary>
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString Key = "";

/// <summary>
/// Timestamp of the data, in nanoseconds, as a string.
/// </summary>
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString TimestampNano = "0";

/// <summary>
/// Content stored as SVOData.
/// Allow any type of content, including raw data like compressed images or JSON.
/// </summary>
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString Content = "";

FSlSVOData()
:
Key(""),
TimestampNano(""),
Content("")
{}
};


/*
* Rendering parameters
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ class STEREOLABS_API USlCameraProxy : public UObject
ESlTrackingState GetPosition(FSlPose& Pose, ESlReferenceFrame ReferenceFrame);

UFUNCTION(BlueprintPure, meta = (Keywords = "Set Region Of Interest"), Category = "Zed|Tracking")
ESlErrorCode SetRegionOfInterest(FSlMat& Mat);
ESlErrorCode SetRegionOfInterest(FSlMat& Mat, TSet<ESlModule> Module);

UFUNCTION(BlueprintPure, meta = (Keywords = "Get Region Of Interest"), Category = "Zed|Tracking")
ESlErrorCode GetRegionOfInterest(FSlMat& Mat, FIntPoint& resolution);
ESlErrorCode GetRegionOfInterest(FSlMat& Mat, FIntPoint& Resolution, ESlModule Module);

UFUNCTION(BlueprintPure, meta = (Keywords = "start region of interest auto detection"), Category = "Zed|Tracking")
ESlErrorCode StartRegionOfInterestAutoDetection(FSlRegionOfInterestParameters& roiParams);
ESlErrorCode StartRegionOfInterestAutoDetection(FSlRegionOfInterestParameters& RoiParams);

UFUNCTION(BlueprintPure, meta = (Keywords = "get region of interest auto detection status"), Category = "Zed|Tracking")
ESlRegionOfInterestAutoDetectionState GetRegionOfInterestAutoDetectionStatus();
Expand Down Expand Up @@ -601,6 +601,31 @@ class STEREOLABS_API USlCameraProxy : public UObject
UFUNCTION(BlueprintCallable, meta = (Keywords = "disable svo recording"), Category = "Zed|SVO")
void DisableSVORecording();

/// <summary>
/// Ingests SVOData in a SVO file.
/// </summary>
/// <param name="svoData">Data to ingest in the SVO file.</param>
UFUNCTION(BlueprintCallable, meta = (Keywords = "ingest svo data"), Category = "Zed|SVO")
int IngestDataIntoSVO(const FSlSVOData& svoData);

/// <summary>
/// Retrieves SVOData from an SVO file.
/// </summary>
/// <param name="key">The key of the SVOData that is going to be retrieved.</param>
/// <param name="resSVOData">The array to be filled with FSlSVOData objects.</param>
/// <param name="ts_nano_begin">The beginning of the range.</param>
/// <param name="ts_nano_end">The end of the range.</param>
/// <returns>sl_ERROR_CODE_SUCCESS in case of success, sl_ERROR_CODE_FAILURE otherwise.</returns>
UFUNCTION(BlueprintCallable, meta = (Keywords = "retrieve svo data"), Category = "Zed|SVO")
int RetrieveSVOData(const FString& key, TArray<FSlSVOData>& resSVOData, FString ts_nano_begin, FString ts_nano_end);

/// <summary>
/// Gets the external channels that can be retrieved from the SVO file.
/// </summary>
/// <returns>List of available keys in the SVO.</returns>
UFUNCTION(BlueprintCallable, meta = (Keywords = "get svo data keys"), Category = "Zed|SVO")
TArray<FString> GetSVODataKeys();

/*
* Set the SVO playback position
* @param Position The new position
Expand Down Expand Up @@ -758,6 +783,12 @@ class STEREOLABS_API USlCameraProxy : public UObject
*/
SL_POSITIONAL_TRACKING_STATE GetCameraPosition(SL_PoseData* pose, SL_REFERENCE_FRAME rframe);

/// <summary>
/// Returns the current status of positional tracking module.
/// </summary>
/// <returns>The SL_PositionalTrackingStatus of the camera.</returns>
SL_PositionalTrackingStatus* GetPositionalTrackingStatus();

/*
* Easy access to IMU pose
*/
Expand Down
Loading

0 comments on commit 15fdfcc

Please sign in to comment.