浏览代码

Merge pull request #206 from Unity-Technologies/rename_KeyPoint_to_Keypoint

Renamed KeyPoint to Keypoint
/main
GitHub 4 年前
当前提交
c13b382e
共有 8 个文件被更改,包括 87 次插入81 次删除
  1. 4
      com.unity.perception/CHANGELOG.md
  2. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/CocoKeypointTemplate.asset
  3. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/JointLabel.cs
  4. 100
      com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointLabeler.cs
  5. 10
      com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointTemplate.cs
  6. 46
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs
  7. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs.meta
  8. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

4
com.unity.perception/CHANGELOG.md


### Upgrade Notes
All appearances of the term `KeyPoint` have been renamed to `Keypoint`. Therefore, after upgrading to this version, if you have code that relies on any renamed types or names, make sure to alter your code to reflect the new names.
### Known Issues
### Added

Added new ScenarioBase virtual lifecycle hooks: OnAwake, OnStart, OnComplete, and OnIdle.
### Changed
Renamed all appearances of the term `KeyPoint` within types and names to `Keypoint`.
ScenarioBase's Awake, Start, and Update methods are now private. The newly added virtual lifecycle hooks are to be used as replacements.

2
com.unity.perception/Runtime/GroundTruth/Labelers/CocoKeypointTemplate.asset


templateName: Coco
jointTexture: {fileID: 2800000, guid: e381cbaaf29614168bafc8f7ec5dbfe9, type: 3}
skeletonTexture: {fileID: 2800000, guid: e381cbaaf29614168bafc8f7ec5dbfe9, type: 3}
keyPoints:
keypoints:
- label: nose
associateToRig: 0
rigLabel: 0

6
com.unity.perception/Runtime/GroundTruth/Labelers/JointLabel.cs


