浏览代码

renamed in everything but tests and class filenames

/main
Mohsen Kamalzadeh 4 年前
当前提交
cc86748c
共有 4 个文件被更改,包括 58 次插入58 次删除
  1. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/CocoKeypointTemplate.asset
  2. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/JointLabel.cs
  3. 100
      com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointLabeler.cs
  4. 8
      com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointTemplate.cs

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($"{GetType().Name}'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
};
}

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


/// A definition of a keypoint (joint).
/// </summary>
[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;
public KeypointDefinition[] keypoints;
/// <summary>
/// Array of the <see cref="SkeletonDefinition"/> for the template.
/// </summary>

正在加载...
取消
保存