比较提交

...
此合并请求有变更与目标分支冲突。
/TestProjects/PerceptionURP/Packages/manifest.json
/TestProjects/PerceptionURP/ProjectSettings/ProjectVersion.txt
/TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
/com.unity.perception/Editor/Unity.Perception.Editor.asmdef
/com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
/com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
/com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
/TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset.meta
/com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs.meta
/TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset
/TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset.meta
/com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
/com.unity.perception/Runtime/GroundTruth/Labelers
/com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs
/com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs

1 次代码提交

作者 SHA1 备注 提交日期
Jon Hogins ab3dae9a Starting to migrate BoundingBoxLabeler 4 年前
共有 29 个文件被更改,包括 730 次插入65 次删除
  1. 30
      TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
  2. 2
      TestProjects/PerceptionURP/Packages/manifest.json
  3. 4
      TestProjects/PerceptionURP/ProjectSettings/ProjectVersion.txt
  4. 6
      com.unity.perception/Editor/Unity.Perception.Editor.asmdef
  5. 18
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs
  6. 27
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
  7. 101
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  8. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
  9. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  10. 23
      TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset
  11. 8
      TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset.meta
  12. 3
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs.meta
  13. 33
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs
  14. 3
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs.meta
  15. 24
      com.unity.perception/Editor/GroundTruth/BoundingBoxLabelerEditor.cs
  16. 3
      com.unity.perception/Editor/GroundTruth/BoundingBoxLabelerEditor.cs.meta
  17. 287
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  18. 3
      com.unity.perception/Runtime/GroundTruth/Labelers.meta
  19. 108
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs
  20. 3
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs.meta
  21. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs.meta
  22. 9
      com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs
  23. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs.meta
  24. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
  25. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs.meta
  26. 10
      com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
  27. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs.meta
  28. 27
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs

30
TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity


boundingBoxOrigin: 0
LabelingConfiguration: {fileID: 11400000, guid: e74234fe725079e4aa7ecd74797ceb79,
type: 2}
labelers:
- id: 0
- id: 1
- id: 2
references:
version: 1
00000000:
type: {class: RenderedObjectInfoLabeler, ns: UnityEngine.Perception.GroundTruth,
asm: Unity.Perception.Runtime}
data:
enabled: 1
foldout: 0
annotationId: F9F22E05-443F-4602-A422-EBE4EA9B55CB
labelingConfiguration: {fileID: 0}
00000001:
type: {class: BoundingBoxLabeler, ns: UnityEngine.Perception.GroundTruth, asm: Unity.Perception.Runtime}
data:
enabled: 1
foldout: 0
annotationId: F9F22E05-443F-4602-A422-EBE4EA9B55CB
labelingConfiguration: {fileID: 11400000, guid: e74234fe725079e4aa7ecd74797ceb79,
type: 2}
00000002:
type: {class: SemanticSegmentationLabeler, ns: UnityEngine.Perception.GroundTruth,
asm: Unity.Perception.Runtime}
data:
enabled: 1
foldout: 0
annotationId: 12F94D8D-5425-4DEB-9B21-5E53AD957D66
labelConfig: {fileID: 0}
--- !u!114 &963194231
MonoBehaviour:
m_ObjectHideFlags: 0

2
TestProjects/PerceptionURP/Packages/manifest.json


"com.unity.render-pipelines.universal": "7.3.1",
"com.unity.simulation.capture": "0.0.10-preview.6",
"com.unity.simulation.core": "0.0.10-preview.8",
"com.unity.test-framework": "1.1.13",
"com.unity.test-framework": "1.1.14",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.12",
"com.unity.ugui": "1.0.0",

4
TestProjects/PerceptionURP/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2019.3.13f1
m_EditorVersionWithRevision: 2019.3.13f1 (d4ddf0d95db9)
m_EditorVersion: 2019.4.0f1
m_EditorVersionWithRevision: 2019.4.0f1 (0af376155913)

