Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
ButtonPusher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Button Pusher
ButtonPusher
Commits
a07b33a7
Commit
a07b33a7
authored
7 years ago
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Writing tests for class "MotionDiscriminator"...
parent
db1b263f
master
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
183 additions
and
91 deletions
+183
-91
MotionDiscriminatorTests.cs
Assets/Editor/MotionDiscriminatorTests.cs
+79
-0
MotionDiscriminatorTests.cs.meta
Assets/Editor/MotionDiscriminatorTests.cs.meta
+13
-0
SourceBufferTests.cs
Assets/Editor/SourceBufferTests.cs
+50
-65
DistItvExtractor.cs
Assets/MotionAnalysis/DistItvExtractor.cs
+19
-1
MotionDiscriminator.cs
Assets/MotionAnalysis/MotionDiscriminator.cs
+22
-25
No files found.
Assets/Editor/MotionDiscriminatorTests.cs
0 → 100644
View file @
a07b33a7
using
MotionAnalysis
;
using
NUnit.Framework
;
using
System.Collections.Generic
;
using
Windows.Kinect
;
public
class
MotionDiscriminatorTests
{
[
Test
]
public
void
IsPreseted_False_When_Constructed
()
{
var
obj
=
new
MotionDiscriminator
();
var
expected
=
false
;
var
actual
=
obj
.
IsPreseted
;
Assert
.
AreEqual
(
expected
,
actual
,
"IsPreseted should be false when constructed"
);
}
[
Test
]
public
void
Motion_Unknown_When_Constructed
()
{
var
obj
=
new
MotionDiscriminator
();
var
expected
=
MotionState
.
UNKNOWN
;
var
actual
=
obj
.
Motion
;
Assert
.
AreEqual
(
expected
,
actual
,
"Motion should be unknown when constructed"
);
}
[
Test
]
public
void
IsPreset_False_When_Preset_Without_KneeJoints
()
{
var
obj
=
new
MotionDiscriminator
();
obj
.
Preset
(
new
BodyDummy
());
var
expected
=
false
;
var
actual
=
obj
.
IsPreseted
;
Assert
.
AreEqual
(
expected
,
actual
,
"IsPreseted should be false when preset without knee joints"
);
}
[
Test
]
public
void
IsPreset_True_When_Preset_With_KneeJoints
()
{
var
obj
=
new
MotionDiscriminator
();
obj
.
Preset
(
new
KneeJointsBodyStub
());
var
expected
=
true
;
var
actual
=
obj
.
IsPreseted
;
Assert
.
AreEqual
(
expected
,
actual
,
"IsPreseted should be true when preset with knee joints"
);
}
[
Test
]
public
void
Motion_Unknown_When_DistHandBaseSpineShoulder_Smaller_Than_0
()
{
}
}
public
class
BodyDummy
:
BodyFake
{
public
BodyDummy
()
{
Joints
=
new
Dictionary
<
JointType
,
KinectModule
.
IJoint
>();
}
}
public
class
KneeJointsBodyStub
:
BodyFake
{
public
KneeJointsBodyStub
()
{
Joints
=
new
Dictionary
<
JointType
,
KinectModule
.
IJoint
>
{
{
JointType
.
KneeLeft
,
new
JointStub
()
},
{
JointType
.
KneeRight
,
new
JointStub
()
}
};
}
}
This diff is collapsed.
Click to expand it.
Assets/Editor/MotionDiscriminatorTests.cs.meta
0 → 100644
View file @
a07b33a7
fileFormatVersion: 2
guid: 589b57a674870c843ae2e26060f61ee9
timeCreated: 1518028922
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
Click to expand it.
Assets/Editor/SourceBufferTests.cs
View file @
a07b33a7
...
...
@@ -5,8 +5,6 @@ using System;
using
System.Collections.Generic
;
using
KinectModule
;
// To test the update function and the updated buffer, you need a stub for the source frame class.
public
class
SourceBufferTests
{
[
Test
]
...
...
@@ -136,29 +134,24 @@ public class SourceBufferTests
public
class
MultiSourceFrameStub
:
IMultiSourceFrame
{
private
IColorFrame
_ColorFrame
;
private
IBodyIndexFrame
_BodyIndexFrame
;
private
IDepthFrame
_DepthFrame
;
private
IBodyFrame
_BodyFrame
;
public
IColorFrame
LastColorFrame
{
get
{
return
_ColorFrame
;
}
}
public
IColorFrame
LastColorFrame
{
get
;
private
set
;
}
public
IBodyIndexFrame
LastBodyIndexFrame
{
get
{
return
_BodyIndexFrame
;
}
}
public
IDepthFrame
LastDepthFrame
{
get
{
return
_DepthFrame
;
}
}
public
IBodyFrame
LastBodyFrame
{
get
{
return
_BodyFrame
;
}
}
{
get
;
private
set
;
}
public
IDepthFrame
LastDepthFrame
{
get
;
private
set
;
}
public
IBodyFrame
LastBodyFrame
{
get
;
private
set
;
}
public
MultiSourceFrameStub
(
IColorFrame
color
,
IBodyIndexFrame
bodyIndex
,
IDepthFrame
depth
,
IBodyFrame
body
)
{
_
ColorFrame
=
color
;
_
BodyIndexFrame
=
bodyIndex
;
_
DepthFrame
=
depth
;
_
BodyFrame
=
body
;
Last
ColorFrame
=
color
;
Last
BodyIndexFrame
=
bodyIndex
;
Last
DepthFrame
=
depth
;
Last
BodyFrame
=
body
;
}
}
...
...
@@ -236,53 +229,42 @@ public class BodyFrameDummy : IBodyFrame
public
class
BodyFake
:
IBody
{
private
bool
_IsTracked
=
false
;
private
Dictionary
<
JointType
,
IJoint
>
_Joints
=
new
Dictionary
<
JointType
,
IJoint
>
{
{
JointType
.
AnkleLeft
,
new
JointStub
()
},
{
JointType
.
AnkleRight
,
new
JointStub
()
},
{
JointType
.
ElbowLeft
,
new
JointStub
()
},
{
JointType
.
ElbowRight
,
new
JointStub
()
},
{
JointType
.
FootLeft
,
new
JointStub
()
},
{
JointType
.
FootRight
,
new
JointStub
()
},
{
JointType
.
HandLeft
,
new
JointStub
()
},
{
JointType
.
HandRight
,
new
JointStub
()
},
{
JointType
.
HandTipLeft
,
new
JointStub
()
},
{
JointType
.
HandTipRight
,
new
JointStub
()
},
{
JointType
.
Head
,
new
JointStub
()
},
{
JointType
.
HipLeft
,
new
JointStub
()
},
{
JointType
.
HipRight
,
new
JointStub
()
},
{
JointType
.
KneeLeft
,
new
JointStub
()
},
{
JointType
.
KneeRight
,
new
JointStub
()
},
{
JointType
.
Neck
,
new
JointStub
()
},
{
JointType
.
ShoulderLeft
,
new
JointStub
()
},
{
JointType
.
ShoulderRight
,
new
JointStub
()
},
{
JointType
.
SpineBase
,
new
JointStub
()
},
{
JointType
.
SpineMid
,
new
JointStub
()
},
{
JointType
.
SpineShoulder
,
new
JointStub
()
},
{
JointType
.
ThumbLeft
,
new
JointStub
()
},
{
JointType
.
ThumbRight
,
new
JointStub
()
},
{
JointType
.
WristLeft
,
new
JointStub
()
},
{
JointType
.
WristRight
,
new
JointStub
()
}
};
public
bool
IsTracked
{
get
{
return
_IsTracked
;
}
set
{
_IsTracked
=
value
;
}
}
public
bool
IsTracked
{
get
;
set
;
}
public
Dictionary
<
JointType
,
IJoint
>
Joints
{
get
;
protected
set
;
}
public
BodyFake
()
{
get
IsTracked
=
false
;
Joints
=
new
Dictionary
<
JointType
,
IJoint
>
{
return
_Joints
;
}
{
JointType
.
AnkleLeft
,
new
JointStub
()
},
{
JointType
.
AnkleRight
,
new
JointStub
()
},
{
JointType
.
ElbowLeft
,
new
JointStub
()
},
{
JointType
.
ElbowRight
,
new
JointStub
()
},
{
JointType
.
FootLeft
,
new
JointStub
()
},
{
JointType
.
FootRight
,
new
JointStub
()
},
{
JointType
.
HandLeft
,
new
JointStub
()
},
{
JointType
.
HandRight
,
new
JointStub
()
},
{
JointType
.
HandTipLeft
,
new
JointStub
()
},
{
JointType
.
HandTipRight
,
new
JointStub
()
},
{
JointType
.
Head
,
new
JointStub
()
},
{
JointType
.
HipLeft
,
new
JointStub
()
},
{
JointType
.
HipRight
,
new
JointStub
()
},
{
JointType
.
KneeLeft
,
new
JointStub
()
},
{
JointType
.
KneeRight
,
new
JointStub
()
},
{
JointType
.
Neck
,
new
JointStub
()
},
{
JointType
.
ShoulderLeft
,
new
JointStub
()
},
{
JointType
.
ShoulderRight
,
new
JointStub
()
},
{
JointType
.
SpineBase
,
new
JointStub
()
},
{
JointType
.
SpineMid
,
new
JointStub
()
},
{
JointType
.
SpineShoulder
,
new
JointStub
()
},
{
JointType
.
ThumbLeft
,
new
JointStub
()
},
{
JointType
.
ThumbRight
,
new
JointStub
()
},
{
JointType
.
WristLeft
,
new
JointStub
()
},
{
JointType
.
WristRight
,
new
JointStub
()
}
};
}
public
override
bool
Equals
(
object
obj
)
...
...
@@ -310,10 +292,13 @@ public class BodyFake : IBody
public
class
JointStub
:
IJoint
{
private
CameraSpacePoint
_Position
=
new
CameraSpacePoint
{
X
=
0
,
Y
=
0
,
Z
=
0
};
public
CameraSpacePoint
Position
{
get
{
return
_Position
;
}
}
{
get
;
private
set
;
}
public
JointStub
()
{
Position
=
new
CameraSpacePoint
{
X
=
0
,
Y
=
0
,
Z
=
0
};
}
public
override
bool
Equals
(
object
obj
)
{
...
...
This diff is collapsed.
Click to expand it.
Assets/MotionAnalysis/DistItvExtractor.cs
View file @
a07b33a7
using
UnityEngine
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
Windows.Kinect
;
namespace
MotionAnalysis
...
...
@@ -17,6 +18,23 @@ namespace MotionAnalysis
SpineMidRecent
,
HandLeftRecent
,
HandRightRecent
;
private
Dictionary
<
string
,
CameraSpacePoint
?>
Points
=
new
Dictionary
<
string
,
CameraSpacePoint
?>
{
{
"Head"
,
null
},
{
"HandLeft"
,
null
},
{
"HandRight"
,
null
},
{
"SpineShoulder"
,
null
},
{
"SpineMid"
,
null
},
{
"ElbowLeft"
,
null
},
{
"ElbowRight"
,
null
},
{
"KneeLeft"
,
null
},
{
"KneeRight"
,
null
},
{
"SpineMidRecent"
,
null
},
{
"HandLeftRecent"
,
null
},
{
"HandRightRecent"
,
null
}
};
private
float
Table
;
...
...
This diff is collapsed.
Click to expand it.
Assets/MotionAnalysis/MotionDiscriminator.cs
View file @
a07b33a7
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
Windows.Kinect
;
namespace
MotionAnalysis
...
...
@@ -17,23 +16,21 @@ namespace MotionAnalysis
{
IsPreseted
=
false
;
if
(
DoNotHaveKneeJoint
(
body
))
return
;
Extractor
=
new
DistItvExtractor
(
ComputeKneeMean
(
body
));
if
(
HaveKneeJoint
(
body
))
{
Extractor
=
new
DistItvExtractor
(
ComputeKneeMean
(
body
));
IsPreseted
=
true
;
IsPreseted
=
true
;
Init
();
Init
();
}
}
private
bool
DoNot
HaveKneeJoint
(
KinectModule
.
IBody
body
)
private
bool
HaveKneeJoint
(
KinectModule
.
IBody
body
)
{
KinectModule
.
IJoint
left
,
right
;
return
!
body
.
Joints
.
TryGetValue
(
JointType
.
KneeLeft
,
out
left
)
||
!
body
.
Joints
.
TryGetValue
(
JointType
.
KneeRight
,
out
right
);
return
body
!=
null
&&
body
.
Joints
.
ContainsKey
(
JointType
.
KneeLeft
)
&&
body
.
Joints
.
ContainsKey
(
JointType
.
KneeRight
);
}
private
float
ComputeKneeMean
(
KinectModule
.
IBody
body
)
...
...
@@ -57,7 +54,7 @@ namespace MotionAnalysis
Determine
();
}
void
Determine
()
private
void
Determine
()
{
Clap
();
Jump
();
...
...
@@ -71,7 +68,7 @@ namespace MotionAnalysis
OnTheTable
();
}
void
Clap
()
private
void
Clap
()
{
const
float
distPrepare
=
0.3f
,
distDone
=
0.1f
;
...
...
@@ -85,7 +82,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
CLAP_DONE
;
}
void
Jump
()
private
void
Jump
()
{
const
float
distPrepare
=
0.05f
,
distDone
=
0.0f
;
...
...
@@ -96,13 +93,13 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
JUMP_DONE
;
}
void
Hurray
()
private
void
Hurray
()
{
if
(
Extractor
.
DistHandBaseHead
>
0
)
Motion
|=
MotionState
.
HURRAY
;
}
void
HandMove
()
private
void
HandMove
()
{
if
(
Extractor
.
DistHandLeft
>
0
)
Motion
|=
MotionState
.
HAND_MOVE_UP_LEFT
;
...
...
@@ -115,7 +112,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
HAND_MOVE_DOWN_RIGHT
;
}
void
GuardBase
()
private
void
GuardBase
()
{
const
float
distBase
=
0.5f
;
...
...
@@ -128,7 +125,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
GUARD_BASE_RIGHT
;
}
void
HandUp
()
private
void
HandUp
()
{
const
float
distUp
=
0.2f
;
...
...
@@ -139,7 +136,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
HAND_UP_RIGHT
;
}
void
HandDown
()
private
void
HandDown
()
{
if
(
Extractor
.
DistHandBaseSpineMid_Left
<
0.0f
)
Motion
|=
MotionState
.
HAND_DOWN_LEFT
;
...
...
@@ -148,7 +145,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
HAND_DOWN_RIGHT
;
}
void
Jesus
()
private
void
Jesus
()
{
const
float
distJesus
=
0.5f
;
...
...
@@ -156,7 +153,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
JESUS
;
}
void
Headphone
()
private
void
Headphone
()
{
const
float
itvDepth
=
0.2f
,
itvEar
=
0.2f
;
...
...
@@ -170,7 +167,7 @@ namespace MotionAnalysis
Motion
|=
MotionState
.
HEADPHONE_RIGHT
;
}
void
OnTheTable
()
private
void
OnTheTable
()
{
const
float
distTable
=
0.5f
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment