浏览代码

Initial commit of 3D bounding box data

/aisv565_bbox3d
Steven Borkman 4 年前
当前提交
8a9e5b0d
共有 10 个文件被更改,包括 284 次插入7 次删除
  1. 17
      TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
  2. 2
      com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs
  3. 4
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat
  4. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Resources/VisualizationUI.prefab
  5. 12
      com.unity.perception/Runtime/GroundTruth/IGroundTruthUpdater.cs
  6. 3
      com.unity.perception/Runtime/GroundTruth/IGroundTruthUpdater.cs.meta
  7. 185
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs
  8. 3
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs.meta
  9. 52
      com.unity.perception/Runtime/GroundTruth/Labelers/GroundTruthUpdateSystem.cs
  10. 11
      com.unity.perception/Runtime/GroundTruth/Labelers/GroundTruthUpdateSystem.cs.meta

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


- id: 1
- id: 2
- id: 3
- id: 4
showVisualizations: 1
references:
version: 1

enabled: 1
enabled: 0
objectCountMetricId: 51da3c27-369d-4929-aea6-d01614635ce2
m_LabelConfig: {fileID: 11400000, guid: cedcacfb1d9beb34fbbb231166c472fe,
type: 2}

data:
enabled: 1
enabled: 0
annotationId: f9f22e05-443f-4602-a422-ebe4ea9b55cb
idLabelConfig: {fileID: 11400000, guid: cedcacfb1d9beb34fbbb231166c472fe,
type: 2}

data:
enabled: 1
enabled: 0
objectInfoMetricId: 5ba92024-b3b7-41a7-9d3f-c03a6a8ddd01
idLabelConfig: {fileID: 11400000, guid: cedcacfb1d9beb34fbbb231166c472fe,
type: 2}

data:
enabled: 1
enabled: 0
00000004:
type: {class: BoundingBox3DLabeler, ns: UnityEngine.Perception.GroundTruth,
asm: Unity.Perception.Runtime}
data:
enabled: 1
annotationId: 0bfbe00d-00fa-4555-88d1-471b58449f5c
idLabelConfig: {fileID: 11400000, guid: cedcacfb1d9beb34fbbb231166c472fe,
type: 2}
--- !u!114 &963194231
MonoBehaviour:
m_ObjectHideFlags: 0

2
com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs


{
var labelSetupSystem = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>();
labelSetupSystem?.Activate(this);
m_IsActivated = true;
}
}

4
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Materials/SegmentationMaterial.mat


m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 1
- _BackTransparency: 0
- _BackTransparency: 0.048913043
- _Blend: 2
- _BlendOp: 0
- _BumpScale: 1

- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _SegmentTransparency: 0.8
- _SegmentTransparency: 0.61818254
- _Shininess: 0
- _Smoothness: 0.5
- _SmoothnessSource: 0

2
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/Resources/VisualizationUI.prefab


m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_PixelPerfect: 1
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0

12
com.unity.perception/Runtime/GroundTruth/IGroundTruthUpdater.cs


using System.Collections.Generic;
namespace UnityEngine.Perception.GroundTruth
{
public interface IGroundTruthUpdater
{
void OnBeginUpdate(int count);
void OnUpdateEntity(Labeling labeling, GroundTruthInfo groundTruthInfo);
void OnEndUpdate();
}
}

3
com.unity.perception/Runtime/GroundTruth/IGroundTruthUpdater.cs.meta


fileFormatVersion: 2
guid: c12f77198d5a412ba5b18034135d7846
timeCreated: 1596720636

185
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs


using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Unity.Entities;
using Unity.Profiling;
using Unity.Simulation;
using UnityEngine.Scripting;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace UnityEngine.Perception.GroundTruth
{
// ##### 3D bounding box
//
// A json file that stored collections of 3D bounding boxes.
// Each bounding box record maps a tuple of (instance, label) to translation, size and rotation that draws a 3D bounding box,
// as well as velocity and acceleration (optional) of the 3D bounding box.
// All location data is given with respect to the **sensor coordinate system**.
//
//
// bounding_box_3d {
// label_id: <int> -- Integer identifier of the label
// label_name: <str> -- String identifier of the label
// instance_id: <str> -- UUID of the instance.
// translation: <float, float, float> -- 3d bounding box's center location in meters as center_x, center_y, center_z with respect to global coordinate system.
// size: <float, float, float> -- 3d bounding box size in meters as width, length, height.
// rotation: <float, float, float, float> -- 3d bounding box orientation as quaternion: w, x, y, z.
// velocity: <float, float, float> -- 3d bounding box velocity in meters per second as v_x, v_y, v_z.
// acceleration: <float, float, float> [optional] -- 3d bounding box acceleration in meters per second^2 as a_x, a_y, a_z.
// }
public sealed class BoundingBox3DLabeler : CameraLabeler, IGroundTruthUpdater
{
public enum OutputMode
{
Verbose,
Kitti
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
abstract class BoxData
{
public int label_id;
public string label_name;
public uint instance_id;
}
class KittiData : BoxData
{
public float[] translation;
public float[] size;
public float yaw;
}
class VerboseData : BoxData
{
public float[] translation;
public float[] size;
public float[] rotation;
public float[] velocity; // TODO
public float[] acceleration; // TODO
}
static ProfilerMarker s_BoundingBoxCallback = new ProfilerMarker("OnBoundingBoxes3DReceived");
public string annotationId = "0bfbe00d-00fa-4555-88d1-471b58449f5c";
Dictionary<int, AsyncAnnotation> m_AsyncAnnotations;
AnnotationDefinition m_AnnotationDefinition;
BoxData[] m_BoundingBoxValues;
public OutputMode mode = OutputMode.Kitti;
public IdLabelConfig idLabelConfig;
protected override bool supportsVisualization => false;
public BoundingBox3DLabeler() {}
public BoundingBox3DLabeler(IdLabelConfig labelConfig)
{
this.idLabelConfig = labelConfig;
}
protected override void Setup()
{
if (idLabelConfig == null)
throw new InvalidOperationException("BoundingBox2DLabeler's idLabelConfig field must be assigned");
var updater = World.DefaultGameObjectInjectionWorld?.GetOrCreateSystem<GroundTruthUpdateSystem>();
updater?.Activate(this);
m_AsyncAnnotations = new Dictionary<int, AsyncAnnotation>();
m_AnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition("bounding box 3D", idLabelConfig.GetAnnotationSpecification(),
"Bounding box for each labeled object visible to the sensor", id: new Guid(annotationId));
}
protected override void Cleanup()
{
var updater = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthUpdateSystem>();
updater?.Deactivate(this);
}
int m_CurrentIndex;
int m_CurrentFrame;
public void OnBeginUpdate(int count)
{
if (m_BoundingBoxValues == null || count != m_BoundingBoxValues.Length)
m_BoundingBoxValues = new BoxData[count];
m_CurrentIndex = 0;
m_CurrentFrame = Time.frameCount;
}
BoxData Convert(IdLabelEntry label, uint instanceId, Renderer renderer, OutputMode outputMode)
{
return outputMode == OutputMode.Kitti ? ConvertToKitti(label, instanceId, renderer) : ConvertToVerboseData(label, instanceId, renderer);
}
BoxData ConvertToVerboseData(IdLabelEntry label, uint instanceId, Renderer renderer)
{
var camTrans = perceptionCamera.transform;
var bounds = renderer.bounds;
var localCenter = camTrans.InverseTransformPoint(bounds.center);
var localRotation = Quaternion.Inverse(renderer.transform.rotation) * camTrans.rotation;
return new VerboseData
{
label_id = label.id,
label_name = label.label,
instance_id = instanceId,
translation = new float[] { localCenter.x, localCenter.y, localCenter.z },
size = new float[] { bounds.extents.x, bounds.extents.y, bounds.extents.z },
rotation = new float[] { localRotation.w, localRotation.x, localRotation.y, localRotation.z },
velocity = null,
acceleration = null
};
}
BoxData ConvertToKitti(IdLabelEntry label, uint instanceId, Renderer renderer)
{
var camTrans = perceptionCamera.transform;
var bounds = renderer.bounds;
var localCenter = camTrans.InverseTransformPoint(bounds.center);
var localRotation = Quaternion.Inverse(renderer.transform.rotation) * camTrans.rotation;
return new KittiData
{
label_id = label.id,
label_name = label.label,
instance_id = instanceId,
translation = new float[] { localCenter.x, localCenter.y, localCenter.z },
size = new float[] { bounds.extents.x, bounds.extents.y, bounds.extents.z },
yaw = localRotation.eulerAngles.y,
};
}
public void OnUpdateEntity(Labeling labeling, GroundTruthInfo groundTruthInfo)
{
using (s_BoundingBoxCallback.Auto())
{
var renderer = labeling.gameObject.GetComponent<Renderer>();
if (renderer == null) return;
if (idLabelConfig.TryGetLabelEntryFromInstanceId(groundTruthInfo.instanceId, out var labelEntry))
{
m_BoundingBoxValues[m_CurrentIndex++] = Convert(labelEntry, groundTruthInfo.instanceId, renderer, mode);
}
}
}
public void OnEndUpdate()
{
perceptionCamera.SensorHandle.ReportAnnotationAsync(m_AnnotationDefinition).ReportValues(m_BoundingBoxValues);
}
}
}

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


fileFormatVersion: 2
guid: 8c19a08d5a9b48ac86e37d001ed7463f
timeCreated: 1596554354

52
com.unity.perception/Runtime/GroundTruth/Labelers/GroundTruthUpdateSystem.cs


using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Entities;
using Unity.Entities.UniversalDelegates;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEngine.Perception.GroundTruth
{
public class GroundTruthUpdateSystem : ComponentSystem
{
List<IGroundTruthUpdater> m_ActiveUpdaters = new List<IGroundTruthUpdater>();
public void Activate(IGroundTruthUpdater updater)
{
m_ActiveUpdaters.Add(updater);
}
public void Deactivate(IGroundTruthUpdater updater)
{
m_ActiveUpdaters.Remove(updater);
}
EntityQueryBuilder m_QueryBuilder;
EntityQuery m_Query;
protected override void OnCreate()
{
//These are here to inform the system runner the queries we are interested in. Without these calls, OnUpdate() might not be called
GetEntityQuery(ComponentType.ReadOnly<Labeling>());
m_QueryBuilder = Entities.WithAllReadOnly<Labeling, GroundTruthInfo>();
m_Query = m_QueryBuilder.ToEntityQuery();
}
protected override void OnUpdate()
{
var count = m_Query.CalculateEntityCount();
foreach (var updater in m_ActiveUpdaters)
{
updater.OnBeginUpdate(count);
m_QueryBuilder.ForEach((Entity entity, Labeling labeling, ref GroundTruthInfo groundTruth) =>
{
updater.OnUpdateEntity(labeling, groundTruth);
});
updater.OnEndUpdate();
}
}
}
}

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


fileFormatVersion: 2
guid: 2c6db511440054e7192d6fda3368019f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存