6
com.unity.perception/Editor/Unity.Perception.Editor.asmdef


],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [

18
com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs


public void OnEnable()
{
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(nameof(LabelingConfiguration.LabelEntries)), true, false, true, true);
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 3 + k_Margin;
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + k_Margin;
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;

labelProperty.stringValue = newLabel;
}
}
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight * 2), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newValue = EditorGUI.IntField(contentRect, nameof(LabelEntry.value), valueProperty.intValue);
if (change.changed)
valueProperty.intValue = newValue;
}
//
// using (var change = new EditorGUI.ChangeCheckScope())
// {
// var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight * 2), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
// var newValue = EditorGUI.IntField(contentRect, nameof(LabelEntry.value), valueProperty.intValue);
// if (change.changed)
// valueProperty.intValue = newValue;
// }
}
bool autoAssign => serializedObject.FindProperty(nameof(LabelingConfiguration.AutoAssignIds)).boolValue;

27
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs


using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth

labelEntryIndex = -1;
labelEntry = default;
return false;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal struct LabelEntrySpec
{
/// <summary>
/// The label id prepared for reporting in the annotation
/// </summary>
[UsedImplicitly]
public int label_id;
/// <summary>
/// The label name prepared for reporting in the annotation
/// </summary>
[UsedImplicitly]
public string label_name;
}
internal LabelEntrySpec[] GetAnnotationSpecification()
{
return LabelEntries.Select((l) => new LabelEntrySpec()
{
label_id = l.id,
label_name = l.label,
}).ToArray();
}
}

101
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


/// <summary>
/// Whether semantic segmentation images should be generated
/// </summary>
public bool produceSegmentationImages = true;
[FormerlySerializedAs("produceSegmentationImages")]
public bool produceSemanticSegmentationImages = true;
/// <summary>
/// Whether object counts should be computed
/// </summary>

/// </summary>
public LabelingConfiguration LabelingConfiguration;
[SerializeReference]
public List<CameraLabeler> labelers = new List<CameraLabeler>();
internal event Action<int, NativeArray<uint>> segmentationImageReceived;
internal event Action<int, NativeArray<uint>> instanceSegmentationImageReceived;
internal event Action<NativeSlice<uint>, IReadOnlyList<LabelEntry>, int> classCountsReceived;

internal RenderTexture segmentationTexture;
internal RenderTexture instanceSegmentationTexture;
RenderTextureReader<short> m_ClassLabelingTextureReader;
RenderTextureReader<uint> m_SegmentationReader;
RenderTextureReader<short> m_SemanticSegmentationTextureReader;
RenderTextureReader<uint> m_InstanceSegmentationReader;
RenderedObjectInfoGenerator m_RenderedObjectInfoGenerator;
Dictionary<string, object> m_PersistentSensorData = new Dictionary<string, object>();

public int pixel_value;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
struct ObjectCountSpec
{
[UsedImplicitly]
public int label_id;
[UsedImplicitly]
public string label_name;
}
/// <summary>
/// Add a data object which will be added to the dataset with each capture. Overrides existing sensor data associated with the given key.
/// </summary>

var width = myCamera.pixelWidth;
var height = myCamera.pixelHeight;
if ((produceSegmentationImages || produceObjectCountAnnotations || produceBoundingBoxAnnotations) && LabelingConfiguration == null)
if ((produceSemanticSegmentationImages || produceObjectCountAnnotations || produceBoundingBoxAnnotations) && LabelingConfiguration == null)
produceSegmentationImages = false;
produceSemanticSegmentationImages = false;
segmentationTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8));
segmentationTexture.name = "Segmentation";
instanceSegmentationTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8));
instanceSegmentationTexture.name = "Segmentation";
labelingTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8));
labelingTexture.name = "Labeling";

