浏览代码

Adding and fixing remainder of tests.

/keypoint_self_occlusion
Jon Hogins 4 年前
当前提交
6c40a9bc
共有 4 个文件被更改,包括 201 次插入31 次删除
  1. 1
      com.unity.perception/Editor/GroundTruth/JointLabelEditor.cs
  2. 20
      com.unity.perception/Runtime/GroundTruth/Labelers/JointLabel.cs
  3. 20
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  4. 191
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs

1
com.unity.perception/Editor/GroundTruth/JointLabelEditor.cs


namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(JointLabel))]
[CanEditMultipleObjects]
public class JointLabelEditor : Editor
{
public override void OnInspectorGUI()

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


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;

{
singlePerceptionCamera = FindObjectOfType<PerceptionCamera>();
}
float occlusionDistance;
Mesh sphereMesh = null;
#if UNITY_EDITOR
var defaultAssets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Library/unity default resources");
sphereMesh = (Mesh) defaultAssets.FirstOrDefault(a => a.name == "Sphere");
#endif
Vector3 occlusionDistance;
occlusionDistance = selfOcclusionDistance;
occlusionDistance = transform.lossyScale * selfOcclusionDistance;
occlusionDistance = KeypointLabeler.defaultSelfOcclusionDistance;
occlusionDistance = Vector3.one * KeypointLabeler.defaultSelfOcclusionDistance;
occlusionDistance = KeypointLabeler.defaultSelfOcclusionDistance;
occlusionDistance = Vector3.one * KeypointLabeler.defaultSelfOcclusionDistance;
occlusionDistance = keypointLabeler.selfOcclusionDistance;
occlusionDistance = Vector3.one * keypointLabeler.selfOcclusionDistance;
}
break;
default:

Gizmos.color = /*Color.green;*/new Color(1, 1, 1, .5f);
Gizmos.DrawWireSphere(transform.position, occlusionDistance);
Gizmos.DrawMesh(sphereMesh, 0, transform.position, transform.rotation, occlusionDistance * 2);
}
}
}

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


}
}
var cameraPosition = perceptionCamera.transform.position;
var cameraforward = perceptionCamera.transform.forward;
var jointTransform = joint.transform;
var jointPosition = jointTransform.position;
jointSelfOcclusionDistance = joint.selfOcclusionDistance;
{
//apply the scale of the object to the normalized ray from the object to the camera to compute
//the actual self-occlusion distance
var depthOfJoint = Vector3.Dot(jointPosition - cameraPosition, cameraforward);
var cameraEffectivePosition = jointPosition + (-cameraforward * depthOfJoint);
var jointRelativeCameraPosition = jointTransform.InverseTransformPoint(cameraEffectivePosition);
var jointRelativeCheckPosition = jointRelativeCameraPosition.normalized * joint.selfOcclusionDistance;
var worldSpaceCheckVector = jointTransform.TransformVector(jointRelativeCheckPosition);
jointSelfOcclusionDistance = worldSpaceCheckVector.magnitude;
}
InitKeypoint(joint.transform.position, cachedData, checkLocationsSlice, idx, jointSelfOcclusionDistance);
InitKeypoint(jointPosition, cachedData, checkLocationsSlice, idx, jointSelfOcclusionDistance);
}
cachedData.keypoints.pose = "unset";

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


static void SetupCubeJoint(GameObject cube, string label, float x, float y, float z, float? selfOcclusionDistance = null)
{
var joint = new GameObject();
joint.transform.parent = cube.transform;
joint.transform.SetParent(cube.transform, false);
joint.transform.localPosition = new Vector3(x, y, z);
var jointLabel = joint.AddComponent<JointLabel>();
jointLabel.labels.Add(label);

Projection
}
public static IEnumerable<(Vector3 origin, float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded)>
public static IEnumerable<(CheckDistanceType checkDistanceType, Vector3 origin, Vector3 objectScale, Quaternion rotation,
float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded)>
foreach (var checkDistanceType in new[] {CheckDistanceType.Global, CheckDistanceType.JointLabel})
{
yield return (
checkDistanceType,
Vector3.zero,
Vector3.one,
Quaternion.identity,
0.1f,
0.2f,
60f,
true);
yield return (
checkDistanceType,
Vector3.zero,
Vector3.one,
Quaternion.identity,
0.2f,
0.005f,
60f,
false);
yield return (
checkDistanceType,
Vector3.zero,
Vector3.one,
Quaternion.identity,
0.1f,
0.05f,
60f,
false);
yield return (
checkDistanceType,
new Vector3(0, 0, 88),
Vector3.one,
Quaternion.identity,
0.1f,
0.05f,
1f,
false);
//larger value here for the occluded check due to lack of depth precision close to far plane.
//We choose to mark points not occluded when the point depth and geometry depth are the same in the depth buffer
yield return (
checkDistanceType,
new Vector3(0, 0, 88),
Vector3.one,
Quaternion.identity,
1f,
2f,
1f,
true);
}
CheckDistanceType.Global,
0.1f,
Vector3.one * .5f,
Quaternion.identity,
0.3f,
true);
false);
CheckDistanceType.Global,
new Vector3(1f, 1f, .5f),
Quaternion.identity,
0.005f,
0.3f,
CheckDistanceType.JointLabel,
0.1f,
0.05f,
new Vector3(1f, 1f, .5f),
Quaternion.identity,
0.2f,
0.3f,
false);
true);
new Vector3(0, 0, 88),
0.1f,
0.05f,
1f,
false);
//larger value here for the occluded check due to lack of depth precision close to far plane.
//We choose to mark points not occluded when the point depth and geometry depth are the same in the depth buffer
CheckDistanceType.JointLabel,
Vector3.zero,
Vector3.one * .5f,
Quaternion.identity,
0.2f,
0.3f,
60f,
true);
new Vector3(0, 0, 88),
1f,
2f,
1f,
CheckDistanceType.JointLabel,
Vector3.zero,
new Vector3(1f, 1f, .05f),
Quaternion.AngleAxis(45, Vector3.right),
0.2f,
0.21f,
60f,
true);
}

