Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embodiment-learning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SoftwareProjectVR17
embodiment-learning
Commits
6e9d0a33
Commit
6e9d0a33
authored
Jan 9, 2018
by
Noxer
Browse files
Options
Downloads
Patches
Plain Diff
Added all fingers and switched format to list of JSON
parent
a10c0937
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Record/Recorder.cs
+74
-19
74 additions, 19 deletions
Assets/Record/Recorder.cs
with
74 additions
and
19 deletions
Assets/Record/Recorder.cs
+
74
−
19
View file @
6e9d0a33
...
@@ -3,6 +3,7 @@ using Leap.Unity;
...
@@ -3,6 +3,7 @@ using Leap.Unity;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
UnityEngine
;
using
UnityEngine
;
using
UnityEngine.UI
;
using
UnityEngine.UI
;
...
@@ -19,8 +20,14 @@ public class Recorder : MonoBehaviour
...
@@ -19,8 +20,14 @@ public class Recorder : MonoBehaviour
private
string
path
=
"Assets/Record/Recorded/"
;
private
string
path
=
"Assets/Record/Recorded/"
;
private
StreamWriter
mStreamWriter
;
private
StreamWriter
mStreamWriter
;
private
string
date
;
// Finger bones from base to tip
private
Bone
.
BoneType
[]
bones
=
new
Bone
.
BoneType
[]
{
Bone
.
BoneType
.
TYPE_METACARPAL
,
Bone
.
BoneType
.
TYPE_PROXIMAL
,
Bone
.
BoneType
.
TYPE_INTERMEDIATE
,
Bone
.
BoneType
.
TYPE_DISTAL
};
public
void
ToggleRecording
()
public
void
ToggleRecording
()
{
{
...
@@ -34,8 +41,7 @@ public class Recorder : MonoBehaviour
...
@@ -34,8 +41,7 @@ public class Recorder : MonoBehaviour
{
{
Directory
.
CreateDirectory
(
path
+
gestureName
);
Directory
.
CreateDirectory
(
path
+
gestureName
);
mStreamWriter
=
new
StreamWriter
(
path
+
gestureName
+
"/"
+
recordingNumber
.
ToString
()
+
".txt"
);
mStreamWriter
=
new
StreamWriter
(
path
+
gestureName
+
"/"
+
recordingNumber
.
ToString
()
+
".txt"
);
mStreamWriter
.
WriteLine
(
"Gesture: "
+
gestureName
+
"; Author: "
+
userName
+
"; Recorded: "
+
date
);
mStreamWriter
.
WriteLine
(
"Gesture: "
+
gestureName
+
"; Author: "
+
userName
);
mStreamWriter
.
WriteLine
(
"timestamp l_palm_pos_x l_palm_pos_y l_palm_pos_z r_palm_pos_x r_palm_pos_y r_palm_pos_z"
);
//UI
//UI
recordingLabel
.
SetActive
(
true
);
recordingLabel
.
SetActive
(
true
);
...
@@ -59,42 +65,91 @@ public class Recorder : MonoBehaviour
...
@@ -59,42 +65,91 @@ public class Recorder : MonoBehaviour
{
{
if
(
mStreamWriter
!=
null
)
if
(
mStreamWriter
!=
null
)
{
{
Vector3
leftPalmPosition
=
Vector3
.
zero
,
rightPalmPosition
=
Vector3
.
zero
;
Dictionary
<
string
,
float
>
hands
=
new
Dictionary
<
string
,
float
>();
Vector4
leftPalmRotation
=
Vector3
.
zero
,
rightPalmRotation
=
Vector3
.
zero
;
Frame
frame
=
LeapService
.
CurrentFrame
;
Frame
frame
=
LeapService
.
CurrentFrame
;
foreach
(
Hand
hand
in
frame
.
Hands
)
foreach
(
Hand
hand
in
frame
.
Hands
)
{
{
if
(
hand
.
IsLeft
)
if
(
hand
.
IsLeft
)
{
{
leftPalmPosition
=
hand
.
PalmPosition
.
ToVector3
();
handToDict
(
"l"
,
hand
,
hands
);
leftPalmRotation
=
new
Vector4
(
hand
.
Rotation
.
x
,
hand
.
Rotation
.
y
,
hand
.
Rotation
.
z
,
hand
.
Rotation
.
w
);
}
}
else
else
{
{
rightPalmPosition
=
hand
.
PalmPosition
.
ToVector3
();
handToDict
(
"r"
,
hand
,
hands
);
rightPalmRotation
=
new
Vector4
(
hand
.
Rotation
.
x
,
hand
.
Rotation
.
y
,
hand
.
Rotation
.
z
,
hand
.
Rotation
.
w
);
}
}
}
}
mStreamWriter
.
WriteLine
(
DataToString
(
VecToData
(
leftPalmPosition
),
VecToData
(
leftPalmRotation
),
VecToData
(
rightPalmPosition
),
VecToData
(
rightPalmRotation
)));
hands
[
"timestamp"
]
=
Time
.
unscaledTime
;
mStreamWriter
.
WriteLine
(
JsonUtility
.
ToJson
(
hands
));
}
}
}
}
private
static
string
VecToData
(
Vector3
vec
)
private
void
handToDict
(
string
prefix
,
Hand
hand
,
Dictionary
<
string
,
float
>
result
)
{
{
// Iterate over each finger and bone
return
string
.
Format
(
"{0} {1} {2}"
,
vec
.
x
,
vec
.
y
,
vec
.
z
);
foreach
(
Finger
finger
in
hand
.
Fingers
)
{
foreach
(
var
boneType
in
bones
)
{
// Load the bone
var
bone
=
finger
.
Bone
(
boneType
);
var
boneID
=
string
.
Join
(
"_"
,
new
string
[]{
prefix
,
FingerName
(
finger
.
Type
),
BoneName
(
boneType
)});
// Store the center of the bone
result
[
boneID
+
"_cen_x"
]
=
bone
.
Center
.
x
;
result
[
boneID
+
"_cen_y"
]
=
bone
.
Center
.
y
;
result
[
boneID
+
"_cen_z"
]
=
bone
.
Center
.
z
;
// Store the direction of the bone
result
[
boneID
+
"_dir_x"
]
=
bone
.
Direction
.
x
;
result
[
boneID
+
"_dir_y"
]
=
bone
.
Direction
.
y
;
result
[
boneID
+
"_dir_z"
]
=
bone
.
Direction
.
z
;
// Store the length of the bone
result
[
boneID
+
"_len"
]
=
bone
.
Length
;
}
}
}
private
static
string
DataToString
(
params
object
[]
list
)
// Store the palm of the hand
{
var
palmID
=
string
.
Join
(
"_"
,
new
string
[]{
prefix
,
"palm"
});
string
[]
strs
=
new
string
[
list
.
Length
];
result
[
palmID
+
"_pos_x"
]
=
hand
.
PalmPosition
.
x
;
result
[
palmID
+
"_pos_y"
]
=
hand
.
PalmPosition
.
y
;
result
[
palmID
+
"_pos_z"
]
=
hand
.
PalmPosition
.
z
;
result
[
palmID
+
"_rot_x"
]
=
hand
.
Rotation
.
x
;
result
[
palmID
+
"_rot_y"
]
=
hand
.
Rotation
.
y
;
result
[
palmID
+
"_rot_z"
]
=
hand
.
Rotation
.
z
;
result
[
palmID
+
"_rot_w"
]
=
hand
.
Rotation
.
w
;
}
for
(
int
i
=
0
;
i
<
list
.
Length
;
i
++)
{
private
string
FingerName
(
Finger
.
FingerType
fingerType
)
strs
[
i
]
=
list
[
i
].
ToString
();
{
switch
(
fingerType
)
{
case
Finger
.
FingerType
.
TYPE_INDEX
:
return
"index"
;
case
Finger
.
FingerType
.
TYPE_MIDDLE
:
return
"middle"
;
case
Finger
.
FingerType
.
TYPE_PINKY
:
return
"pinky"
;
case
Finger
.
FingerType
.
TYPE_RING
:
return
"ring"
;
case
Finger
.
FingerType
.
TYPE_THUMB
:
return
"thumb"
;
}
return
"unknown"
;
}
}
return
string
.
Join
(
" "
,
strs
);
private
string
BoneName
(
Bone
.
BoneType
boneType
)
{
switch
(
boneType
)
{
case
Bone
.
BoneType
.
TYPE_DISTAL
:
return
"distral"
;
case
Bone
.
BoneType
.
TYPE_INTERMEDIATE
:
return
"intermediate"
;
case
Bone
.
BoneType
.
TYPE_METACARPAL
:
return
"metacarpal"
;
case
Bone
.
BoneType
.
TYPE_PROXIMAL
:
return
"proximal"
;
}
return
"unknown"
;
}
}
public
void
UpdateGestureName
(
string
name
)
public
void
UpdateGestureName
(
string
name
)
...
...
This diff is collapsed.
Click to expand it.
aliako
@aliako
mentioned in commit
37e40c85
·
Jan 29, 2018
mentioned in commit
37e40c85
mentioned in commit 37e40c85229313ff233aaf11c1a503965222b55e
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment