浏览代码

Keypoints at leas partially working

/solo_support
Steve Borkman 3 年前
当前提交
406b7f70
共有 3 个文件被更改,包括 356 次插入163 次删除
  1. 37
      com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs
  2. 272
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  3. 210
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

37
com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs


case BoundingBox3DLabeler.BoundingBoxAnnotation bbox:
annotations.Add(ConvertAnnotation(frame, bbox));
break;
case KeypointLabeler.Annotation keypoint:
annotations.Add(ConvertAnnotation(frame, keypoint));
break;
}
}

["annotationId"] = metric.annotationId,
["description"] = metric.description
};
}
static JToken ConvertAnnotation(Frame frame, KeypointLabeler.Annotation keypoint)
{
var outBox = ToAnnotationHeader(frame, keypoint);
var values = new JArray();
foreach (var kp in keypoint.entries)
{
var keypoints = new JArray();
foreach (var k in kp.keypoints)
{
keypoints.Add(new JObject
{
["index"] = k.index,
["location"] = FromVector2(k.location),
["state"] = k.state
});
}
values.Add(new JObject
{
["instance_id"] = kp.instanceId,
["label_id"] = kp.labelId,
["template_guid"] = kp.templateGuid,
["pose"] = kp.pose,
["keypoints"] = keypoints
});
}
outBox["values"] = values;
return outBox;
}
static JToken ConvertAnnotation(Frame frame, BoundingBox3DLabeler.BoundingBoxAnnotation bbox)

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


using System.Linq;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine.Perception.GroundTruth.DataModel;
using UnityEngine.Perception.GroundTruth.Exporters.Solo;
using UnityEngine.Rendering;
namespace UnityEngine.Perception.GroundTruth

[Serializable]
public sealed class KeypointLabeler : CameraLabeler
{
[Serializable]
public struct Keypoint : IMessageProducer
{
/// <summary>
/// The index of the keypoint in the template file
/// </summary>
public int index;
public Vector2 location;
/// <summary>
/// The state of the point,
/// 0 = not present,
/// 1 = keypoint is present but not visible,
/// 2 = keypoint is present and visible
/// </summary>
public int state;
public void ToMessage(IMessageBuilder builder)
{
builder.AddInt("index", index);
builder.AddFloatVector("location", Utils.ToFloatVector(location));
builder.AddInt("state", state);
}
}
public class Definition : AnnotationDefinition
{
static readonly string k_Id = "keypoints";
static readonly string k_Description = "Produces keypoint annotations for all visible labeled objects that have a humanoid animation avatar component.";
static readonly string k_AnnotationType = "keypoints";
public IEnumerable<Entry> entries;
public Definition() : base(k_Id, k_Description, k_AnnotationType) { }
public Definition(IEnumerable<Entry> entries)
: base(k_Id, k_Description, k_AnnotationType)
{
this.entries = entries;
}
[Serializable]
public struct JointDefinition : IMessageProducer
{
public string label;
public int index;
public Color color;
public void ToMessage(IMessageBuilder builder)
{
builder.AddString("label", label);
builder.AddInt("index", index);
builder.AddIntVector("color", Utils.ToIntVector(color));
}
}
[Serializable]
public struct SkeletonDefinition : IMessageProducer
{
public int joint1;
public int joint2;
public Color color;
public void ToMessage(IMessageBuilder builder)
{
builder.AddInt("joint1", joint1);
builder.AddInt("joint2", joint2);
builder.AddIntVector("color", Utils.ToIntVector(color));
}
}
[Serializable]
public struct Entry : IMessageProducer
{
public int labelId;
public string labelName;
public string templateId;
public string templateName;
public JointDefinition[] keyPoints;
public SkeletonDefinition[] skeleton;
public void ToMessage(IMessageBuilder builder)
{
builder.AddInt("label_id", labelId);
builder.AddString("label_name", labelName);
builder.AddString("template_id", templateId);
builder.AddString("template_name", templateName);
var nested = builder.AddNestedMessage("keypoints");
foreach (var kp in keyPoints)
{
kp.ToMessage(nested);
}
nested = builder.AddNestedMessage("skeleton");
foreach (var bone in skeleton)
{
bone.ToMessage(nested);
}
}
}
public override void ToMessage(IMessageBuilder builder)
{
base.ToMessage(builder);
foreach (var e in entries)
{
var nested = builder.AddNestedMessageToVector("entries");
e.ToMessage(nested);
}
}
}
public class Annotation : DataModel.Annotation
{
public IEnumerable<Entry> entries;
[Serializable]
public class Entry : IMessageProducer
{
/// <summary>
/// The label id of the entity
/// </summary>
public int labelId;
/// <summary>
/// The instance id of the entity
/// </summary>
public uint instanceId;
/// <summary>
/// The template that the points are based on
/// </summary>
public string templateGuid;
/// <summary>
/// Pose ground truth for the current set of keypoints
/// </summary>
public string pose = "unset";
/// <summary>
/// Array of all of the keypoints
/// </summary>
public Keypoint[] keypoints;
public void ToMessage(IMessageBuilder builder)
{
builder.AddInt("instance_id", (int)instanceId);
builder.AddInt("label_id", labelId);
builder.AddString("template_guid", templateGuid);
builder.AddString("pose", pose);
var nested = builder.AddNestedMessage("keypoints");
foreach (var keypoint in keypoints)
{
keypoint.ToMessage(nested);
}
}
}
}
/// <summary>
/// The active keypoint template. Required to annotate keypoint data.
/// </summary>

/// <summary>
/// The GUID id to associate with the annotations produced by this labeler.
/// </summary>
public static string annotationId = "8b3ef246-daa7-4dd5-a0e8-a943f6e7f8c2";
public static string annotationId = "keypoints";
/// <summary>
/// The <see cref="IdLabelConfig"/> which associates objects with labels.
/// </summary>

public KeypointObjectFilter objectFilter;
// ReSharper restore MemberCanBePrivate.Global
// AnnotationDefinition m_AnnotationDefinition;
AnnotationDefinition m_AnnotationDefinition;
Dictionary<int, (AsyncAnnotationFuture annotation, Dictionary<uint, KeypointEntry> keypoints)> m_AsyncAnnotations;
List<KeypointEntry> m_KeypointEntriesToReport;
Dictionary<int, (AsyncAnnotationFuture annotation, Dictionary<uint, Annotation.Entry> keypoints)> m_AsyncAnnotations;
List<Annotation.Entry> m_KeypointEntriesToReport;
int m_CurrentFrame;

public event Action<int, List<KeypointEntry>> KeypointsComputed;
public event Action<int, List<Annotation.Entry>> KeypointsComputed;
/// <summary>
/// Creates a new key point labeler. This constructor creates a labeler that

{
if (idLabelConfig == null)
throw new InvalidOperationException($"{nameof(KeypointLabeler)}'s idLabelConfig field must be assigned");
#if false
m_AnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition("keypoints", TemplateToJson(activeTemplate, idLabelConfig),
"pixel coordinates of keypoints in a model, along with skeletal connectivity data", id: new Guid(annotationId));
#else
// m_AnnotationDefinition = new AnnotationDefinition();
#endif
m_AnnotationDefinition = new Definition(TemplateToJson(activeTemplate, idLabelConfig));
DatasetCapture.RegisterAnnotationDefinition(m_AnnotationDefinition);
m_AsyncAnnotations = new Dictionary<int, (AsyncAnnotationFuture, Dictionary<uint, KeypointEntry>)>();
m_KeypointEntriesToReport = new List<KeypointEntry>();
m_AsyncAnnotations = new Dictionary<int, (AsyncAnnotationFuture, Dictionary<uint, Annotation.Entry>)>();
m_KeypointEntriesToReport = new List<Annotation.Entry>();
m_CurrentFrame = 0;
perceptionCamera.InstanceSegmentationImageReadback += OnInstanceSegmentationImageReadback;

{
if (keypoint.state == 0) return 0;
var centerX = Mathf.FloorToInt(keypoint.x);
var centerY = Mathf.FloorToInt(keypoint.y);
var centerX = Mathf.FloorToInt(keypoint.location.x);
var centerY = Mathf.FloorToInt(keypoint.location.y);
if (!PixelOnScreen(centerX, centerY, dimensions))
return 0;

if (keypoint.state == 0)
{
keypoint.x = 0;
keypoint.y = 0;
keypoint.location = Vector2.zero;
keypoint.x = math.clamp(keypoint.x, 0, dimensions.width - .001f);
keypoint.y = math.clamp(keypoint.y, 0, dimensions.height - .001f);
keypoint.location.x = math.clamp(keypoint.location.x, 0, dimensions.width - .001f);
keypoint.location.y = math.clamp(keypoint.location.y, 0, dimensions.height - .001f);
}
keypointSet.Value.keypoints[i] = keypoint;

{
foreach (var objectInfo in objectInfos)
{
if (entry.instance_id == objectInfo.instanceId)
if (entry.instanceId == objectInfo.instanceId)
{
include = true;
break;

//This code assumes that OnRenderedObjectInfoReadback will be called immediately after OnInstanceSegmentationImageReadback
KeypointsComputed?.Invoke(frameCount, m_KeypointEntriesToReport);
// asyncAnnotation.annotation.ReportValues(m_KeypointEntriesToReport);
var toReport = new Annotation
{
sensorId = perceptionCamera.ID,
Id = m_AnnotationDefinition.id,
annotationType = m_AnnotationDefinition.annotationType,
description = m_AnnotationDefinition.description,
entries = m_KeypointEntriesToReport
};
asyncAnnotation.annotation.Report(toReport);
}
/// <param name="scriptableRenderContext"></param>

#if false
var keypoints = new Dictionary<uint, KeypointEntry>();
var keypoints = new Dictionary<uint, Annotation.Entry>();
#endif
#if false
// ReSharper disable InconsistentNaming
// ReSharper disable NotAccessedField.Global
// ReSharper disable NotAccessedField.Local

// ReSharper restore InconsistentNaming
// ReSharper restore NotAccessedField.Global
// ReSharper restore NotAccessedField.Local
#endif
float GetCaptureHeight()
{
var targetTexture = perceptionCamera.attachedCamera.targetTexture;

{
public bool status;
public Animator animator;
public KeypointEntry keypoints;
public Annotation.Entry keypoints;
public List<(JointLabel, int)> overrides;
}

{
status = false,
animator = null,
keypoints = new KeypointEntry(),
keypoints = new Annotation.Entry(),
cached.keypoints.instance_id = labeledEntity.instanceId;
cached.keypoints.label_id = labelEntry.id;
cached.keypoints.frame = -1;
cached.keypoints.template_guid = activeTemplate.templateID;
cached.keypoints.instanceId = labeledEntity.instanceId;
cached.keypoints.labelId = labelEntry.id;
cached.keypoints.templateGuid = activeTemplate.templateID;
cached.keypoints.keypoints = new Keypoint[activeTemplate.keypoints.Length];
for (var i = 0; i < cached.keypoints.keypoints.Length; i++)

}
var cachedData = m_KnownStatus[labeledEntity.instanceId];
cachedData.keypoints.frame = frame;
if (cachedData.status)
{

var cachedKeypointEntry = cachedData.keypoints;
var keypointEntry = new KeypointEntry()
var keypointEntry = new Annotation.Entry
frame = cachedKeypointEntry.frame,
instance_id = cachedKeypointEntry.instance_id,
instanceId = cachedKeypointEntry.instanceId,
label_id = cachedKeypointEntry.label_id,
labelId = cachedKeypointEntry.labelId,
template_guid = cachedKeypointEntry.template_guid
templateGuid = cachedKeypointEntry.templateGuid
};
m_AsyncAnnotations[m_CurrentFrame].keypoints[labeledEntity.instanceId] = keypointEntry;
}

keypoints[idx].index = idx;
if (loc.z < 0)
{
keypoints[idx].x = 0;
keypoints[idx].y = 0;
keypoints[idx].location = Vector2.zero;
keypoints[idx].x = loc.x;
keypoints[idx].y = loc.y;
keypoints[idx].location = new Vector2(loc.x, loc.y);
keypoints[idx].state = 2;
}
}

return "unset";
}
Keypoint? GetKeypointForJoint(KeypointEntry entry, int joint)
Keypoint? GetKeypointForJoint(Annotation.Entry entry, int joint)
{
if (joint < 0 || joint >= entry.keypoints.Length) return null;
return entry.keypoints[joint];

if (joint1 != null && joint1.Value.state == 2 && joint2 != null && joint2.Value.state == 2)
{
VisualizationHelper.DrawLine(joint1.Value.x, joint1.Value.y, joint2.Value.x, joint2.Value.y, bone.color, 8, skeletonTexture);
VisualizationHelper.DrawLine(joint1.Value.location, joint2.Value.location, bone.color, 8, skeletonTexture);
}
}

VisualizationHelper.DrawPoint(keypoint.x, keypoint.y, activeTemplate.keypoints[keypoint.index].color, 8, jointTexture);
VisualizationHelper.DrawPoint(keypoint.location.x, keypoint.location.y, activeTemplate.keypoints[keypoint.index].color, 8, jointTexture);
#if false
// ReSharper disable InconsistentNaming
// ReSharper disable NotAccessedField.Local
[Serializable]

}
// ReSharper restore InconsistentNaming
// ReSharper restore NotAccessedField.Local
KeypointJson[] TemplateToJson(KeypointTemplate input, IdLabelConfig labelConfig)
#endif
// TODO rename this method
Definition.Entry [] TemplateToJson(KeypointTemplate input, IdLabelConfig labelConfig)
var jsons = new KeypointJson[labelConfig.labelEntries.Count];
var jsons = new Definition.Entry[labelConfig.labelEntries.Count];
var json = new KeypointJson();
json.label_id = cfg.id;
json.label_name = cfg.label;
json.template_id = input.templateID;
json.template_name = input.templateName;
json.key_points = new JointJson[input.keypoints.Length];
json.skeleton = new SkeletonJson[input.skeleton.Length];
var json = new Definition.Entry
{
labelId = cfg.id,
labelName = cfg.label,
templateId = input.templateID,
templateName = input.templateName,
keyPoints = new Definition.JointDefinition[input.keypoints.Length],
skeleton = new Definition.SkeletonDefinition[input.skeleton.Length]
};
json.key_points[i] = new JointJson
json.keyPoints[i] = new Definition.JointDefinition
{
label = input.keypoints[i].label,
index = i,

for (var i = 0; i < input.skeleton.Length; i++)
{
json.skeleton[i] = new SkeletonJson()
json.skeleton[i] = new Definition.SkeletonDefinition
{
joint1 = input.skeleton[i].joint1,
joint2 = input.skeleton[i].joint2,

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


#endif
}
static GameObject SetupCamera(IdLabelConfig config, KeypointTemplate template, Action<int, List<KeypointLabeler.KeypointEntry>> computeListener, RenderTexture renderTexture = null, KeypointObjectFilter keypointObjectFilter = KeypointObjectFilter.Visible)
static GameObject SetupCamera(IdLabelConfig config, KeypointTemplate template, Action<int, List<KeypointLabeler.Annotation.Entry>> computeListener, RenderTexture renderTexture = null, KeypointObjectFilter keypointObjectFilter = KeypointObjectFilter.Visible)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);

[UnityTest]
public IEnumerator Keypoint_TestStaticLabeledCube()
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
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].location.x, t.keypoints[1].location.x);
Assert.AreEqual(t.keypoints[2].location.x, t.keypoints[3].location.x);
Assert.AreEqual(t.keypoints[4].location.x, t.keypoints[5].location.x);
Assert.AreEqual(t.keypoints[6].location.x, t.keypoints[7].location.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);
Assert.AreEqual(t.keypoints[0].location.y, t.keypoints[3].location.y);
Assert.AreEqual(t.keypoints[1].location.y, t.keypoints[2].location.y);
Assert.AreEqual(t.keypoints[4].location.y, t.keypoints[7].location.y);
Assert.AreEqual(t.keypoints[5].location.y, t.keypoints[6].location.y);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
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].location.x, t.keypoints[1].location.x);
Assert.AreEqual(t.keypoints[2].location.x, t.keypoints[3].location.x);
Assert.AreEqual(t.keypoints[4].location.x, t.keypoints[5].location.x);
Assert.AreEqual(t.keypoints[6].location.x, t.keypoints[7].location.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);
Assert.AreEqual(t.keypoints[0].location.y, t.keypoints[3].location.y);
Assert.AreEqual(t.keypoints[1].location.y, t.keypoints[2].location.y);
Assert.AreEqual(t.keypoints[4].location.y, t.keypoints[7].location.y);
Assert.AreEqual(t.keypoints[5].location.y, t.keypoints[6].location.y);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
testCase = incoming[2];
Assert.AreEqual(0, testCase.Count);

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

[UnityTest]
public IEnumerator Keypoint_TestMovingCube()
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var keypoints = new[]
{

texture.Create();
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
cam.GetComponent<PerceptionCamera>().showVisualizations = false;

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(1024 / 2, t.keypoints[0].x);
Assert.AreEqual(768 / 2, t.keypoints[0].y);
Assert.AreEqual(1024 / 2, t.keypoints[0].location.x);
Assert.AreEqual(768 / 2, t.keypoints[0].location.y);
Assert.AreEqual(0, t.keypoints[0].index);
Assert.AreEqual(2, t.keypoints[0].state);

Assert.AreEqual(1, testCase2.Count);
var t2 = testCase2.First();
Assert.AreEqual(445, t2.keypoints[0].x, 1);
Assert.AreEqual(768 / 2, t2.keypoints[0].y);
Assert.AreEqual(445, t2.keypoints[0].location.x, 1);
Assert.AreEqual(768 / 2, t2.keypoints[0].location.y);
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(9, t.keypoints.Length);
Assert.NotZero(t.keypoints[0].state);

for (var i = 0; i < 9; i++) Assert.AreEqual(i, t.keypoints[i].index);
Assert.Zero(t.keypoints[8].state);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
var cube = TestHelper.CreateLabeledCube(scale: 6, z: 8);

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
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].location.x, t.keypoints[1].location.x);
Assert.AreEqual(t.keypoints[2].location.x, t.keypoints[3].location.x);
Assert.AreEqual(t.keypoints[4].location.x, t.keypoints[5].location.x);
Assert.AreEqual(t.keypoints[6].location.x, t.keypoints[7].location.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);
Assert.AreEqual(t.keypoints[0].location.y, t.keypoints[3].location.y);
Assert.AreEqual(t.keypoints[1].location.y, t.keypoints[2].location.y);
Assert.AreEqual(t.keypoints[4].location.y, t.keypoints[7].location.y);
Assert.AreEqual(t.keypoints[5].location.y, t.keypoints[6].location.y);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
}

{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
CreateFullyOccludedScene(template, cam);

public IEnumerator Keypoint_FullyOccluded_WithIncludeOccluded_ReportsProperly(
[Values(KeypointObjectFilter.VisibleAndOccluded, KeypointObjectFilter.All)] KeypointObjectFilter keypointObjectFilter)
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var texture = new RenderTexture(1024, 768, 16);
texture.Create();

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(9, t.keypoints.Length);
for (var i = 0; i < 8; i++)

Assert.Zero(t.keypoints[8].state);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
}
private void CreateFullyOccludedScene(KeypointTemplate template, GameObject cam)

public IEnumerator Keypoint_Offscreen_DoesNotReport(
[Values(KeypointObjectFilter.VisibleAndOccluded, KeypointObjectFilter.Visible)] KeypointObjectFilter keypointObjectFilter)
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var texture = new RenderTexture(1024, 768, 16);
texture.Create();

[UnityTest]
public IEnumerator Keypoint_Offscreen_WithIncludeAll_ReportsProperly()
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var texture = new RenderTexture(1024, 768, 16);
texture.Create();

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.Zero(t.keypoints[i].x);
Assert.Zero(t.keypoints[i].y);
Assert.Zero(t.keypoints[i].location.x);
Assert.Zero(t.keypoints[i].location.y);
}
}

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

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(9, t.keypoints.Length);
Assert.AreEqual(2, t.keypoints[0].state);

for (var i = 0; i < 9; i++) Assert.AreEqual(i, t.keypoints[i].index);
Assert.Zero(t.keypoints[8].state);
Assert.Zero(t.keypoints[8].x);
Assert.Zero(t.keypoints[8].y);
Assert.Zero(t.keypoints[8].location.x);
Assert.Zero(t.keypoints[8].location.y);
}

var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var texture = new RenderTexture(1024, 768, 16);

incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
incoming.Add(new List<KeypointLabeler.Annotation.Entry>(data));
}, texture);
var cameraComponent = cam.GetComponent<Camera>();

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(screenPointCenterExpected.x, t.keypoints[8].x, Screen.width * .1);
Assert.AreEqual(screenPointCenterExpected.y, t.keypoints[8].y, Screen.height * .1);
Assert.AreEqual(screenPointCenterExpected.x, t.keypoints[8].location.x, Screen.width * .1);
Assert.AreEqual(screenPointCenterExpected.y, t.keypoints[8].location.y, Screen.height * .1);
Assert.AreEqual(8, t.keypoints[8].index);
Assert.AreEqual(2, t.keypoints[8].state);
}

[ValueSource(nameof(Keypoint_OnBox_ReportsProperCoordinates_TestCases))]
(float scale, bool expectObject, int expectedState, KeypointObjectFilter keypointFilter, Vector2 expectedTopLeft, Vector2 expectedBottomRight) args)
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var incoming = new List<List<KeypointLabeler.Annotation.Entry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var frameSize = 1024;
var texture = new RenderTexture(frameSize, frameSize, 16);

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(1, t.instanceId);
Assert.AreEqual(1, t.labelId);
Assert.AreEqual(template.templateID.ToString(), t.templateGuid);
Assert.AreEqual(args.expectedTopLeft.x, t.keypoints[0].x, k_Delta);
Assert.AreEqual(args.expectedBottomRight.y, t.keypoints[0].y, k_Delta);
Assert.AreEqual(args.expectedTopLeft.x, t.keypoints[0].location.x, k_Delta);
Assert.AreEqual(args.expectedBottomRight.y, t.keypoints[0].location.y, k_Delta);
Assert.AreEqual(args.expectedTopLeft.x, t.keypoints[1].x, k_Delta);
Assert.AreEqual(args.expectedTopLeft.y, t.keypoints[1].y, k_Delta);
Assert.AreEqual(args.expectedTopLeft.x, t.keypoints[1].location.x, k_Delta);
Assert.AreEqual(args.expectedTopLeft.y, t.keypoints[1].location.y, k_Delta);
Assert.AreEqual(args.expectedBottomRight.x, t.keypoints[2].x, k_Delta);
Assert.AreEqual(args.expectedTopLeft.y, t.keypoints[2].y, k_Delta);
Assert.AreEqual(args.expectedBottomRight.x, t.keypoints[2].location.x, k_Delta);
Assert.AreEqual(args.expectedTopLeft.y, t.keypoints[2].location.y, k_Delta);
Assert.AreEqual(args.expectedBottomRight.x, t.keypoints[3].x, k_Delta);
Assert.AreEqual(args.expectedBottomRight.y, t.keypoints[3].y, k_Delta);
Assert.AreEqual(args.expectedBottomRight.x, t.keypoints[3].location.x, k_Delta);
Assert.AreEqual(args.expectedBottomRight.y, t.keypoints[3].location.y, k_Delta);
}
}
}
正在加载...
取消
保存