(Vector3 origin, float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded) args,
[Values(CheckDistanceType.Global, CheckDistanceType.JointLabel)] CheckDistanceType checkDistanceType,
(CheckDistanceType checkDistanceType, Vector3 origin, Vector3 objectScale, Quaternion rotation,
float checkDistance, float pointDistance, float cameraFieldOfView, bool expectOccluded) args,
[Values(ProjectionKind.Orthographic, ProjectionKind.Projection)] ProjectionKind projectionKind)
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();

var labelerSelfOcclusionDistance =
checkDistanceType == CheckDistanceType.Global ? args.checkDistance : 0.5f;
args.checkDistanceType == CheckDistanceType.Global ? args.checkDistance : 0.5f;
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);

}
var cube = TestHelper.CreateLabeledCube(scale: 1f, x: args.origin.x, y: args.origin.y, z: args.origin.z);
var localSelfOcclusionDistance = checkDistanceType == CheckDistanceType.JointLabel ? (float?)args.checkDistance : null;
cube.transform.localScale = args.objectScale;
cube.transform.localRotation = args.rotation;
var localSelfOcclusionDistance = args.checkDistanceType == CheckDistanceType.JointLabel ? (float?)args.checkDistance : null;
cube.SetActive(true);
cam.SetActive(true);
AddTestObjectForCleanup(cam);
AddTestObjectForCleanup(cube);
for (int i = 0; i < 10000; i++)
yield return null;
//force all async readbacks to complete
DestroyTestObject(cam);
texture.Release();
var testCase = incoming.Last();
Assert.AreEqual(1, testCase.Count);
var t = testCase.First();
Assert.AreEqual(args.expectOccluded ? 1 : 2, t.keypoints[8].state);
}
public static IEnumerable<(Vector3 objectScale, Quaternion rotation, float checkDistance, Vector3 pointLocalPosition, bool expectOccluded)>
Keypoint_OnCorner_OfRotatedScaledBox_RespectsThreshold_TestCases()
{
yield return (
new Vector3(90f, 90f, 10f),
Quaternion.identity,
.11f,
new Vector3(-.4f, -.4f, -.4f),
false);
yield return (
new Vector3(90f, 90f, 1f),
Quaternion.identity,
.5f,
new Vector3(-.4f, -.4f, .4f),
true);
yield return (
new Vector3(90, 90, 9),
Quaternion.AngleAxis(90, Vector3.right),
.11f,
new Vector3(-.4f, -.4f, -.4f),
false);
yield return (
new Vector3(90, 90, 90),
Quaternion.AngleAxis(90, Vector3.right),
.11f,
new Vector3(-.4f, -.4f, -.4f),
false);
yield return (
new Vector3(90, 60, 90),
Quaternion.AngleAxis(45, Vector3.right),
.11f,
new Vector3(-.4f, -.4f, -.4f),
true);
}
[UnityTest]
public IEnumerator Keypoint_OnCorner_OfRotatedScaledBox_RespectsThreshold(
[ValueSource(nameof(Keypoint_OnCorner_OfRotatedScaledBox_RespectsThreshold_TestCases))]
(Vector3 objectScale, Quaternion rotation, float checkDistance, Vector3 pointLocalPosition, bool expectOccluded) args)
{
var incoming = new List<List<KeypointLabeler.KeypointEntry>>();
var template = CreateTestTemplate(Guid.NewGuid(), "TestTemplate");
var frameSize = 1024;
var texture = new RenderTexture(frameSize, frameSize, 16);
var labelerSelfOcclusionDistance = 0.5f;
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
}, texture, defaultSelfOcclusionDistance: labelerSelfOcclusionDistance);
var camComponent = cam.GetComponent<Camera>();
camComponent.orthographic = true;
camComponent.orthographicSize = 100f;
cam.transform.localPosition = new Vector3(0, 0, -95f);
var cube = TestHelper.CreateLabeledCube(scale: 1f);
cube.transform.localScale = args.objectScale;
cube.transform.localRotation = args.rotation;
SetupCubeJoint(cube, "Center", args.pointLocalPosition.x, args.pointLocalPosition.y, args.pointLocalPosition.z, args.checkDistance);
cube.SetActive(true);
cam.SetActive(true);

正在加载...
取消
保存