SetupPasses(customPassVolume);
#endif
#if URP_PRESENT
instanceSegmentationUrpPass = new InstanceSegmentationUrpPass(myCamera, segmentationTexture);
instanceSegmentationUrpPass = new InstanceSegmentationUrpPass(myCamera, instanceSegmentationTexture);
if (produceSegmentationImages)
if (produceSemanticSegmentationImages)
{
var specs = LabelingConfiguration.LabelEntries.Select((l) => new SemanticSegmentationSpec()
{

m_SegmentationAnnotationDefinition = SimulationManager.RegisterAnnotationDefinition("semantic segmentation", specs, "pixel-wise semantic segmentation label", "PNG");
m_ClassLabelingTextureReader = new RenderTextureReader<short>(labelingTexture, myCamera,
m_SemanticSegmentationTextureReader = new RenderTextureReader<short>(labelingTexture, myCamera,
var labelingMetricSpec = LabelingConfiguration.LabelEntries.Select((l) => new ObjectCountSpec()
{
label_id = l.id,
label_name = l.label,
}).ToArray();
var labelingMetricSpec = LabelingConfiguration.GetAnnotationSpecification();
if (produceObjectCountAnnotations)
{

if (produceBoundingBoxAnnotations)
{
m_BoundingBoxAnnotationDefinition = SimulationManager.RegisterAnnotationDefinition("bounding box", labelingMetricSpec, "Bounding box for each labeled object visible to the sensor", id: new Guid(boundingBoxId));
}
if (produceRenderedObjectInfoMetric)
m_RenderedObjectInfoMetricDefinition = SimulationManager.RegisterMetricDefinition("rendered object info", labelingMetricSpec, "Information about each labeled object visible to the sensor", id: new Guid(renderedObjectInfoId));

m_SegmentationReader = new RenderTextureReader<uint>(segmentationTexture, myCamera, (frameCount, data, tex) =>
m_InstanceSegmentationReader = new RenderTextureReader<uint>(instanceSegmentationTexture, myCamera, (frameCount, data, tex) =>
if (segmentationImageReceived != null)
segmentationImageReceived(frameCount, data);
instanceSegmentationImageReceived?.Invoke(frameCount, data);
m_RenderedObjectInfoGenerator.Compute(data, tex.width, boundingBoxOrigin, out var renderedObjectInfos, out var classCounts, Allocator.Temp);

RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
SimulationManager.SimulationEnding += OnSimulationEnding;
}
// ReSharper disable InconsistentNaming
struct RenderedObjectInfoValue

void ReportAsyncAnnotations()
{
if (produceSegmentationImages || produceObjectCountAnnotations || produceBoundingBoxAnnotations || produceRenderedObjectInfoMetric)
if (produceSemanticSegmentationImages || produceObjectCountAnnotations || produceBoundingBoxAnnotations || produceRenderedObjectInfoMetric)
if (produceSegmentationImages)
if (produceSemanticSegmentationImages)
captureInfo.SegmentationAsyncAnnotation = SensorHandle.ReportAnnotationAsync(m_SegmentationAnnotationDefinition);
if (produceObjectCountAnnotations)

void OnSimulationEnding()
{
m_ClassLabelingTextureReader?.WaitForAllImages();
m_ClassLabelingTextureReader?.Dispose();
m_ClassLabelingTextureReader = null;
m_SemanticSegmentationTextureReader?.WaitForAllImages();
m_SemanticSegmentationTextureReader?.Dispose();
m_SemanticSegmentationTextureReader = null;
m_SegmentationReader?.WaitForAllImages();
m_SegmentationReader?.Dispose();
m_SegmentationReader = null;
m_InstanceSegmentationReader?.WaitForAllImages();
m_InstanceSegmentationReader?.Dispose();
m_InstanceSegmentationReader = null;
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
}

OnSimulationEnding();
m_ClassLabelingTextureReader?.Dispose();
m_ClassLabelingTextureReader = null;
if (segmentationTexture != null)
segmentationTexture.Release();
m_SemanticSegmentationTextureReader?.Dispose();
m_SemanticSegmentationTextureReader = null;
if (instanceSegmentationTexture != null)
instanceSegmentationTexture.Release();
segmentationTexture = null;
instanceSegmentationTexture = null;
if (labelingTexture != null)
labelingTexture.Release();

Profiler.EndSample();
return AsyncRequest.Result.Completed;
});
}
}
[Serializable]
public abstract class CameraLabeler
{
public bool enabled;
public bool foldout;
protected PerceptionCamera PerceptionCamera { get; private set; }
protected SensorHandle SensorHandle { get; private set; }
public abstract void Setup();
public virtual void Update() { }
public virtual void OnInstanceSegmentationRead(int frameCount) { }
internal void Init(PerceptionCamera perceptionCamera)
{
PerceptionCamera = perceptionCamera;
SensorHandle = perceptionCamera.SensorHandle;
}
}
}

4
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


public IEnumerator EnableSemanticSegmentation_GeneratesCorrectDataset()
{
var labelingConfiguration = CreateLabelingConfiguration();
SetupCamera(labelingConfiguration, pc => pc.produceSegmentationImages = true);
SetupCamera(labelingConfiguration, pc => pc.produceSemanticSegmentationImages = true);
string expectedImageFilename = $"segmentation_{Time.frameCount}.png";

camera.orthographicSize = 1;
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.produceSegmentationImages = false;
perceptionCamera.produceSemanticSegmentationImages = false;
perceptionCamera.produceRenderedObjectInfoMetric = false;
perceptionCamera.produceBoundingBoxAnnotations = false;
perceptionCamera.produceObjectCountAnnotations = false;

4
com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs


var skinnedMeshRenderer = planeObject.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.sharedMesh = meshFilter.sharedMesh;
skinnedMeshRenderer.material = meshRenderer.material;
Object.DestroyImmediate(oldObject);
}
planeObject.transform.SetPositionAndRotation(new Vector3(0, 0, 10), Quaternion.Euler(90, 0, 0));

perceptionCamera.captureRgbImages = false;
perceptionCamera.produceBoundingBoxAnnotations = false;
perceptionCamera.produceObjectCountAnnotations = true;
perceptionCamera.segmentationImageReceived += onSegmentationImageReceived;
perceptionCamera.instanceSegmentationImageReceived += onSegmentationImageReceived;
#endif
AddTestObjectForCleanup(cameraObject);
cameraObject.SetActive(true);

23
TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 0}
m_Name: SemanticSegmentationLabelingConfiguration
m_EditorClassIdentifier: Unity.Perception.Runtime:UnityEngine.Perception.GroundTruth:SemanticSegmentationLabelConfig
LabelEntries:
- label: box
pixelValue: 10000
- label: cube
pixelValue: 20000
- label: crate
pixelValue: 30000
AutoAssignIds: 1
StartingLabelId: 1

8
TestProjects/PerceptionURP/Assets/SemanticSegmentationLabelingConfiguration.asset.meta


fileFormatVersion: 2
guid: c140c5aa05dd09e4fadaa26de31b1f39
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

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


fileFormatVersion: 2
guid: d6936a1fe4b946a8b72f33ac7c4906e4
timeCreated: 1589372488

33
com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs


using System.IO;
using Newtonsoft.Json.Linq;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[ScriptedImporter(1, "labelconfig")]
public class LabelingConfigurationImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var text = File.ReadAllText(ctx.assetPath);
var jObject = JObject.Parse(text);
var config = ScriptableObject.CreateInstance<LabelingConfiguration>();
if (jObject["auto-assign-ids"].HasValues)
config.AutoAssignIds = jObject["auto-assign-ids"].Value<bool>();
if (jObject["starting-index"].HasValues)
{
var startingLabelId = (StartingLabelId)jObject["starting-index"].Value<int>();
config.StartingLabelId = startingLabelId;
}
if (jObject["configs"].HasValues)
{
}
ctx.SetMainObject(config);
}
}
}

3
com.unity.perception/Editor/GroundTruth/LabelingConfigurationImporter.cs.meta


fileFormatVersion: 2
guid: b0ecdacff7b34c54b2bad5b04e868356
timeCreated: 1589474006

24
com.unity.perception/Editor/GroundTruth/BoundingBoxLabelerEditor.cs


using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(BoundingBoxLabeler))]
public class BoundingBoxLabelerEditor : Editor
{
public override void OnInspectorGUI()
{
// base.OnInspectorGUI();
// return;
EditorGUILayout.PropertyField(this.serializedObject.FindProperty(nameof(BoundingBoxLabeler.annotationId)));
var serializedProperty = this.serializedObject.FindProperty(nameof(BoundingBoxLabeler.labelingConfiguration));
if (serializedProperty.objectReferenceValue != null)
{
EditorGUILayout.Separator();
var editor = Editor.CreateEditor(serializedProperty.objectReferenceValue);
editor.OnInspectorGUI();
}
}
}
}

3
com.unity.perception/Editor/GroundTruth/BoundingBoxLabelerEditor.cs.meta


fileFormatVersion: 2
guid: d114d25761d742d4806c0f9e2e498764
timeCreated: 1589407154

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Rendering;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(PerceptionCamera))]
public class PerceptionCameraEditor : Editor
{
ReorderableList m_LabelersList;
public void OnEnable()
{
m_LabelersList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(nameof(PerceptionCamera.labelers)), true, false, true, true);
m_LabelersList.drawHeaderCallback = (rect) => {
EditorGUI.LabelField(rect, "Camera Labelers", EditorStyles.largeLabel);
};
m_LabelersList.elementHeightCallback = GetElementHeight;
m_LabelersList.drawElementCallback = DrawElement;
m_LabelersList.onAddCallback += OnAdd;
m_LabelersList.onRemoveCallback += OnRemove;
}
float GetElementHeight(int index)
{
var serializedProperty = this.serializedObject.FindProperty(nameof(PerceptionCamera.labelers));
var element = serializedProperty.GetArrayElementAtIndex(index);
var editor = GetCameraLabelerDrawer(element, index);
return editor.GetElementHeight(element);
}
PerceptionCamera PerceptionCamera => ((PerceptionCamera)this.target);
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
var element = this.serializedObject.FindProperty(nameof(PerceptionCamera.labelers)).GetArrayElementAtIndex(index);
var editor = GetCameraLabelerDrawer(element, index);
editor.OnGUI(rect, element);
}
void OnRemove(ReorderableList list)
{
var labelers = serializedObject.FindProperty(nameof(PerceptionCamera.labelers));
labelers.DeleteArrayElementAtIndex(list.index);
serializedObject.ApplyModifiedProperties();
}
void OnAdd(ReorderableList list)
{
Undo.RegisterCompleteObjectUndo(target, "Remove camera labeler");
var labelers = this.serializedObject.FindProperty(nameof(PerceptionCamera.labelers));
var dropdownOptions = TypeCache.GetTypesDerivedFrom<CameraLabeler>();
var menu = new GenericMenu();
foreach (var option in dropdownOptions)
{
var localOption = option;
menu.AddItem(new GUIContent(option.Name),
false,
() => AddLabeler(labelers, localOption));
}
menu.ShowAsContext();
}
void AddLabeler(SerializedProperty labelers, Type labelerType)
{
var insertIndex = labelers.arraySize;
labelers.InsertArrayElementAtIndex(insertIndex);
var element = labelers.GetArrayElementAtIndex(insertIndex);
var labeler = (CameraLabeler) Activator.CreateInstance(labelerType);
labeler.enabled = true;
element.managedReferenceValue = labeler;
serializedObject.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.description)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.period)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.startTime)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.captureRgbImages)));
//EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.labelers)));
m_LabelersList.DoLayoutList();
}
Dictionary<SerializedProperty, CameraLabelerDrawer> cameraLabelerDrawers = new Dictionary<SerializedProperty, CameraLabelerDrawer>();
CameraLabelerDrawer GetCameraLabelerDrawer(SerializedProperty element, int listIndex)
{
CameraLabelerDrawer drawer;
if (cameraLabelerDrawers.TryGetValue(element, out drawer))
return drawer;
var labeler = PerceptionCamera.labelers[listIndex];
foreach (var drawerType in TypeCache.GetTypesWithAttribute(typeof(CameraLabelerDrawerAttribute)))
{
var attr = drawerType.GetCustomAttributes(typeof(CameraLabelerDrawerAttribute), true)[0] as CameraLabelerDrawerAttribute;
if (attr.targetLabelerType == labeler.GetType())
{
drawer = Activator.CreateInstance(drawerType) as CameraLabelerDrawer;
drawer.CameraLabeler = labeler;
break;
}
if (attr.targetLabelerType.IsAssignableFrom(labeler.GetType()))
{
drawer = Activator.CreateInstance(drawerType) as CameraLabelerDrawer;
drawer.CameraLabeler = labeler;
}
}
cameraLabelerDrawers[element] = drawer;
return drawer;
}
}
[AttributeUsage(AttributeTargets.Class)]
class CameraLabelerDrawerAttribute : Attribute
{
public CameraLabelerDrawerAttribute(Type targetLabelerType)
{
this.targetLabelerType = targetLabelerType;
}
public Type targetLabelerType;
}
[CameraLabelerDrawer(typeof(CameraLabeler))]
public class CameraLabelerDrawer
{
public CameraLabeler CameraLabeler { get; internal set; }
class Styles
{
public static float defaultLineSpace = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
public static float reorderableListHandleIndentWidth = 12;
public static GUIContent enabled = new GUIContent("Enabled", "Enable or Disable the custom pass");
}
bool firstTime = true;
// Serialized Properties
SerializedProperty m_Enabled;
SerializedProperty m_LabelerFoldout;
List<SerializedProperty> m_CustomPassUserProperties = new List<SerializedProperty>();
void FetchProperties(SerializedProperty property)
{
m_Enabled = property.FindPropertyRelative(nameof(CameraLabeler.enabled));
m_LabelerFoldout = property.FindPropertyRelative(nameof(CameraLabeler.foldout));
}
void LoadUserProperties(SerializedProperty customPass)
{
foreach (var field in CameraLabeler.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
var serializeField = field.GetCustomAttribute<SerializeField>();
var hideInInspector = field.GetCustomAttribute<HideInInspector>();
var nonSerialized = field.GetCustomAttribute<NonSerializedAttribute>();
if (nonSerialized != null || hideInInspector != null)
continue;
if (!field.IsPublic && serializeField == null)
continue;
if (field.Name == nameof(CameraLabeler.enabled) || field.Name == nameof(CameraLabeler.foldout))
continue;
var prop = customPass.FindPropertyRelative(field.Name);
if (prop != null)
m_CustomPassUserProperties.Add(prop);
}
}
void InitInternal(SerializedProperty customPass)
{
FetchProperties(customPass);
Initialize(customPass);
LoadUserProperties(customPass);
firstTime = false;
}
/// <summary>
/// Use this function to initialize the local SerializedProperty you will use in your pass.
/// </summary>
/// <param name="customPass">Your custom pass instance represented as a SerializedProperty</param>
protected virtual void Initialize(SerializedProperty customPass) {}
internal void OnGUI(Rect rect, SerializedProperty property)
{
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.BeginChangeCheck();
if (firstTime)
InitInternal(property);
DoHeaderGUI(ref rect);
if (m_LabelerFoldout.boolValue)
{
EditorGUI.EndChangeCheck();
return;
}
EditorGUI.BeginDisabledGroup(!m_Enabled.boolValue);
{
DoPassGUI(property, rect);
}
EditorGUI.EndDisabledGroup();
if (EditorGUI.EndChangeCheck())
property.serializedObject.ApplyModifiedProperties();
}
/// <summary>
/// Implement this function to draw your custom GUI.
/// </summary>
/// <param name="customPass">Your custom pass instance represented as a SerializedProperty</param>
/// <param name="rect">space available for you to draw the UI</param>
protected virtual void DoPassGUI(SerializedProperty customPass, Rect rect)
{
foreach (var prop in m_CustomPassUserProperties)
{
EditorGUI.PropertyField(rect, prop);
rect.y += Styles.defaultLineSpace;
}
}
void DoHeaderGUI(ref Rect rect)
{
var enabledSize = EditorStyles.boldLabel.CalcSize(Styles.enabled) + new Vector2(Styles.reorderableListHandleIndentWidth, 0);
var headerRect = new Rect(rect.x + Styles.reorderableListHandleIndentWidth,
rect.y + EditorGUIUtility.standardVerticalSpacing,
rect.width - Styles.reorderableListHandleIndentWidth - enabledSize.x,
EditorGUIUtility.singleLineHeight);
rect.y += Styles.defaultLineSpace;
var enabledRect = headerRect;
enabledRect.x = rect.xMax - enabledSize.x;
enabledRect.width = enabledSize.x;
m_LabelerFoldout.boolValue = EditorGUI.Foldout(headerRect, m_LabelerFoldout.boolValue, $"{CameraLabeler.GetType().Name}", true, EditorStyles.boldLabel);
EditorGUIUtility.labelWidth = enabledRect.width - 14;
m_Enabled.boolValue = EditorGUI.Toggle(enabledRect, Styles.enabled, m_Enabled.boolValue);
EditorGUIUtility.labelWidth = 0;
}
/// <summary>
/// Implement this functions if you implement DoPassGUI. The result of this function must match the number of lines displayed in your custom GUI.
/// Note that this height can be dynamic.
/// </summary>
/// <param name="customPass">Your custom pass instance represented as a SerializedProperty</param>
/// <returns>The height in pixels of tour custom pass GUI</returns>
protected virtual float GetHeight(SerializedProperty customPass)
{
float height = 0;
foreach (var prop in m_CustomPassUserProperties)
{
height += EditorGUI.GetPropertyHeight(prop);
height += EditorGUIUtility.standardVerticalSpacing;
}
return height;
}
internal float GetElementHeight(SerializedProperty property)
{
float height = Styles.defaultLineSpace;
if (firstTime)
InitInternal(property);
if (m_LabelerFoldout.boolValue)
return height;
return height + GetHeight(property);
}
}
}

