浏览代码

Merge master to 0.8.0 (#265)

* addressed feedback

- new test for keypoint labeler
- added ClearMaterialProperties method to IGroundTruthGenerator
- Other fixes

* docs clarification

* Update CHANGELOG.md

* added missing interface method implementation for HDRP

* Amending dataset schema to describe correct coordinate system (#255)

The summary for the 3d bounding box states the coordinates are from the sensor's reference frame, but the string for the translational component says it's global.  I *think* this is just a typo in the doc, so correcting the description to match the summary for this type of entry.

* Adding supported version badges (#256)

* Cloud rendering support (#227)

* Adding support for cloud rendering in the run simulation window

* minor fixes

* minor update

* Update BoundingBox3DLabeler.cs

* Update BoundingBox3DLabeler.cs

* inner mesh scaling and disabled renderes

* A fix that prevents normal sampler returning values outsi...
/0.8.0-preview.1_staging
GitHub 4 年前
当前提交
cabe7c5a
共有 20 个文件被更改,包括 312 次插入163 次删除
  1. 6
      .github/pull_request_template.md
  2. 3
      README.md
  3. 4
      TestProjects/PerceptionHDRP/Packages/packages-lock.json
  4. 7
      com.unity.perception/CHANGELOG.md
  5. 2
      com.unity.perception/Documentation~/Schema/Synthetic_Dataset_Schema.md
  6. 15
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  7. 19
      com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
  8. 50
      com.unity.perception/Runtime/GroundTruth/InstanceIdToColorMapping.cs
  9. 7
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs
  10. 121
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  11. 30
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs
  12. 33
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs
  13. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs
  14. 10
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs
  15. 5
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs
  16. 23
      com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs
  17. 3
      com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs
  18. 2
      com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
  19. 51
      com.unity.perception/Tests/Runtime/GroundTruthTests/InstanceIdToColorMappingTests.cs
  20. 81
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

6
.github/pull_request_template.md


# Peer Review Information:
Information on any code, feature, documentation changes here
**Editor Version Target (i.e. 19.3, 20.1)**: 2019.3
**Editor Version Target**: 2019.4
## Dev Testing:
**Tests Added**:

**At Risk Areas**:
**Notes + Expectations**:
- [ ] - Updated test rail

3
README.md


[![license badge](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE.md)
<img src="https://img.shields.io/badge/unity-2019.4-green.svg?style=flat-square" alt="unity 2019.4">
<img src="https://img.shields.io/badge/unity-2020.2-green.svg?style=flat-square" alt="unity 2020.2">
> com.unity.perception is in active development. Its features and API are subject to significant change as development progresses.

4
TestProjects/PerceptionHDRP/Packages/packages-lock.json


"com.unity.collections": "0.9.0-preview.6",
"com.unity.nuget.newtonsoft-json": "1.1.2",
"com.unity.render-pipelines.core": "7.1.6",
"com.unity.simulation.capture": "0.0.10-preview.19",
"com.unity.simulation.capture": "0.0.10-preview.20",
"com.unity.simulation.client": "0.0.10-preview.10",
"com.unity.simulation.core": "0.0.10-preview.22"
}

"url": "https://packages.unity.com"
},
"com.unity.simulation.capture": {
"version": "0.0.10-preview.19",
"version": "0.0.10-preview.20",
"depth": 1,
"source": "registry",
"dependencies": {

7
com.unity.perception/CHANGELOG.md


### Changed
Expanded documentation on the Keypoint Labeler
Updated Keypoint Labeler logic to only report keypoints for visible objects by default
Increased color variety in instance segmentation images
### Deprecated

Fixed compiler warnings in projects with HDRP on 2020.1 and later
Fixed a bug in the Normal Sampler where it would return values less than the passed in minimum value, or greater than the passed in maximum value, for random values very close to 0 or 1 respectively.
## [0.8.0-preview.2] - 2021-03-15

`ScenarioBase`'s `Awake()`, `Start()`, and `Update()` functions are now private. If you previously used these, replace the usages with `OnAwake()`, `OnStart()`, and `OnUpdate()`.
The interface `IGroundTruthGenerator` now contains a new method named `ClearMaterialProperties` for disabling ground truth generation on a `Labeling` component or its associated `MaterialPropertyBlock`. Update your implementing classes to including this method.
### Known Issues

Improved UI for `KeypointTemplate` and added useful default colors for keypoint and skeleton definitions.
Added the ability to switch ground-truth labeling on or off for an object at runtime by enabling or disabling its `Labeling` component.
Added the ability to switch ground truth generation on or off for an object at runtime by enabling or disabling its `Labeling` component. A new method named `ClearMaterialProperties()` in `IGroundTruthGenerator` handles this functionality.
### Changed

2
com.unity.perception/Documentation~/Schema/Synthetic_Dataset_Schema.md


label_id: <int> -- Integer identifier of the label
label_name: <str> -- String identifier of the label
instance_id: <str> -- UUID of the instance.
translation { -- 3d bounding box's center location in meters with respect to global coordinate system.
translation { -- 3d bounding box's center location in meters with respect to the sensor's coordinate system
x: <float> -- The x coordinate
y: <float> -- The y coordinate
z: <float> -- The z coordinate

15
com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs


Label m_PrevExecutionIdLabel;
RunParameters m_RunParameters;
const string m_SupportedGPUString = "NVIDIA";
[MenuItem("Window/Run in Unity Simulation")]
static void ShowWindow()
{

async void RunInUnitySimulation()
{
#if PLATFORM_CLOUD_RENDERING
if (!m_SysParamDefinitions[m_SysParamIndex].description.Contains(m_SupportedGPUString))
{
EditorUtility.DisplayDialog("Unsupported Sysparam",
"The current selection of the Sysparam " + m_SysParamDefinitions[m_SysParamIndex].description +
" is not supported by this build target. Please select a sysparam with GPU", "Ok");
return;
}
#endif
m_RunParameters = new RunParameters
{
runName = m_RunNameField.value,

{
scenes = new[] { m_RunParameters.currentOpenScenePath },
locationPathName = Path.Combine(projectBuildDirectory, $"{m_RunParameters.runName}.x86_64"),
#if PLATFORM_CLOUD_RENDERING
target = BuildTarget.CloudRendering,
#else
#endif
};
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
var summary = report.summary;

19
com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs


public interface IGroundTruthGenerator
{
/// <summary>
/// Called by <see cref="LabelManager"/> when first registered or when a Labeling is created at runtime.
/// Enables ground truth generation for a <see cref="Labeling"/> component or its associated <see cref="MaterialPropertyBlock"/>. This function is called by <see cref="LabelManager"/> when a <see cref="Labeling"/> component is registered, created, or enabled.
/// <param name="mpb">The MaterialPropertyBlock for the given meshRenderer. Can be used to set properties for custom rendering.</param>
/// <param name="renderer">The Renderer under the given Labeling.</param>
/// <param name="labeling">The Labeling component created</param>
/// <param name="instanceId">The instanceId assigned to the given Labeling instance.</param>
/// <param name="mpb">The <see cref="MaterialPropertyBlock"/> for the given <see cref="MeshRenderer"/>. Can be used to set properties for custom rendering.</param>
/// <param name="renderer">The <see cref="Renderer"/> under the given <see cref="LabelManager"/>.</param>
/// <param name="labeling">The <see cref="LabelManager"/> component that was registered, created, or enabled</param>
/// <param name="instanceId">The instanceId assigned to the given <see cref="LabelManager"/> instance.</param>
/// <summary>
/// Disables ground truth generation for a <see cref="Labeling"/> component or its associated <see cref="MaterialPropertyBlock"/>. This function is called by <see cref="LabelManager"/> when a <see cref="Labeling"/> component is disabled.
/// </summary>
/// <param name="mpb">The <see cref="MaterialPropertyBlock"/> for the given <see cref="MeshRenderer"/>. Can be used to set properties for custom rendering.</param>
/// <param name="renderer">The <see cref="Renderer"/> under the given <see cref="LabelManager"/>.</param>
/// <param name="labeling">The <see cref="LabelManager"/> component for which ground-truth generation should stop.</param>
/// <param name="instanceId">The instanceId assigned to the given <see cref="LabelManager"/> instance.</param>
void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId);
}
}

50
com.unity.perception/Runtime/GroundTruth/InstanceIdToColorMapping.cs


using System;
using System.Collections.Generic;
using Unity.Profiling;
namespace UnityEngine.Perception.GroundTruth
{

/// </summary>
public const uint maxId = uint.MaxValue - ((256 * 256 * 256) * 2) + k_HslCount;
static Dictionary<uint, uint> s_IdToColorCache;
static uint[] s_IdToColorCache;
const uint k_HslCount = 64;
const uint k_HslCount = 1024;
public static readonly Color32 invalidColor = new Color(0, 0, 0, 255);
const int k_HuesInEachValue = 30;
const int k_HuesInEachValue = 64;
const uint k_Values = k_HslCount / k_HuesInEachValue;
/// <summary>
/// The color returned when an instanceId is not mapped to any color, and for clearing ground truth material properties on a <see cref="MaterialPropertyBlock"/>.
/// </summary>
public static readonly Color32 invalidColor = new Color(0, 0, 0, 255);
static void InitializeMaps()
private static ProfilerMarker k_InitializeMapsMarker = new ProfilerMarker(nameof(InitializeMaps));
internal static void InitializeMaps()
s_IdToColorCache = new Dictionary<uint, uint>();
s_ColorToIdCache = new Dictionary<uint, uint>();
using (k_InitializeMapsMarker.Auto())
{
s_IdToColorCache = new uint[k_HslCount + 1];
s_ColorToIdCache = new Dictionary<uint, uint>();
s_IdToColorCache[0] = k_InvalidPackedColor;
s_IdToColorCache[k_InvalidPackedColor] = 0;
s_IdToColorCache[0] = k_InvalidPackedColor;
s_ColorToIdCache[k_InvalidPackedColor] = 0;
for (uint i = 1; i <= k_HslCount; i++)
{
var color = GenerateHSLValueForId(i);
s_IdToColorCache[i] = color;
s_ColorToIdCache[color] = i;
for (uint i = 1; i <= k_HslCount; i++)
{
var color = GenerateHSLValueForId(i);
s_IdToColorCache[i] = color;
s_ColorToIdCache.Add(color, i);
}
}
}

var ratio = count * k_GoldenRatio;
// assign hue based on golden ratio
var hueId = count % k_HuesInEachValue;
var ratio = hueId * k_GoldenRatio;
count /= k_HuesInEachValue;
ratio = count * k_GoldenRatio;
var value = 1 - (ratio - Mathf.Floor(ratio));
var valueId = count / k_HuesInEachValue;
// avoid value 0
var value = 1 - (float)valueId / (k_Values + 1);
var color = (Color32)Color.HSVToRGB(hue, 1f, value);
color.a = 255;

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


// Need to convert all bounds into labeling mesh space...
foreach (var mesh in meshFilters)
{
if (!mesh.GetComponent<Renderer>().enabled)
continue;
var currentTransform = mesh.gameObject.transform;
// Grab the bounds of the game object from the mesh, although these bounds are axis-aligned,
// they are axis-aligned with respect to the current component's coordinate space. This, in theory

// Apply the transformations on this object until we reach the labeled transform
while (currentTransform != labelTransform)
{
transformedBounds.center = Vector3.Scale(transformedBounds.center, currentTransform.localScale);
transformedBounds.center = currentTransform.localRotation * transformedBounds.center;
transformedBounds.center += currentTransform.localPosition;
transformedBounds.extents = Vector3.Scale(transformedBounds.extents, currentTransform.localScale);
transformedRotation *= currentTransform.localRotation;

// Convert the combined bounds into world space
combinedBounds.center = labelTransform.TransformPoint(combinedBounds.center);
combinedBounds.extents = Vector3.Scale(combinedBounds.extents, labelTransform.localScale);
combinedBounds.extents = Vector3.Scale(combinedBounds.extents, labelTransform.lossyScale);
// Now convert all points into camera's space
var cameraCenter = cameraTransform.InverseTransformPoint(combinedBounds.center);

121
com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs


}
}
}
}
private void OnRenderedObjectInfoReadback(int frameCount, NativeArray<RenderedObjectInfo> objectInfos)
{

{
include = true;
break;
}
}
}
}
if (include)
m_KeypointEntriesToReport.Add(entry);
}

void ProcessLabel(Labeling labeledEntity)
{
if (idLabelConfig.TryGetLabelEntryFromInstanceId(labeledEntity.instanceId, out var labelEntry))
if (!idLabelConfig.TryGetLabelEntryFromInstanceId(labeledEntity.instanceId, out var labelEntry))
return;
// Cache out the data of a labeled game object the first time we see it, this will
// save performance each frame. Also checks to see if a labeled game object can be annotated.
if (!m_KnownStatus.ContainsKey(labeledEntity.instanceId))
// Cache out the data of a labeled game object the first time we see it, this will
// save performance each frame. Also checks to see if a labeled game object can be annotated.
if (!m_KnownStatus.ContainsKey(labeledEntity.instanceId))
var cached = new CachedData()
var cached = new CachedData()
{
status = false,
animator = null,
keypoints = new KeypointEntry(),
overrides = new List<(JointLabel, int)>()
};
status = false,
animator = null,
keypoints = new KeypointEntry(),
overrides = new List<(JointLabel, int)>()
};
var entityGameObject = labeledEntity.gameObject;
var entityGameObject = labeledEntity.gameObject;
cached.keypoints.instance_id = labeledEntity.instanceId;
cached.keypoints.label_id = labelEntry.id;
cached.keypoints.template_guid = activeTemplate.templateID;
cached.keypoints.instance_id = labeledEntity.instanceId;
cached.keypoints.label_id = labelEntry.id;
cached.keypoints.template_guid = activeTemplate.templateID;
cached.keypoints.keypoints = new Keypoint[activeTemplate.keypoints.Length];
for (var i = 0; i < cached.keypoints.keypoints.Length; i++)
{
cached.keypoints.keypoints[i] = new Keypoint { index = i, state = 0 };
}
cached.keypoints.keypoints = new Keypoint[activeTemplate.keypoints.Length];
for (var i = 0; i < cached.keypoints.keypoints.Length; i++)
{
cached.keypoints.keypoints[i] = new Keypoint { index = i, state = 0 };
}
var animator = entityGameObject.transform.GetComponentInChildren<Animator>();
if (animator != null)
{
cached.animator = animator;
cached.status = true;
}
var animator = entityGameObject.transform.GetComponentInChildren<Animator>();
if (animator != null)
foreach (var joint in entityGameObject.transform.GetComponentsInChildren<JointLabel>())
{
if (TryToGetTemplateIndexForJoint(activeTemplate, joint, out var idx))
cached.animator = animator;
cached.overrides.Add((joint, idx));
}
foreach (var joint in entityGameObject.transform.GetComponentsInChildren<JointLabel>())
{
if (TryToGetTemplateIndexForJoint(activeTemplate, joint, out var idx))
{
cached.overrides.Add((joint, idx));
cached.status = true;
}
}
m_KnownStatus[labeledEntity.instanceId] = cached;
}
m_KnownStatus[labeledEntity.instanceId] = cached;
}
var cachedData = m_KnownStatus[labeledEntity.instanceId];
var cachedData = m_KnownStatus[labeledEntity.instanceId];
if (cachedData.status)
{
var animator = cachedData.animator;
var keypoints = cachedData.keypoints.keypoints;
if (cachedData.status)
// Go through all of the rig keypoints and get their location
for (var i = 0; i < activeTemplate.keypoints.Length; i++)
var animator = cachedData.animator;
var keypoints = cachedData.keypoints.keypoints;
// Go through all of the rig keypoints and get their location
for (var i = 0; i < activeTemplate.keypoints.Length; i++)
var pt = activeTemplate.keypoints[i];
if (pt.associateToRig)
var pt = activeTemplate.keypoints[i];
if (pt.associateToRig)
var bone = animator.GetBoneTransform(pt.rigLabel);
if (bone != null)
var bone = animator.GetBoneTransform(pt.rigLabel);
if (bone != null)
{
}
}
// Go through all of the additional or override points defined by joint labels and get
// their locations
foreach (var (joint, idx) in cachedData.overrides)
{
// Go through all of the additional or override points defined by joint labels and get
// their locations
foreach (var (joint, idx) in cachedData.overrides)
{
}
cachedData.keypoints.pose = "unset";
}
if (cachedData.animator != null)
{
cachedData.keypoints.pose = GetPose(cachedData.animator);
}
cachedData.keypoints.pose = "unset";
m_AsyncAnnotations[m_CurrentFrame].keypoints[labeledEntity.instanceId] = cachedData.keypoints;
if (cachedData.animator != null)
{
cachedData.keypoints.pose = GetPose(cachedData.animator);
m_AsyncAnnotations[m_CurrentFrame].keypoints[labeledEntity.instanceId] = cachedData.keypoints;
}
}

30
com.unity.perception/Runtime/GroundTruth/Labeling/LabelEntryMatchCache.cs


if (m_IdLabelConfig.TryGetMatchingConfigurationEntry(labeling, out _, out var index))
{
Debug.Assert(index < k_DefaultValue, "Too many entries in the label config");
if (labeling.enabled)
{
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
{
var oldLength = m_InstanceIdToLabelEntryIndexLookup.Length;
m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
for (var i = oldLength; i < instanceId; i++)
m_InstanceIdToLabelEntryIndexLookup[i] = k_DefaultValue;
}
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index;
}
else if (m_InstanceIdToLabelEntryIndexLookup.Length > instanceId)
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = k_DefaultValue;
var oldLength = m_InstanceIdToLabelEntryIndexLookup.Length;
m_InstanceIdToLabelEntryIndexLookup.Resize((int)instanceId + 1, NativeArrayOptions.ClearMemory);
for (var i = oldLength; i < instanceId; i++)
m_InstanceIdToLabelEntryIndexLookup[i] = k_DefaultValue;
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = (ushort)index;
}
else if (m_InstanceIdToLabelEntryIndexLookup.Length > instanceId)
{

/// <inheritdoc/>
void IGroundTruthGenerator.ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
{
if (m_InstanceIdToLabelEntryIndexLookup.Length > instanceId)
{
m_InstanceIdToLabelEntryIndexLookup[(int)instanceId] = k_DefaultValue;
}
}
/// <inheritdoc/>
public void Dispose()

33
com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs


{
terrain.GetSplatMaterialPropertyBlock(mpb);
foreach (var pass in m_ActiveGenerators)
pass.SetupMaterialProperties(mpb, null, labeling, instanceId);
{
if (labeling.enabled)
{
pass.SetupMaterialProperties(mpb, null, labeling, instanceId);
}
else
{
pass.ClearMaterialProperties(mpb, null, labeling, instanceId);
}
}
terrain.SetSplatMaterialPropertyBlock(mpb);
}

{
renderer.GetPropertyBlock(mpb);
foreach (var pass in m_ActiveGenerators)
pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
{
if (labeling.enabled)
{
pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
}
else
{
pass.ClearMaterialProperties(mpb, renderer, labeling, instanceId);
}
}
renderer.SetPropertyBlock(mpb);

if (!mpb.isEmpty)
{
foreach (var pass in m_ActiveGenerators)
pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
{
if (labeling.enabled)
{
pass.SetupMaterialProperties(mpb, renderer, labeling, instanceId);
}
else
{
pass.ClearMaterialProperties(mpb, renderer, labeling, instanceId);
}
}
renderer.SetPropertyBlock(mpb, i);
}

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/GroundTruthCrossPipelinePass.cs


public abstract void SetupMaterialProperties(
MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId);
public abstract void ClearMaterialProperties(
MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId);
}
}

10
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/InstanceSegmentationCrossPipelinePass.cs


if (!found)
Debug.LogError($"Could not get a unique color for {instanceId}");
if (labeling.enabled)
mpb.SetVector(k_SegmentationIdProperty, (Color)color);
else
mpb.SetVector(k_SegmentationIdProperty, (Color) InstanceIdToColorMapping.invalidColor);
mpb.SetVector(k_SegmentationIdProperty, (Color)color);
}
public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
{
mpb.SetVector(k_SegmentationIdProperty, (Color) InstanceIdToColorMapping.invalidColor);
}
}
}

5
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/LensDistortionCrossPipelinePass.cs


{
SetLensDistortionShaderParameters();
}
public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
{
SetLensDistortionShaderParameters();
}
}
}

23
com.unity.perception/Runtime/GroundTruth/RenderPasses/CrossPipelinePasses/SemanticSegmentationCrossPipelinePass.cs


{
var entry = new SemanticSegmentationLabelEntry();
var found = false;
if (labeling.enabled)
foreach (var l in m_LabelConfig.labelEntries)
foreach (var l in m_LabelConfig.labelEntries)
if (labeling.labels.Contains(l.label))
if (labeling.labels.Contains(l.label))
{
entry = l;
found = true;
break;
}
entry = l;
found = true;
break;
if (found)
mpb.SetVector(k_LabelingId, entry.color);
else
mpb.SetVector(k_LabelingId, Color.black);
mpb.SetVector(k_LabelingId, found ? entry.color : Color.black);
}
public override void ClearMaterialProperties(MaterialPropertyBlock mpb, Renderer renderer, Labeling labeling, uint instanceId)
{
mpb.SetVector(k_LabelingId, Color.black);
}
}
}

3
com.unity.perception/Runtime/GroundTruth/RenderPasses/HdrpPasses/GroundTruthPass.cs


public abstract void SetupMaterialProperties(
MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId);
public abstract void ClearMaterialProperties(
MaterialPropertyBlock mpb, Renderer meshRenderer, Labeling labeling, uint instanceId);
protected GroundTruthPass(Camera targetCamera)
{
this.targetCamera = targetCamera;

2
com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs


return min;
var stdTruncNorm = NormalCdfInverse(c);
return stdTruncNorm * stdDev + mean;
return math.clamp(stdTruncNorm * stdDev + mean, min, max);
}
/// <summary>

51
com.unity.perception/Tests/Runtime/GroundTruthTests/InstanceIdToColorMappingTests.cs


public class InstanceIdToColorMappingTests
{
[Test]
public void InitializeMaps_DoesNotThrow()
{
Assert.DoesNotThrow(InstanceIdToColorMapping.InitializeMaps);
}
[Test]
for (var i = 1u; i <= 64u; i++)
for (var i = 1u; i <= 1024u; i++)
Assert.IsTrue(InstanceIdToColorMapping.TryGetColorFromInstanceId(i, out var color));
Assert.IsTrue(InstanceIdToColorMapping.TryGetInstanceIdFromColor(color, out var id));
Assert.IsTrue(InstanceIdToColorMapping.TryGetColorFromInstanceId(i, out var color), $"Failed TryGetColorFromInstanceId on id {i}");
Assert.IsTrue(InstanceIdToColorMapping.TryGetInstanceIdFromColor(color, out var id), $"Failed TryGetInstanceIdFromColor on id {i}");
Assert.AreEqual(i, id);
color = InstanceIdToColorMapping.GetColorFromInstanceId(i);

[TestCase(4u,255,0,223,255)]
[TestCase(5u,0,255,212,255)]
[TestCase(6u,255,138,0,255)]
[TestCase(64u,195,0,75,255)]
[TestCase(65u,0,0,1,254)]
[TestCase(66u,0,0,2,254)]
[TestCase(64u + 256u,0,1,0,254)]
[TestCase(65u + 256u,0,1,1,254)]
[TestCase(64u + 65536u,1,0,0,254)]
[TestCase(16777216u,255,255,192,254)]
[TestCase(64u + 16777216u,0,0,0,253)]
[TestCase(64u + (16777216u * 2),0,0,0,252)]
[TestCase(1024u,30, 0, 11,255)]
[TestCase(1025u,0,0,1,254)]
[TestCase(1026u,0,0,2,254)]
[TestCase(1024u + 256u,0,1,0,254)]
[TestCase(1025u + 256u,0,1,1,254)]
[TestCase(1024u + 65536u,1,0,0,254)]
[TestCase(1024u + 16777216u,0,0,0,253)]
[TestCase(1024u + (16777216u * 2),0,0,0,252)]
Assert.AreEqual(color.r, r);
Assert.AreEqual(color.g, g);
Assert.AreEqual(color.b, b);
Assert.AreEqual(color.a, a);
var expected = new Color32(r, g, b, a);
Assert.AreEqual(expected, color);
Assert.AreEqual(color.r, r);
Assert.AreEqual(color.g, g);
Assert.AreEqual(color.b, b);
Assert.AreEqual(color.a, a);
Assert.AreEqual(expected, color);
id2 = InstanceIdToColorMapping.GetInstanceIdFromColor(color);
Assert.AreEqual(id, id2);

public void InstanceIdToColorMappingTests_GetCorrectValuesFor255()
{
var expectedColor = new Color(0, 0, 191, 254);
var expectedColor = new Color32(19, 210, 0, 255);
Assert.AreEqual(color.r, expectedColor.r);
Assert.AreEqual(color.g, expectedColor.g);
Assert.AreEqual(color.b, expectedColor.b);
Assert.AreEqual(color.a, expectedColor.a);
Assert.AreEqual(expectedColor, color);
Assert.AreEqual(color.r, expectedColor.r);
Assert.AreEqual(color.g, expectedColor.g);
Assert.AreEqual(color.b, expectedColor.b);
Assert.AreEqual(color.a, expectedColor.a);
Assert.AreEqual(expectedColor, color);
id2 = InstanceIdToColorMapping.GetInstanceIdFromColor(color);
Assert.AreEqual(255u, id2);
}

81
com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs


texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

}
[UnityTest]
public IEnumerator Keypoint_TestStaticLabeledCube_WithDisabledLabeling_AndSwitchingLabelingState()
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var texture = new RenderTexture(1024, 768, 16);
texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);
SetupCubeJoints(cube, template);
var labeling = cube.GetComponent<Labeling>();
cube.SetActive(true);
cam.SetActive(true);
AddTestObjectForCleanup(cam);
AddTestObjectForCleanup(cube);
labeling.enabled = false;
yield return null;
labeling.enabled = true;
yield return null;
labeling.enabled = false;
yield return null;
//force all async readbacks to complete
DestroyTestObject(cam);
texture.Release();
var testCase = incoming[0];
Assert.AreEqual(0, testCase.Count);
testCase = incoming[1];
Assert.AreEqual(1, testCase.Count);
var t = testCase.First();
Assert.NotNull(t);
Assert.AreEqual(1, t.instance_id);
Assert.AreEqual(1, t.label_id);
Assert.AreEqual(template.templateID.ToString(), t.template_guid);
Assert.AreEqual(9, t.keypoints.Length);
Assert.AreEqual(t.keypoints[0].x, t.keypoints[1].x);
Assert.AreEqual(t.keypoints[2].x, t.keypoints[3].x);
Assert.AreEqual(t.keypoints[4].x, t.keypoints[5].x);
Assert.AreEqual(t.keypoints[6].x, t.keypoints[7].x);
Assert.AreEqual(t.keypoints[0].y, t.keypoints[3].y);
Assert.AreEqual(t.keypoints[1].y, t.keypoints[2].y);
Assert.AreEqual(t.keypoints[4].y, t.keypoints[7].y);
Assert.AreEqual(t.keypoints[5].y, t.keypoints[6].y);
for (var i = 0; i < 9; i++) Assert.AreEqual(i, t.keypoints[i].index);
for (var i = 0; i < 8; i++) Assert.AreEqual(2, t.keypoints[i].state);
Assert.Zero(t.keypoints[8].state);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
testCase = incoming[2];
Assert.AreEqual(0, testCase.Count);
}
[UnityTest]
public IEnumerator Keypoint_TestAllOffScreen()
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();

{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
});
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
CreateFullyOccludedScene(template, cam);

var texture = new RenderTexture(1024, 768, 16);
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
}, texture);
var cameraComponent = cam.GetComponent<Camera>();

正在加载...
取消
保存