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
f6672a4d
Commit
f6672a4d
authored
Feb 10, 2018
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring class "DistItvExtractor"
parent
79d8170b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
240 additions
and
77 deletions
+240
-77
DistItvExtractor.cs
Assets/MotionAnalysis/DistItvExtractor.cs
+236
-73
MotionDiscriminator.cs
Assets/MotionAnalysis/MotionDiscriminator.cs
+4
-4
No files found.
Assets/MotionAnalysis/DistItvExtractor.cs
View file @
f6672a4d
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
UnityEngine
;
using
Windows.Kinect
;
...
...
@@ -6,19 +8,6 @@ namespace MotionAnalysis
{
public
class
DistItvExtractor
{
private
CameraSpacePoint
Head
,
HandLeft
,
HandRight
,
SpineShoulder
,
SpineMid
,
ElbowLeft
,
ElbowRight
,
KneeLeft
,
KneeRight
,
SpineMidRecent
,
HandLeftRecent
,
HandRightRecent
;
private
Dictionary
<
string
,
CameraSpacePoint
?>
Points
=
new
Dictionary
<
string
,
CameraSpacePoint
?>
{
...
...
@@ -38,45 +27,45 @@ namespace MotionAnalysis
private
float
Table
;
public
float
DistHandBaseSpineShoulder
public
float
?
DistHandBaseSpineShoulder
{
get
;
private
set
;
}
public
float
DistHand
public
float
?
DistSpine
{
get
;
private
set
;
}
public
float
DistSpine
public
float
?
DistHandBaseHead
{
get
;
private
set
;
}
public
float
DistHandBaseHead
public
float
?
DistHandLeft
{
get
;
private
set
;
}
public
float
DistHandLef
t
public
float
?
DistHandRigh
t
{
get
;
private
set
;
}
public
float
DistHandRigh
t
public
float
?
DistHandBaseElbow_Lef
t
{
get
;
private
set
;
}
public
float
DistHandBaseElbow_Lef
t
public
float
?
DistHandBaseElbow_Righ
t
{
get
;
private
set
;
}
public
float
DistHandBaseElbow_Righ
t
public
float
?
DistHandBaseHead_Lef
t
{
get
;
private
set
;
}
public
float
DistHandBaseHead_Lef
t
public
float
?
DistHandBaseHead_Righ
t
{
get
;
private
set
;
}
public
float
DistHandBaseHead_Righ
t
public
float
?
DistHandBaseSpineMid_Lef
t
{
get
;
private
set
;
}
public
float
DistHandBaseSpineMid_Lef
t
public
float
?
DistHandBaseSpineMid_Righ
t
{
get
;
private
set
;
}
public
float
DistHandBaseSpineMid_Right
public
float
?
DistKneeBaseTable
{
get
;
private
set
;
}
public
float
DistKneeBaseTable
public
float
?
ItvHand
{
get
;
private
set
;
}
public
float
ItvElbowBaseSpineMid_Left
public
float
?
ItvElbowBaseSpineMid_Left
{
get
;
private
set
;
}
public
float
ItvElbowBaseSpineMid_Right
public
float
?
ItvElbowBaseSpineMid_Right
{
get
;
private
set
;
}
public
float
ItvHandBaseHead
public
float
?
ItvHandBaseHead
{
get
;
private
set
;
}
public
float
ItvHandBaseHead_LeftEar
public
float
?
ItvHandBaseHead_LeftEar
{
get
;
private
set
;
}
public
float
ItvHandBaseHead_RightEar
public
float
?
ItvHandBaseHead_RightEar
{
get
;
private
set
;
}
public
float
ItvHandBaseHead_LeftDepth
public
float
?
ItvHandBaseHead_LeftDepth
{
get
;
private
set
;
}
public
float
ItvHandBaseHead_RightDepth
public
float
?
ItvHandBaseHead_RightDepth
{
get
;
private
set
;
}
public
DistItvExtractor
(
float
table
)
...
...
@@ -93,22 +82,18 @@ namespace MotionAnalysis
private
void
UpdatePosition
(
KinectModule
.
IBody
body
)
{
Head
=
body
.
Joints
[
JointType
.
Head
]
.
Position
;
HandLeft
=
body
.
Joints
[
JointType
.
HandLeft
]
.
Position
;
HandRight
=
body
.
Joints
[
JointType
.
HandRight
]
.
Position
;
SpineShoulder
=
body
.
Joints
[
JointType
.
SpineShoulder
].
Position
;
SpineMid
=
body
.
Joints
[
JointType
.
SpineMid
]
.
Position
;
ElbowLeft
=
body
.
Joints
[
JointType
.
ElbowLeft
]
.
Position
;
ElbowRight
=
body
.
Joints
[
JointType
.
ElbowRight
]
.
Position
;
KneeLeft
=
body
.
Joints
[
JointType
.
KneeLeft
]
.
Position
;
KneeRight
=
body
.
Joints
[
JointType
.
KneeRight
]
.
Position
;
Points
.
Keys
.
Select
(
x
=>
(
JointType
)
Enum
.
Parse
(
typeof
(
JointType
),
x
))
.
ToList
()
.
ForEach
(
x
=>
Points
[
x
.
ToString
()]
=
body
.
Joints
.
ContainsKey
(
x
)
?
(
CameraSpacePoint
?)
body
.
Joints
[
x
].
Position
:
null
);
}
private
void
SaveRecent
()
{
SpineMidRecent
=
SpineMid
;
HandLeftRecent
=
HandLeft
;
HandRightRecent
=
HandRight
;
Points
[
"SpineMidRecent"
]
=
Points
[
"SpineMid"
]
;
Points
[
"HandLeftRecent"
]
=
Points
[
"HandLeft"
]
;
Points
[
"HandRightRecent"
]
=
Points
[
"HandRight"
]
;
}
private
void
UpdateDistItv
()
...
...
@@ -125,74 +110,252 @@ namespace MotionAnalysis
ComputeHeadphone
();
}
bool
PointsNotNull
(
string
[]
names
)
{
foreach
(
var
x
in
names
)
if
(
Points
[
x
]
==
null
)
return
false
;
return
true
;
}
private
void
ComputeClap
()
{
DistHandBaseSpineShoulder
=
Mathf
.
Min
(
HandLeft
.
Y
,
HandRight
.
Y
)
-
SpineShoulder
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"SpineShoulder"
,
}))
{
DistHandBaseSpineShoulder
=
null
;
ItvHand
=
null
;
DistHand
=
Distance
(
HandLeft
,
HandRight
);
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
]
.
Value
;
var
spineshoulder
=
Points
[
"SpineShoulder"
].
Value
;
DistHandBaseSpineShoulder
=
Mathf
.
Min
(
handleft
.
Y
,
handright
.
Y
)
-
spineshoulder
.
Y
;
ItvHand
=
Mathf
.
Sqrt
(
Mathf
.
Pow
(
handleft
.
X
-
handright
.
X
,
2.0f
)
+
Mathf
.
Pow
(
handleft
.
Y
-
handright
.
Y
,
2.0f
)
+
Mathf
.
Pow
(
handleft
.
Z
-
handright
.
Z
,
2.0f
));
}
private
void
ComputeJump
()
{
DistSpine
=
SpineMid
.
Y
-
SpineMidRecent
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"SpineMid"
,
"SpineMidRecent"
}))
{
DistSpine
=
null
;
return
;
}
var
spinemid
=
Points
[
"SpineMid"
]
.
Value
;
var
spinemidrecent
=
Points
[
"SpineMidRecent"
].
Value
;
DistSpine
=
spinemid
.
Y
-
spinemidrecent
.
Y
;
}
private
void
ComputeHurray
()
{
DistHandBaseHead
=
Mathf
.
Min
(
HandLeft
.
Y
,
HandRight
.
Y
)
-
Head
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"Head"
}))
{
DistHandBaseHead
=
null
;
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
].
Value
;
var
head
=
Points
[
"Head"
]
.
Value
;
DistHandBaseHead
=
Mathf
.
Min
(
handleft
.
Y
,
handright
.
Y
)
-
head
.
Y
;
}
private
void
ComputeHandMove
()
{
DistHandLeft
=
HandLeft
.
Y
-
HandLeftRecent
.
Y
;
DistHandRight
=
HandRight
.
Y
-
HandRightRecent
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"HandLeftRecent"
,
"HandRightRecent"
}))
{
DistHandLeft
=
null
;
DistHandRight
=
null
;
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
]
.
Value
;
var
handleftrecent
=
Points
[
"HandLeftRecent"
]
.
Value
;
var
handrightrecent
=
Points
[
"HandRightRecent"
].
Value
;
DistHandLeft
=
handleft
.
Y
-
handleftrecent
.
Y
;
DistHandRight
=
handright
.
Y
-
handrightrecent
.
Y
;
}
private
void
ComputeGuardBase
()
{
DistHandBaseElbow_Left
=
HandLeft
.
Y
-
ElbowLeft
.
Y
;
DistHandBaseElbow_Right
=
HandRight
.
Y
-
ElbowRight
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"ElbowLeft"
,
"ElbowRight"
,
"SpineMid"
}))
{
DistHandBaseElbow_Left
=
null
;
DistHandBaseElbow_Right
=
null
;
ItvElbowBaseSpineMid_Left
=
null
;
ItvElbowBaseSpineMid_Right
=
null
;
ItvElbowBaseSpineMid_Left
=
Mathf
.
Abs
(
ElbowLeft
.
X
-
SpineMid
.
X
);
ItvElbowBaseSpineMid_Right
=
Mathf
.
Abs
(
ElbowRight
.
X
-
SpineMid
.
X
);
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
]
.
Value
;
var
elbowleft
=
Points
[
"ElbowLeft"
]
.
Value
;
var
elbowright
=
Points
[
"ElbowRight"
].
Value
;
var
spinemid
=
Points
[
"SpineMid"
]
.
Value
;
DistHandBaseElbow_Left
=
handleft
.
Y
-
elbowleft
.
Y
;
DistHandBaseElbow_Right
=
handright
.
Y
-
elbowright
.
Y
;
ItvElbowBaseSpineMid_Left
=
Mathf
.
Abs
(
elbowleft
.
X
-
spinemid
.
X
);
ItvElbowBaseSpineMid_Right
=
Mathf
.
Abs
(
elbowright
.
X
-
spinemid
.
X
);
}
private
void
ComputeHandUp
()
{
DistHandBaseHead_Left
=
HandLeft
.
Y
-
Head
.
Y
;
DistHandBaseHead_Right
=
HandRight
.
Y
-
Head
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"Head"
}))
{
DistHandBaseHead_Left
=
null
;
DistHandBaseHead_Right
=
null
;
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
].
Value
;
var
head
=
Points
[
"Head"
]
.
Value
;
DistHandBaseHead_Left
=
handleft
.
Y
-
head
.
Y
;
DistHandBaseHead_Right
=
handright
.
Y
-
head
.
Y
;
}
private
void
ComputeHandDown
()
{
DistHandBaseSpineMid_Left
=
HandLeft
.
Y
-
SpineMid
.
Y
;
DistHandBaseSpineMid_Right
=
HandRight
.
Y
-
SpineMid
.
Y
;
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"SpineMid"
}))
{
DistHandBaseSpineMid_Left
=
null
;
DistHandBaseSpineMid_Right
=
null
;
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
].
Value
;
var
spinemid
=
Points
[
"SpineMid"
]
.
Value
;
DistHandBaseSpineMid_Left
=
handleft
.
Y
-
spinemid
.
Y
;
DistHandBaseSpineMid_Right
=
handright
.
Y
-
spinemid
.
Y
;
}
private
void
ComputeOnTheTable
()
{
DistKneeBaseTable
=
Mathf
.
Min
(
KneeLeft
.
Y
,
KneeRight
.
Y
)
-
Table
;
if
(!
PointsNotNull
(
new
string
[]
{
"KneeLeft"
,
"KneeRight"
}))
{
DistKneeBaseTable
=
null
;
return
;
}
var
kneeleft
=
Points
[
"KneeLeft"
]
.
Value
;
var
kneeright
=
Points
[
"KneeRight"
].
Value
;
DistKneeBaseTable
=
Mathf
.
Min
(
kneeleft
.
Y
,
kneeright
.
Y
)
-
Table
;
}
private
void
ComputeJesus
()
{
ItvHandBaseHead
=
Mathf
.
Min
(
Mathf
.
Abs
(
HandLeft
.
X
-
Head
.
X
),
Mathf
.
Abs
(
HandRight
.
X
-
Head
.
X
));
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"Head"
}))
{
ItvHandBaseHead
=
null
;
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
].
Value
;
var
head
=
Points
[
"Head"
]
.
Value
;
ItvHandBaseHead
=
Mathf
.
Min
(
Mathf
.
Abs
(
handleft
.
X
-
head
.
X
),
Mathf
.
Abs
(
handright
.
X
-
head
.
X
));
}
private
void
ComputeHeadphone
()
{
ItvHandBaseHead_LeftEar
=
Mathf
.
Abs
(
HandLeft
.
X
-
Head
.
X
);
ItvHandBaseHead_RightEar
=
Mathf
.
Abs
(
HandRight
.
X
-
Head
.
X
);
ItvHandBaseHead_LeftDepth
=
Mathf
.
Abs
(
HandLeft
.
Z
-
Head
.
Z
);
ItvHandBaseHead_RightDepth
=
Mathf
.
Abs
(
HandRight
.
Z
-
Head
.
Z
);
}
if
(!
PointsNotNull
(
new
string
[]
{
"HandLeft"
,
"HandRight"
,
"Head"
}))
{
ItvHandBaseHead_LeftEar
=
null
;
ItvHandBaseHead_RightEar
=
null
;
ItvHandBaseHead_LeftDepth
=
null
;
ItvHandBaseHead_RightDepth
=
null
;
private
float
Distance
(
CameraSpacePoint
a
,
CameraSpacePoint
b
)
{
return
Mathf
.
Sqrt
(
Mathf
.
Pow
(
a
.
X
-
b
.
X
,
2.0f
)
+
Mathf
.
Pow
(
a
.
Y
-
b
.
Y
,
2.0f
)
+
Mathf
.
Pow
(
a
.
Z
-
b
.
Z
,
2.0f
));
return
;
}
var
handleft
=
Points
[
"HandLeft"
]
.
Value
;
var
handright
=
Points
[
"HandRight"
].
Value
;
var
head
=
Points
[
"Head"
]
.
Value
;
ItvHandBaseHead_LeftEar
=
Mathf
.
Abs
(
handleft
.
X
-
head
.
X
);
ItvHandBaseHead_RightEar
=
Mathf
.
Abs
(
handright
.
X
-
head
.
X
);
ItvHandBaseHead_LeftDepth
=
Mathf
.
Abs
(
handleft
.
Z
-
head
.
Z
);
ItvHandBaseHead_RightDepth
=
Mathf
.
Abs
(
handright
.
Z
-
head
.
Z
);
}
}
}
\ No newline at end of file
Assets/MotionAnalysis/MotionDiscriminator.cs
View file @
f6672a4d
...
...
@@ -72,15 +72,15 @@ namespace MotionAnalysis
private
void
Clap
()
{
const
float
dist
Prepare
=
0.3f
,
dist
Done
=
0.1f
;
const
float
itv
Prepare
=
0.3f
,
itv
Done
=
0.1f
;
if
(
Extractor
.
DistHandBaseSpineShoulder
<=
0.0f
)
return
;
if
(
Extractor
.
DistHand
>
dist
Prepare
)
if
(
Extractor
.
ItvHand
>
itv
Prepare
)
Motion
|=
MotionState
.
CLAP_PREPARE
;
else
if
(
Extractor
.
DistHand
<
dist
Done
)
else
if
(
Extractor
.
ItvHand
<
itv
Done
)
Motion
|=
MotionState
.
CLAP_DONE
;
}
...
...
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