3
com.unity.perception/Runtime/GroundTruth/Labelers.meta


fileFormatVersion: 2
guid: 021a5e99d6664a188c5c78599587a08c
timeCreated: 1589374593

108
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs


using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth
{
[Serializable]
public struct IdLabelEntry : ILabelEntry
{
string ILabelEntry.label => this.label;
public string label;
public int id;
}
/// <summary>
/// A definition for how a <see cref="Labeling"/> should be resolved to a single label and id for ground truth generation.
/// </summary>
[CreateAssetMenu(fileName = "IdLabelingConfiguration", menuName = "Perception/ID Labeling Configuration", order = 1)]
public class IdLabelConfig : LabelingConfiguration2<IdLabelEntry>
{
}
[Serializable]
public struct SemanticSegmentationLabelEntry : ILabelEntry
{
string ILabelEntry.label => this.label;
public string label;
public int pixelValue;
}
/// <summary>
/// A definition for how a <see cref="Labeling"/> should be resolved to a single label and id for ground truth generation.
/// </summary>
[CreateAssetMenu(fileName = "SemanticSegmentationLabelingConfiguration", menuName = "Perception/Semantic Segmentation Label Config", order = 1)]
public class SemanticSegmentationLabelConfig : LabelingConfiguration2<SemanticSegmentationLabelEntry>
{
/// <summary>
/// Whether the inspector will auto-assign ids based on the id of the first element.
/// </summary>
public bool AutoAssignIds = true;
/// <summary>
/// Whether the inspector will start label ids at zero or one when <see cref="AutoAssignIds"/> is enabled.
/// </summary>
public StartingLabelId StartingLabelId = StartingLabelId.One;
}
/// <summary>
/// A definition for how a <see cref="Labeling"/> should be resolved to a single label and id for ground truth generation.
/// </summary>
[CreateAssetMenu(fileName = "LabelingConfiguration2", menuName = "Perception/Labeling Configuration 2", order = 1)]
public class LabelingConfiguration2<T> : ScriptableObject where T : ILabelEntry
{
/// <summary>
/// A sequence of <see cref="LabelEntry"/> which defines the labels relevant for this configuration and their values.
/// </summary>
[FormerlySerializedAs("LabelingConfigurations")]
[SerializeField]
public List<T> LabelEntries = new List<T>();
/// <summary>
/// Attempts to find the matching index in <see cref="LabelEntries"/> for the given <see cref="Labeling"/>.
/// </summary>
/// <remarks>
/// The matching index is the first class name in the given Labeling which matches an entry in <see cref="LabelEntries"/>.
/// </remarks>
/// <param name="labeling">The <see cref="Labeling"/> to match </param>
/// <param name="labelEntry">When this method returns, contains the matching <see cref="LabelEntry"/>, or <code>default</code> if no match was found.</param>
/// <returns>Returns true if a match was found. False if not.</returns>
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out T labelEntry)
{
return TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _);
}
/// <summary>
/// Attempts to find the matching index in <see cref="LabelEntries"/> for the given <see cref="Labeling"/>.
/// </summary>
/// <remarks>
/// The matching index is the first class name in the given Labeling which matches an entry in <see cref="LabelEntries"/>.
/// </remarks>
/// <param name="labeling">The <see cref="Labeling"/> to match </param>
/// <param name="labelEntry">When this method returns, contains the matching <see cref="LabelEntry"/>, or <code>default</code> if no match was found.</param>
/// <param name="labelEntryIndex">When this method returns, contains the index of the matching <see cref="LabelEntry"/>, or <code>-1</code> if no match was found.</param>
/// <returns>Returns true if a match was found. False if not.</returns>
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out T labelEntry, out int labelEntryIndex)
{
foreach (var labelingClass in labeling.labels)
{
for (var i = 0; i < LabelEntries.Count; i++)
{
var entry = LabelEntries[i];
if (string.Equals(entry, labelingClass))
{
labelEntry = LabelEntries[i];
labelEntryIndex = i;
return true;
}
}
}
labelEntryIndex = -1;
labelEntry = default;
return false;
}
}
public interface ILabelEntry
{
string label { get; }
}
}

