[TestFixture]
public class KeypointGroundTruthTests : GroundTruthTestBase
{
static GameObject SetupCamera ( IdLabelConfig config , KeypointTemplate template , Action < List < KeypointLabeler . KeypointEntry > > computeListener )
static GameObject SetupCamera ( IdLabelConfig config , KeypointTemplate template , Action < int , List < KeypointLabeler . KeypointEntry > > computeListener , RenderTexture renderTexture = null )
{
var cameraObject = new GameObject ( ) ;
cameraObject . SetActive ( false ) ;
camera . farClipPlane = 1 0 0 0 ;
camera . transform . position = new Vector3 ( 0 , 0 , - 1 0 ) ;
if ( renderTexture )
{
camera . targetTexture = renderTexture ;
}
var perceptionCamera = cameraObject . AddComponent < PerceptionCamera > ( ) ;
perceptionCamera . captureRgbImages = false ;
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 ) ;
SetupCubeJoint ( cube , template , "FrontUpperRight" , 0.5f , 0.5f , - 0.5f ) ;
SetupCubeJoint ( cube , template , "FrontLowerRight" , 0.5f , - 0.5f , - 0.5f ) ;
SetupCubeJoint ( cube , template , "BackLowerLeft" , - 0.5f , - 0.5f , 0.5f ) ;
SetupCubeJoint ( cube , template , "BackUpperLeft" , - 0.5f , 0.5f , 0.5f ) ;
SetupCubeJoint ( cube , template , "BackUpperRight" , 0.5f , 0.5f , 0.5f ) ;
SetupCubeJoint ( cube , template , "BackLowerRight" , 0.5f , - 0.5f , 0.5f ) ;
SetupCubeJoint ( cube , template , "FrontLowerLeft" , - 0.49 5f , - 0.49 5f , - 0.49 5f ) ;
SetupCubeJoint ( cube , template , "FrontUpperLeft" , - 0.49 5f , 0.49 5f , - 0.49 5f ) ;
SetupCubeJoint ( cube , template , "FrontUpperRight" , 0.49 5f , 0.49 5f , - 0.49 5f ) ;
SetupCubeJoint ( cube , template , "FrontLowerRight" , 0.49 5f , - 0.49 5f , - 0.49 5f ) ;
SetupCubeJoint ( cube , template , "BackLowerLeft" , - 0.49 5f , - 0.49 5f , 0.49 5f ) ;
SetupCubeJoint ( cube , template , "BackUpperLeft" , - 0.49 5f , 0.49 5f , 0.49 5f ) ;
SetupCubeJoint ( cube , template , "BackUpperRight" , 0.49 5f , 0.49 5f , 0.49 5f ) ;
SetupCubeJoint ( cube , template , "BackLowerRight" , 0.49 5f , - 0.49 5f , 0.49 5f ) ;
}
[UnityTest]
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var texture = new RenderTexture ( 1 0 2 4 , 7 6 8 , 1 6 ) ;
texture . Create ( ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} , texture ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( data ) = >
var cube = TestHelper . CreateLabeledCube ( scale : 6 , z : 8 ) ;
SetupCubeJoints ( cube , template ) ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
AddTestObjectForCleanup ( cam ) ;
AddTestObjectForCleanup ( cube ) ;
yield return null ;
yield return null ;
texture . Release ( ) ;
var testCase = incoming . Last ( ) ;
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 ) ;
}
[UnityTest]
public IEnumerator Keypoint_TestAllOffScreen ( )
{
var incoming = new List < List < KeypointLabeler . KeypointEntry > > ( ) ;
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} ) ;
cube . transform . position = new Vector3 ( - 1 0 0 0 , - 1 0 0 0 , 0 ) ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
yield return null ;
yield return null ;
foreach ( var i in incoming )
{
Assert . Zero ( i . Count ) ;
}
}
[UnityTest]
public IEnumerator Keypoint_TestPartialOffScreen ( )
{
var incoming = new List < List < KeypointLabeler . KeypointEntry > > ( ) ;
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var texture = new RenderTexture ( 1 0 2 4 , 7 6 8 , 1 6 ) ;
texture . Create ( ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} , texture ) ;
var cube = TestHelper . CreateLabeledCube ( scale : 6 , z : 8 ) ;
SetupCubeJoints ( cube , template ) ;
cube . transform . position + = Vector3 . right * 1 3.5f ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
AddTestObjectForCleanup ( cam ) ;
AddTestObjectForCleanup ( cube ) ;
for ( var i = 0 ; i < 2 ; i + + )
yield return null ;
if ( texture ! = null ) texture . Release ( ) ;
var testCase = incoming . Last ( ) ;
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 . NotZero ( t . keypoints [ 0 ] . state ) ;
Assert . NotZero ( t . keypoints [ 1 ] . state ) ;
Assert . NotZero ( t . keypoints [ 4 ] . state ) ;
Assert . NotZero ( t . keypoints [ 5 ] . state ) ;
Assert . Zero ( t . keypoints [ 2 ] . state ) ;
Assert . Zero ( t . keypoints [ 3 ] . state ) ;
Assert . Zero ( t . keypoints [ 6 ] . state ) ;
Assert . Zero ( t . keypoints [ 7 ] . 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 ) ;
}
[UnityTest]
public IEnumerator Keypoint_TestAllOnScreen ( )
{
var incoming = new List < List < KeypointLabeler . KeypointEntry > > ( ) ;
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var texture = new RenderTexture ( 1 0 2 4 , 7 6 8 , 1 6 ) ;
texture . Create ( ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} , texture ) ;
var cube = TestHelper . CreateLabeledCube ( scale : 6 , z : 8 ) ;
SetupCubeJoints ( cube , template ) ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
AddTestObjectForCleanup ( cam ) ;
AddTestObjectForCleanup ( cube ) ;
for ( var i = 0 ; i < 2 ; i + + )
yield return null ;
if ( texture ! = null ) texture . Release ( ) ;
var testCase = incoming . Last ( ) ;
Assert . AreEqual ( 1 , testCase . Count ) ;
var t = testCase . First ( ) ;
Assert . Zero ( t . keypoints [ 8 ] . state ) ;
Assert . Zero ( t . keypoints [ 8 ] . x ) ;
Assert . Zero ( t . keypoints [ 8 ] . y ) ;
[UnityTest]
public IEnumerator Keypoint_TestAllBlockedByOther ( )
{
var incoming = new List < List < KeypointLabeler . KeypointEntry > > ( ) ;
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var texture = new RenderTexture ( 1 0 2 4 , 7 6 8 , 1 6 ) ;
texture . Create ( ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} , texture ) ;
var cube = TestHelper . CreateLabeledCube ( scale : 6 , z : 8 ) ;
SetupCubeJoints ( cube , template ) ;
var blocker = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
blocker . transform . position = new Vector3 ( 0 , 0 , 5 ) ;
blocker . transform . localScale = new Vector3 ( 7 , 7 , 7 ) ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
AddTestObjectForCleanup ( cam ) ;
AddTestObjectForCleanup ( cube ) ;
AddTestObjectForCleanup ( blocker ) ;
for ( var i = 0 ; i < 2 ; i + + )
yield return null ;
if ( texture ! = null ) texture . Release ( ) ;
var testCase = incoming . Last ( ) ;
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 ) ;
for ( var i = 0 ; i < 8 ; i + + )
Assert . AreEqual ( t . keypoints [ i ] . state , 1 ) ;
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 ) ;
}
[UnityTest]
public IEnumerator Keypoint_TestPartiallyBlockedByOther ( )
{
var incoming = new List < List < KeypointLabeler . KeypointEntry > > ( ) ;
var template = CreateTestTemplate ( Guid . NewGuid ( ) , "TestTemplate" ) ;
var texture = new RenderTexture ( 1 0 2 4 , 7 6 8 , 1 6 ) ;
texture . Create ( ) ;
var cam = SetupCamera ( SetUpLabelConfig ( ) , template , ( frame , data ) = >
{
incoming . Add ( data ) ;
} , texture ) ;
var cube = TestHelper . CreateLabeledCube ( scale : 6 , z : 8 ) ;
SetupCubeJoints ( cube , template ) ;
var blocker = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
blocker . transform . position = new Vector3 ( 3 , 0 , 5 ) ;
blocker . transform . localScale = new Vector3 ( 7 , 7 , 7 ) ;
cube . SetActive ( true ) ;
cam . SetActive ( true ) ;
AddTestObjectForCleanup ( cam ) ;
AddTestObjectForCleanup ( cube ) ;
AddTestObjectForCleanup ( blocker ) ;
for ( var i = 0 ; i < 2 ; i + + )
yield return null ;
if ( texture ! = null ) texture . Release ( ) ;
var testCase = incoming . Last ( ) ;
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 ] . state , 2 ) ;
Assert . AreEqual ( t . keypoints [ 1 ] . state , 2 ) ;
Assert . AreEqual ( t . keypoints [ 4 ] . state , 2 ) ;
Assert . AreEqual ( t . keypoints [ 5 ] . state , 2 ) ;
Assert . AreEqual ( t . keypoints [ 2 ] . state , 1 ) ;
Assert . AreEqual ( t . keypoints [ 3 ] . state , 1 ) ;
Assert . AreEqual ( t . keypoints [ 6 ] . state , 1 ) ;
Assert . AreEqual ( t . keypoints [ 7 ] . state , 1 ) ;
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 ) ;
}
}
}