public class JointLabel : MonoBehaviour
{
/// <summary>
/// Maps this joint to a joint in a <see cref="KeyPointTemplate"/>
/// Maps this joint to a joint in a <see cref="KeypointTemplate"/>
/// The <see cref="KeyPointTemplate"/> that defines this joint.
/// The <see cref="KeypointTemplate"/> that defines this joint.
public KeyPointTemplate template;
public KeypointTemplate template;
/// <summary>
/// The name of the joint.
/// </summary>

100
com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointLabeler.cs


{
/// <summary>
/// Produces keypoint annotations for a humanoid model. This labeler supports generic
/// <see cref="KeyPointTemplate"/>. Template values are mapped to rigged
/// <see cref="KeypointTemplate"/>. Template values are mapped to rigged
public sealed class KeyPointLabeler : CameraLabeler
public sealed class KeypointLabeler : CameraLabeler
public KeyPointTemplate activeTemplate;
public KeypointTemplate activeTemplate;
/// <inheritdoc/>
public override string description

/// <summary>
/// Action that gets triggered when a new frame of key points are computed.
/// </summary>
public event Action<List<KeyPointEntry>> KeyPointsComputed;
public event Action<List<KeypointEntry>> KeypointsComputed;
/// is not valid until a <see cref="IdLabelConfig"/> and <see cref="KeyPointTemplate"/>
/// is not valid until a <see cref="IdLabelConfig"/> and <see cref="KeypointTemplate"/>
public KeyPointLabeler() { }
public KeypointLabeler() { }
/// <summary>
/// Creates a new key point labeler.

public KeyPointLabeler(IdLabelConfig config, KeyPointTemplate template)
public KeypointLabeler(IdLabelConfig config, KeypointTemplate template)
{
this.idLabelConfig = config;
this.activeTemplate = template;

protected override void Setup()
{
if (idLabelConfig == null)
throw new InvalidOperationException("KeyPointLabeler's idLabelConfig field must be assigned");
throw new InvalidOperationException($"{nameof(KeypointLabeler)}'s idLabelConfig field must be assigned");
m_AnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition("keypoints", new []{TemplateToJson(activeTemplate)},
"pixel coordinates of keypoints in a model, along with skeletal connectivity data", id: new Guid(annotationId));

m_KeyPointEntries = new List<KeyPointEntry>();
m_KeypointEntries = new List<KeypointEntry>();
// Texture to use in case the template does not contain a texture for the joints or the skeletal connections
m_MissingTexture = new Texture2D(1, 1);

var entities = m_EntityQuery.ToEntityArray(Allocator.TempJob);
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
m_KeyPointEntries.Clear();
m_KeypointEntries.Clear();
foreach (var entity in entities)
{

entities.Dispose();
KeyPointsComputed?.Invoke(m_KeyPointEntries);
reporter.ReportValues(m_KeyPointEntries);
KeypointsComputed?.Invoke(m_KeypointEntries);
reporter.ReportValues(m_KeypointEntries);
}
// ReSharper disable InconsistentNaming

/// Record storing all of the keypoint data of a labeled gameobject.
/// </summary>
[Serializable]
public class KeyPointEntry
public class KeypointEntry
{
/// <summary>
/// The label id of the entity

/// <summary>
/// Array of all of the keypoints
/// </summary>
public KeyPoint[] keypoints;
public Keypoint[] keypoints;
}
/// <summary>

public class KeyPoint
public class Keypoint
{
/// <summary>
/// The index of the keypoint in the template file

return pt;
}
List<KeyPointEntry> m_KeyPointEntries;
List<KeypointEntry> m_KeypointEntries;
public KeyPointEntry keyPoints;
public KeypointEntry keypoints;
bool TryToGetTemplateIndexForJoint(KeyPointTemplate template, JointLabel joint, out int index)
bool TryToGetTemplateIndexForJoint(KeypointTemplate template, JointLabel joint, out int index)
for (var i = 0; i < template.keyPoints.Length; i++)
for (var i = 0; i < template.keypoints.Length; i++)
if (template.keyPoints[i].label == jointTemplate.label)
if (template.keypoints[i].label == jointTemplate.label)
{
index = i;
return true;

{
if (template.template == activeTemplate)
{
if (activeTemplate.keyPoints.Any(i => i.label == template.label))
if (activeTemplate.keypoints.Any(i => i.label == template.label))
{
return true;
}

{
status = false,
animator = null,
keyPoints = new KeyPointEntry(),
keypoints = new KeypointEntry(),
overrides = new List<(JointLabel, int)>()
};

cached.keyPoints.instance_id = labeledEntity.instanceId;
cached.keyPoints.label_id = labelEntry.id;
cached.keyPoints.template_guid = activeTemplate.templateID.ToString();
cached.keypoints.instance_id = labeledEntity.instanceId;
cached.keypoints.label_id = labelEntry.id;
cached.keypoints.template_guid = activeTemplate.templateID.ToString();
cached.keyPoints.keypoints = new KeyPoint[activeTemplate.keyPoints.Length];
for (var i = 0; i < cached.keyPoints.keypoints.Length; i++)
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[i] = new Keypoint { index = i, state = 0 };
}
var animator = entityGameObject.transform.GetComponentInChildren<Animator>();

if (cachedData.status)
{
var animator = cachedData.animator;
var keyPoints = cachedData.keyPoints.keypoints;
var keypoints = cachedData.keypoints.keypoints;
for (var i = 0; i < activeTemplate.keyPoints.Length; i++)
for (var i = 0; i < activeTemplate.keypoints.Length; i++)
var pt = activeTemplate.keyPoints[i];
var pt = activeTemplate.keypoints[i];
if (pt.associateToRig)
{
var bone = animator.GetBoneTransform(pt.rigLabel);

keyPoints[i].index = i;
keyPoints[i].x = loc.x;
keyPoints[i].y = loc.y;
keyPoints[i].state = 2;
keypoints[i].index = i;
keypoints[i].x = loc.x;
keypoints[i].y = loc.y;
keypoints[i].state = 2;
}
}
}

foreach (var (joint, idx) in cachedData.overrides)
{
var loc = ConvertToScreenSpace(joint.transform.position);
keyPoints[idx].index = idx;
keyPoints[idx].x = loc.x;
keyPoints[idx].y = loc.y;
keyPoints[idx].state = 2;
keypoints[idx].index = idx;
keypoints[idx].x = loc.x;
keypoints[idx].y = loc.y;
keypoints[idx].state = 2;
cachedData.keyPoints.pose = "unset";
cachedData.keypoints.pose = "unset";
cachedData.keyPoints.pose = GetPose(cachedData.animator);
cachedData.keypoints.pose = GetPose(cachedData.animator);
m_KeyPointEntries.Add(cachedData.keyPoints);
m_KeypointEntries.Add(cachedData.keypoints);
}
}

var skeletonTexture = activeTemplate.skeletonTexture;
if (skeletonTexture == null) skeletonTexture = m_MissingTexture;
foreach (var entry in m_KeyPointEntries)
foreach (var entry in m_KeypointEntries)
{
foreach (var bone in activeTemplate.skeleton)
{

foreach (var keypoint in entry.keypoints)
{
if (keypoint.state != 0)
VisualizationHelper.DrawPoint(keypoint.x, keypoint.y, activeTemplate.keyPoints[keypoint.index].color, 8, jointTexture);
VisualizationHelper.DrawPoint(keypoint.x, keypoint.y, activeTemplate.keypoints[keypoint.index].color, 8, jointTexture);
}
}
}

}
[Serializable]
struct KeyPointJson
struct KeypointJson
{
public string template_id;
public string template_name;

// ReSharper restore InconsistentNaming
// ReSharper restore NotAccessedField.Local
KeyPointJson TemplateToJson(KeyPointTemplate input)
KeypointJson TemplateToJson(KeypointTemplate input)
var json = new KeyPointJson();
var json = new KeypointJson();
json.key_points = new JointJson[input.keyPoints.Length];
json.key_points = new JointJson[input.keypoints.Length];
for (var i = 0; i < input.keyPoints.Length; i++)
for (var i = 0; i < input.keypoints.Length; i++)
label = input.keyPoints[i].label,
label = input.keypoints[i].label,
index = i
};
}

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


using System;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth
{

[Serializable]
public class KeyPointDefinition
public class KeypointDefinition
{
/// <summary>
/// The name of the keypoint

/// Template used to define the keypoints of a humanoid asset.
/// </summary>
[CreateAssetMenu(fileName = "KeypointTemplate", menuName = "Perception/Keypoint Template", order = 2)]
public class KeyPointTemplate : ScriptableObject
public class KeypointTemplate : ScriptableObject
{
/// <summary>
/// The <see cref="Guid"/> of the template

/// </summary>
public Texture2D skeletonTexture;
/// <summary>
/// Array of <see cref="KeyPointDefinition"/> for the template.
/// Array of <see cref="KeypointDefinition"/> for the template.
public KeyPointDefinition[] keyPoints;
[FormerlySerializedAs("keyPoints")]
public KeypointDefinition[] keypoints;
/// <summary>
/// Array of the <see cref="SkeletonDefinition"/> for the template.
/// </summary>

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


namespace GroundTruthTests
{
[TestFixture]
public class KeyPointGroundTruthTests : GroundTruthTestBase
public class KeypointGroundTruthTests : GroundTruthTestBase
static GameObject SetupCamera(IdLabelConfig config, KeyPointTemplate template, Action<List<KeyPointLabeler.KeyPointEntry>> computeListener)
static GameObject SetupCamera(IdLabelConfig config, KeypointTemplate template, Action<List<KeypointLabeler.KeypointEntry>> computeListener)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);

var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.captureRgbImages = false;
var keyPointLabeler = new KeyPointLabeler(config, template);
var keyPointLabeler = new KeypointLabeler(config, template);
keyPointLabeler.KeyPointsComputed += computeListener;
keyPointLabeler.KeypointsComputed += computeListener;
perceptionCamera.AddLabeler(keyPointLabeler);

static KeyPointTemplate CreateTestTemplate(Guid guid, string label)
static KeypointTemplate CreateTestTemplate(Guid guid, string label)
var keyPoints = new[]
var keypoints = new[]
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
new KeyPointDefinition
new KeypointDefinition
{
label = "Center",
associateToRig = false,

},
};
var template = ScriptableObject.CreateInstance<KeyPointTemplate>();
var template = ScriptableObject.CreateInstance<KeypointTemplate>();
template.keyPoints = keyPoints;
template.keypoints = keypoints;
template.skeleton = skeleton;
return template;

Assert.AreEqual(template.templateName, label);
Assert.IsNull(template.jointTexture);
Assert.IsNull(template.skeletonTexture);
Assert.IsNotNull(template.keyPoints);
Assert.IsNotNull(template.keypoints);
Assert.AreEqual(template.keyPoints.Length, 9);
Assert.AreEqual(template.keypoints.Length, 9);
var k0 = template.keyPoints[0];
var k0 = template.keypoints[0];
Assert.NotNull(k0);
Assert.AreEqual(k0.label, "FrontLowerLeft");
Assert.False(k0.associateToRig);

return cfg;
}
static void SetupCubeJoint(GameObject cube, KeyPointTemplate template, string label, float x, float y, float z)
static void SetupCubeJoint(GameObject cube, KeypointTemplate template, string label, float x, float y, float z)
{
var joint = new GameObject();
joint.transform.parent = cube.transform;

jointLabel.templateInformation.Add(templateData);
}
static void SetupCubeJoints(GameObject cube, KeyPointTemplate template)
static void SetupCubeJoints(GameObject cube, KeypointTemplate template)
{
SetupCubeJoint(cube, template, "FrontLowerLeft", -0.5f, -0.5f, -0.5f);
SetupCubeJoint(cube, template, "FrontUpperLeft", -0.5f, 0.5f, -0.5f);

[UnityTest]
public IEnumerator Keypoint_TestStaticLabeledCube()
{
var incoming = new List<List<KeyPointLabeler.KeyPointEntry>>();
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var cam = SetupCamera(SetUpLabelConfig(), template, (data) =>

/com.unity.perception/Tests/Runtime/GroundTruthTests/KeyPointGroundTruthTests.cs.meta → /com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs.meta

/com.unity.perception/Tests/Runtime/GroundTruthTests/KeyPointGroundTruthTests.cs → /com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

正在加载...
取消
保存