3
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration2.cs.meta


fileFormatVersion: 2
guid: ef6f93cc88964359a505ccc75835fd5a
timeCreated: 1589581072

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


fileFormatVersion: 2
guid: d0127208de324c00a881af84cdd63da3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs


using System;
namespace UnityEngine.Perception.GroundTruth {
public class InstanceSegmentationLabeler : CameraLabeler
{
public bool saveImages = false;
public string annotationId = "E657461D-B950-42E1-8141-BEC9B4810241";
}
}

11
com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs.meta


fileFormatVersion: 2
guid: 43085b9d882c415b90fb9ebe4d765f26
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs


using System;
namespace UnityEngine.Perception.GroundTruth
{
[Serializable]
public class RenderedObjectInfoLabeler : CameraLabeler
{
public string annotationId = "F9F22E05-443F-4602-A422-EBE4EA9B55CB";
public LabelingConfiguration labelingConfiguration;
}
}

11
com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs.meta


fileFormatVersion: 2
guid: c2fcc6ce8ec34a44ae0f1679f25b6fb4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs


using System;
namespace UnityEngine.Perception.GroundTruth {
[Serializable]
public class SemanticSegmentationLabeler : CameraLabeler
{
public string annotationId = "12F94D8D-5425-4DEB-9B21-5E53AD957D66";
public SemanticSegmentationLabelConfig labelConfig;
}
}

11
com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs.meta


fileFormatVersion: 2
guid: 6c08fb5eff78425db5567cf66f9cb3fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System;
using System.Linq;
namespace UnityEngine.Perception.GroundTruth {
[Serializable]
public class BoundingBoxLabeler : CameraLabeler
{
public string annotationId = "F9F22E05-443F-4602-A422-EBE4EA9B55CB";
public LabelingConfiguration labelingConfiguration;
AnnotationDefinition m_BoundingBoxAnnotationDefinition;
public override void Setup()
{
var labelingMetricSpec = labelingConfiguration.GetAnnotationSpecification();
m_BoundingBoxAnnotationDefinition = SimulationManager.RegisterAnnotationDefinition("bounding box", labelingMetricSpec, "Bounding box for each labeled object visible to the sensor", id: new Guid(annotationId));
}
public override void Update()
{
//BoundingBoxAsyncMetric = SensorHandle.ReportAnnotationAsync(m_BoundingBoxAnnotationDefinition);
}
public override void OnInstanceSegmentationRead(int frameCount)
{
}
}
}
正在加载...
取消
保存