From 78fba44e637c81185f3802eba20d83fab90fc363 Mon Sep 17 00:00:00 2001 From: Wouter Jansen Date: Mon, 30 Sep 2024 16:06:06 +0200 Subject: [PATCH] Added main parameter to toggle initial instance segmentation. Set to true by default. Ref #23 (cherry picked from commit fe0a647f76194f9a9290e7cd103271e4471fd490) --- AirLib/include/common/AirSimSettings.hpp | 2 ++ Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp | 4 +++- docs/image_apis.md | 2 +- docs/instance_segmentation.md | 2 +- docs/settings.md | 1 + docs/settings_example.json | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AirLib/include/common/AirSimSettings.hpp b/AirLib/include/common/AirSimSettings.hpp index 97f906ae0..e55be18b5 100644 --- a/AirLib/include/common/AirSimSettings.hpp +++ b/AirLib/include/common/AirSimSettings.hpp @@ -509,6 +509,7 @@ namespace airlib float clock_speed = 1.0f; bool engine_sound = false; bool move_world_origin = false; + bool initial_instance_segmentation = true; bool log_messages_visible = true; bool show_los_debug_lines_ = false; HomeGeoPoint origin_geopoint{ GeoPoint(47.641468, -122.140165, 122) }; //The geo-coordinate assigned to Unreal coordinate 0,0,0 @@ -1454,6 +1455,7 @@ namespace airlib speed_unit_factor = settings_json.getFloat("SpeedUnitFactor", 1.0f); speed_unit_label = settings_json.getString("SpeedUnitLabel", "m\\s"); move_world_origin = settings_json.getBool("MoveWorldOrigin", false); + initial_instance_segmentation = settings_json.getBool("InitialInstanceSegmentation", true); log_messages_visible = settings_json.getBool("LogMessagesVisible", true); show_los_debug_lines_ = settings_json.getBool("ShowLosDebugLines", false); diff --git a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp index a39461a08..c27fe2a7c 100755 --- a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp +++ b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp @@ -235,7 +235,9 @@ bool ASimModeBase::IsAnnotationRGBValid(FString annotation_name, FColor color) { void ASimModeBase::InitializeInstanceSegmentation() { - instance_segmentation_annotator_.Initialize(this->GetLevel()); + if (getSettings().initial_instance_segmentation) { + instance_segmentation_annotator_.Initialize(this->GetLevel()); + } ForceUpdateInstanceSegmentation(); updateInstanceSegmentationAnnotation(); } diff --git a/docs/image_apis.md b/docs/image_apis.md index 6661454da..35e8c26a3 100644 --- a/docs/image_apis.md +++ b/docs/image_apis.md @@ -242,7 +242,7 @@ When you specify `ImageType = DepthVis` in `ImageRequest`, you get an image that You normally want to retrieve disparity image as float (i.e. set `pixels_as_float = true` and specify `ImageType = DisparityNormalized` in `ImageRequest`) in which case each pixel is `(Xl - Xr)/Xmax`, which is thereby normalized to values between 0 to 1. ### Segmentation -When you specify `ImageType = Segmentation` in `ImageRequest`, you get an image that gives you ground truth instance segmentation of the scene. At the startup, AirSim assigns a random color index to each mesh available in environment. The RGB values for each color index ID can be retrieved from the API. +When you specify `ImageType = Segmentation` in `ImageRequest`, you get an image that gives you ground truth instance segmentation of the scene. At the startup, AirSim assigns a random color index to each mesh available in environment. You can disable this by setting the main parameter `InitialInstanceSegmentation` to false in the settings.json file. The RGB values for each color index ID can be retrieved from the API. You can assign a specific value to a specific mesh using APIs. For example, below Python code sets the object ID for the mesh called "Ground" to 20 in Blocks environment and hence changes its color in Segmentation view to the 20th color of the instance segmentation colormap: Note that this will not do a check if this color is already assigned to a different object! diff --git a/docs/instance_segmentation.md b/docs/instance_segmentation.md index 64991eff2..01c3652d7 100644 --- a/docs/instance_segmentation.md +++ b/docs/instance_segmentation.md @@ -11,7 +11,7 @@ An Instance segmentation system is implemented into Cosys-AirSim. It uses Proxy * These and other unsupported object types that are less common that either will not be rendered (decals, text, foliage, ...) or will by default be given the RGB color value of [149,149,149] or [0,0,0]. (brush objects, landscape,...). ## Usage -By default, at the start of the simulation, it will give a random color to each object. +By default, at the start of the simulation, it will give a random color to each object. You can disable this by setting the main parameter `InitialInstanceSegmentation` to false in the settings.json file. Please see the [Image API documentation](image_apis.md#segmentation) on how to manually set or get the color information. For an example of the Instance Segmentation API, please see the script _segmentation_test.py_ (Cosys-Airsim/PythonClient/segmentation/segmentation_test.py). diff --git a/docs/settings.md b/docs/settings.md index 66425f3fe..67818ee40 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -55,6 +55,7 @@ Note this does not include most sensor types. "ApiServerPort": 41451, "RecordUIVisible": true, "MoveWorldOrigin": false, + "InitialInstanceSegmentation": true, "LogMessagesVisible": true, "ShowLosDebugLines": false, "ViewMode": "", diff --git a/docs/settings_example.json b/docs/settings_example.json index bae3769f5..90c8d0970 100644 --- a/docs/settings_example.json +++ b/docs/settings_example.json @@ -6,6 +6,7 @@ "ApiServerPort": 41451, "RecordUIVisible": true, "MoveWorldOrigin": false, + "InitialInstanceSegmentation": true, "LogMessagesVisible": true, "ShowLosDebugLines": false, "ViewMode": "",