Skip to content

Commit 13352f5

Browse files
Aisv647 visualizations - Preview Cut (#40)
* Initial cut of labeler visualizers * Added event system to the scene so that the UI would work * Created a shader that can remove the background of the segmentation image * Changed package for the shader * Now with sliders in UI for transparency values * Heads up display information now available * PR fixes Some fairly major UI architecture changes to address comments made during the initial cut PR. Things make more sense now. * Fixes so that rendering is not a frame behind * Graceful-ish handling of more than 1 perception camera for visualization * Removal of expired visualization artifacts fixes for SynthDet Removed bounding boxes and HUD entries for objects no longer being visualized, added performance improvements to handle complete scene changes every frame * Fixes for scroll bars on HUD and UI Controls on top of UI objects * Object pooling for HUD entries * Adding tests for visualization init and destroy. * Updated control panel to not need labels to add new controls * Moving visualization to screen space - camera and unifying into a single canvas to ensure good behavior with multiple cameras. * Bounding box visualizer fix to respond to screen resize * Sort of working enable/disable visualizations * Removing extra logic around enabling or disabling visualizations. Still have a bug with labelers being reset when serialized fields change, resulting in duplicate UI. * Disabling visualizations in non-development players. Making it so the inspector is non-editable in play mode to work around the myriad of issues with inspector changes in play mode seemingly stemming from usages of SerializeReference * Updated documentation * Updated documentation * Updated documentation * Updated changelog to 0.3.0-preview.1 * Fixing pip install issues * Fixed controls property getter * Attempting to fix linux builds. Fixing line ending mismatches when checking out with linux file endings. * Fixing semantic segmentation tests when visualizations are enabled * Fixing some tests wreaked by newline issues. Commenting out renderdoc code to get semantic segmentation tests to compile in players. * Removing final usage of UnityEditorInternal to fix tests * Fix for _MainTex test error * Fix for merge issue Co-authored-by: Jon Hogins <[email protected]>
1 parent 63762ce commit 13352f5

File tree

58 files changed

+4356
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4356
-79
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ upm-ci~/*
3434
**/.bin
3535
CodeCoverage
3636
/.download
37-
/TestProjects/PerceptionURP/Build
37+
**/Build/**
38+
**/Builds/**

TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ Light:
440440
m_BounceIntensity: 1
441441
m_ColorTemperature: 6570
442442
m_UseColorTemperature: 0
443-
m_BoundingSphereOverride: {x: 0, y: 1e-45, z: 1.8643e-41, w: 5.9e-44}
443+
m_BoundingSphereOverride: {x: 4.7e-43, y: 0, z: 0, w: 0}
444444
m_UseBoundingSphereOverride: 0
445445
m_ShadowRadius: 0
446446
m_ShadowAngle: 0
@@ -484,6 +484,7 @@ GameObject:
484484
- component: {fileID: 963194229}
485485
- component: {fileID: 963194227}
486486
- component: {fileID: 963194231}
487+
- component: {fileID: 963194232}
487488
m_Layer: 0
488489
m_Name: Main Camera
489490
m_TagString: MainCamera
@@ -608,6 +609,7 @@ MonoBehaviour:
608609
- id: 1
609610
- id: 2
610611
- id: 3
612+
showVisualizations: 1
611613
references:
612614
version: 1
613615
00000000:
@@ -653,8 +655,20 @@ MonoBehaviour:
653655
m_Script: {fileID: 11500000, guid: 7c51d9f2c5784bb4aee3fdf021966e14, type: 3}
654656
m_Name:
655657
m_EditorClassIdentifier:
656-
light: {fileID: 705507993}
658+
targetLight: {fileID: 705507993}
657659
target: {fileID: 1640252278}
660+
--- !u!114 &963194232
661+
MonoBehaviour:
662+
m_ObjectHideFlags: 0
663+
m_CorrespondingSourceObject: {fileID: 0}
664+
m_PrefabInstance: {fileID: 0}
665+
m_PrefabAsset: {fileID: 0}
666+
m_GameObject: {fileID: 963194225}
667+
m_Enabled: 1
668+
m_EditorHideFlags: 0
669+
m_Script: {fileID: 11500000, guid: 53f4c974fdf704444959724a41de0cfe, type: 3}
670+
m_Name:
671+
m_EditorClassIdentifier:
658672
--- !u!1 &1640252278
659673
GameObject:
660674
m_ObjectHideFlags: 0

TestProjects/PerceptionURP/ProjectSettings/EditorBuildSettings.asset

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
EditorBuildSettings:
55
m_ObjectHideFlags: 0
66
serializedVersion: 2
7-
m_Scenes: []
7+
m_Scenes:
8+
- enabled: 1
9+
path: Assets/Scenes/SampleScene.unity
10+
guid: 9fc0d4010bbf28b4594072e72b8655ab
811
m_configObjects: {}

com.unity.perception/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this package will be documented in this file.
34

45
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
@@ -19,18 +20,34 @@ Fixed compilation warnings with latest com.unity.simulation.core package.
1920

2021
### Security
2122

23+
## [0.3.0-preview.1] - 2020-07-31
24+
25+
### Added
26+
27+
Added realtime visualization capability to the perception package.
28+
29+
Added visualizers for built-in labelers: Semantic Segmentation, 2D Bounding Boxes, Object Count, and Render Object Info.
30+
2231
## [0.2.0-preview.2] - 2020-07-15
32+
2333
### Fixed
34+
2435
Fixed bug that prevented RGB captures to be written out to disk
2536
Fixed compatibility with [email protected]
2637

2738
## [0.2.0-preview.1] - 2020-07-02
39+
2840
### Added
41+
2942
Added CameraLabeler, an extensible base type for all forms of dataset output from a camera.
3043
Added LabelConfig\<T\>, a base class for mapping labels to data used by a labeler. There are two new derived types - ID label config and semantic segmentation label config.
44+
3145
### Changed
46+
3247
Moved the various forms of ground truth from PerceptionCamera into various subclasses of CameraLabeler.
3348
Renamed SimulationManager to DatasetCapture.
3449
Changed Semantic Segmentation to take a SemanticSegmentationLabelConfig, which maps labels to color pixel values.
50+
3551
## [0.1.0] - 2020-06-24
52+
3653
### This is the first release of the _Perception_ package

com.unity.perception/Documentation~/GettingStarted.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Getting Started with Perception
2+
23
This walkthrough will provide creating a new scene for generating perception datasets including segmentation data and image captures.
34

45
## Step 1: Create a project and install Perception
6+
57
First, follow [this guide](SetupSteps.md) to install Perception in your project.
68

79
## Step 2 (for Universal Render Pipeline projects): Add GroundTruthRendererFeature
10+
811
This step can be skipped for HDRP projects.
912

1013
1. Select your project's `ScriptableRenderer` asset and open the inspector window. In most projects it is located at `Assets/Settings/ForwardRenderer.asset`.
@@ -13,17 +16,19 @@ This step can be skipped for HDRP projects.
1316
<img src="images/ScriptableRendererStep.png" align="middle"/>
1417

1518
## Step 3: Create a new scene and camera
19+
1620
1. Create a new scene using File -> New Scene
1721
2. `ctrl+s` to save the scene and give it a name
18-
3. Select the Main Camera and reset the Position transform to 0
22+
3. Select the Main Camera and reset the Position transform to 0
1923
4. In the Hierarchy window select the main camera
20-
1. In the inspector panel of the main camera select Add Component
21-
2. Add a **Perception Camera** component
24+
1. In the inspector panel of the main camera select Add Component
25+
2. Add a **Perception Camera** component
2226

2327
<img src="images/PerceptionCameraFinished.png" align="middle"/>
2428

2529
## Step 4: Create labeled objects
26-
1. Create a cube by right-clicking in the Hierarchy window, select 3D Object -> Cube
30+
31+
1. Create a cube by right-clicking in the Hierarchy window, select 3D Object -> Cube
2732
2. Create 2 more cubes this way
2833
3. Change the names of the cubes to Cube, Box, and Crate
2934
4. Position the Cubes in front of the main Camera
@@ -49,19 +54,39 @@ This step can be skipped for HDRP projects.
4954
<img src="images/MainCameraLabelConfig.PNG" align="middle"/>
5055

5156
## Step 5: Run simulation and generate dataset
57+
5258
1. Press play in the editor, allow the scene to run for a few seconds, and then exit playmode
5359
2. In the console log you will see a Shutdown in Progress message that will show a file path to the location of the generated dataset.
54-
>Example file path on a Windows PC : `C:/Users/<User Name>/AppData/LocalLow/DefaultCompany/UnityTestFramework\2e10ec21-9d97-4cee-b5a2-7e95e299afa4\RGB18f61842-ef8d-4b31-acb5-cb1da36fb7b1`
60+
61+
> Example file path on a Windows PC : `C:/Users/<User Name>/AppData/LocalLow/DefaultCompany/UnityTestFramework\2e10ec21-9d97-4cee-b5a2-7e95e299afa4\RGB18f61842-ef8d-4b31-acb5-cb1da36fb7b1`
62+
5563
3. In the dataset folder you will find the following data:
56-
- RGB captures
57-
- Semantic segmentation images
58-
- Logs
59-
- JSON dataset
60-
64+
- RGB captures
65+
- Semantic segmentation images
66+
- Logs
67+
- JSON dataset
68+
6169
<img src="images/rgb_2.png" align="middle"/>
6270

6371
_RGB image_
6472

6573
<img src="images/segmentation_2.png" align="middle"/>
6674

67-
_Example semantic segmentation image_
75+
_Example semantic segmentation image_
76+
77+
## Optional Step: Realtime visualization of labelers
78+
79+
The perception package now comes with the ability to show realtime results of the labeler in the scene. To enable this capability:
80+
81+
<img src="images/visualized.png" align="middle"/>
82+
83+
_Example of perception running with show visualizations on_
84+
85+
1. To use the visualizer, verify that *Show Visualizations* is checked on in the Inspector pane. This turns on the built in labelers which includes segmentation data, 2D bounding boxes, pixel and object counts.
86+
2. Turning on the visualizer creates new UI controls in the editor's game view. These controls allow you to atomically control each of the individual visualizers. Each individual can be turned on/off on their own. Some visualizers also include controls to change their output.
87+
88+
<img src="images/controls.gif" align="middle"/>
89+
90+
_Visualization controls in action_
91+
92+
***Important Note:*** The perception package takes advantage of asynchronous processing to ensure reasonable frame rates of a scene. A side effect of realtime visualization is that the labelers have to be applied to the capture in its actual frame, which will potentially adversely affect the scene's framerate.
473 KB
Loading
88.6 KB
Loading

com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,18 @@ void AddLabeler(Type labelerType)
7878

7979
public override void OnInspectorGUI()
8080
{
81-
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.description)));
82-
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.period)));
83-
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.startTime)));
84-
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureRgbImages)));
85-
86-
//EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.labelers)));
87-
m_LabelersList.DoLayoutList();
88-
81+
using(new EditorGUI.DisabledScope(EditorApplication.isPlaying))
82+
{
83+
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.description)));
84+
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.period)));
85+
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.startTime)));
86+
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.showVisualizations)));
87+
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.captureRgbImages)));
88+
serializedObject.ApplyModifiedProperties();
89+
90+
//EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.labelers)));
91+
m_LabelersList.DoLayoutList();
92+
}
8993
if (EditorSettings.asyncShaderCompilation)
9094
{
9195
EditorGUILayout.HelpBox("Asynchronous shader compilation may result in invalid data in beginning frames. This can be disabled in Project Settings -> Edtior -> Asynchronous Shader Compilation", MessageType.Warning);

com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using Unity.Collections;
55
using Unity.Profiling;
66
using UnityEngine.Serialization;
7+
using Unity.Simulation;
8+
using UnityEngine.UI;
79

810
namespace UnityEngine.Perception.GroundTruth
911
{
@@ -42,6 +44,10 @@ struct BoundingBoxValue
4244
AnnotationDefinition m_BoundingBoxAnnotationDefinition;
4345
BoundingBoxValue[] m_BoundingBoxValues;
4446

47+
private GameObject visualizationHolder = null;
48+
49+
private Vector2 originalScreenSize = Vector2.zero;
50+
4551
/// <summary>
4652
/// Creates a new BoundingBox2DLabeler. Be sure to assign <see cref="idLabelConfig"/> before adding to a <see cref="PerceptionCamera"/>.
4753
/// </summary>
@@ -58,6 +64,9 @@ public BoundingBox2DLabeler(IdLabelConfig labelConfig)
5864
this.idLabelConfig = labelConfig;
5965
}
6066

67+
/// <inheritdoc/>
68+
protected override bool supportsVisualization => true;
69+
6170
/// <inheritdoc/>
6271
protected override void Setup()
6372
{
@@ -70,6 +79,12 @@ protected override void Setup()
7079
"Bounding box for each labeled object visible to the sensor", id: new Guid(annotationId));
7180

7281
perceptionCamera.RenderedObjectInfosCalculated += OnRenderedObjectInfosCalculated;
82+
83+
visualizationEnabled = supportsVisualization;
84+
85+
// Record the original screen size. The screen size can change during play, and the visual bounding
86+
// boxes need to be scaled appropriately
87+
originalScreenSize = new Vector2(Screen.width, Screen.height);
7388
}
7489

7590
/// <inheritdoc/>
@@ -108,8 +123,80 @@ void OnRenderedObjectInfosCalculated(int frameCount, NativeArray<RenderedObjectI
108123
};
109124
}
110125

126+
if (!CaptureOptions.useAsyncReadbackIfSupported && frameCount != Time.frameCount)
127+
Debug.LogWarning("Not on current frame: " + frameCount + "(" + Time.frameCount + ")");
128+
129+
if (visualizationEnabled)
130+
{
131+
Visualize();
132+
}
133+
111134
asyncAnnotation.ReportValues(m_BoundingBoxValues);
112135
}
113136
}
137+
138+
/// <inheritdoc/>
139+
protected override void PopulateVisualizationPanel(ControlPanel panel)
140+
{
141+
panel.AddToggleControl("BoundingBoxes", enabled => {
142+
visualizationEnabled = enabled;
143+
});
144+
145+
objectPool = new List<GameObject>();
146+
147+
visualizationHolder = new GameObject("BoundsHolder" + Time.frameCount);
148+
visualizationCanvas.AddComponent(visualizationHolder);
149+
}
150+
151+
void ClearObjectPool(int count)
152+
{
153+
for (int i = count; i < objectPool.Count; i++)
154+
{
155+
objectPool[i].SetActive(false);
156+
}
157+
}
158+
159+
List<GameObject> objectPool = null;
160+
161+
void Visualize()
162+
{
163+
ClearObjectPool(m_BoundingBoxValues.Length);
164+
165+
// The player screen can be dynamically resized during play, need to
166+
// scale the bounding boxes appropriately from the original screen size
167+
float screenRatioWidth = Screen.width / originalScreenSize.x;
168+
float screenRatioHeight = Screen.height / originalScreenSize.y;
169+
170+
for (int i = 0; i < m_BoundingBoxValues.Length; i++)
171+
{
172+
var boxVal = m_BoundingBoxValues[i];
173+
174+
if (i >= objectPool.Count)
175+
{
176+
var boundingBoxObject = GameObject.Instantiate(Resources.Load<GameObject>("BoundingBoxPrefab"));
177+
objectPool.Add(boundingBoxObject);
178+
var rectTransform = (RectTransform)boundingBoxObject.transform;
179+
rectTransform.SetParent(visualizationHolder.transform, false);
180+
}
181+
182+
if (!objectPool[i].activeSelf) objectPool[i].SetActive(true);
183+
184+
string label = boxVal.label_name + "_" + boxVal.instance_id;
185+
objectPool[i].GetComponentInChildren<Text>().text = label;
186+
187+
var rectTrans = objectPool[i].transform as RectTransform;
188+
189+
rectTrans.anchoredPosition = new Vector2(boxVal.x * screenRatioWidth, -boxVal.y * screenRatioHeight);
190+
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, boxVal.width * screenRatioWidth);
191+
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, boxVal.height * screenRatioHeight);
192+
}
193+
}
194+
195+
/// <inheritdoc/>
196+
override protected void OnVisualizerEnabledChanged(bool enabled)
197+
{
198+
if (visualizationHolder != null)
199+
visualizationHolder.SetActive(enabled);
200+
}
114201
}
115202
}

0 commit comments

Comments
 (0)