Skip to content
Snippets Groups Projects
Commit ae2abcca authored by Alexis Iakovenko's avatar Alexis Iakovenko
Browse files

Use our recorded datas for the comparer

parent 180d3784
No related branches found
No related tags found
No related merge requests found
Showing
with 191 additions and 900 deletions
fileFormatVersion: 2
guid: c7a51199808a93d4bbcbe974769e2560
guid: adaf5678a184383468de896590e39579
folderAsset: yes
timeCreated: 1511954648
timeCreated: 1512995892
licenseType: Free
DefaultImporter:
externalObjects: {}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CSVOutputGrid
{
public string[,] grid;
public int linesLength;
public CSVOutputGrid(string[,] grid, int linesLength)
{
this.grid = grid;
this.linesLength = linesLength;
}
}
fileFormatVersion: 2
guid: 9a84cf8a8a654ce44bcfcd5cebfba1aa
folderAsset: yes
timeCreated: 1511963617
guid: 1d952874fbd864f4294a28eec3619446
timeCreated: 1512995903
licenseType: Free
DefaultImporter:
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -11,7 +11,7 @@ public class CSVReader : MonoBehaviour
public TextAsset csvFile;
public void Start()
{
string[,] grid = SplitCsvGrid(csvFile.text);
string[,] grid = SplitCsvGrid(csvFile.text).grid;
Debug.Log("size = " + (1+ grid.GetUpperBound(0)) + "," + (1 + grid.GetUpperBound(1)));
DebugOutputGrid(grid);
......@@ -33,7 +33,7 @@ public class CSVReader : MonoBehaviour
}
// splits a CSV file into a 2D string array
static public string[,] SplitCsvGrid(string csvText)
static public CSVOutputGrid SplitCsvGrid(string csvText)
{
string[] lines = csvText.Split("\n"[0]);
......@@ -60,7 +60,7 @@ public class CSVReader : MonoBehaviour
}
}
return outputGrid;
return new CSVOutputGrid(outputGrid, lines.Length - 1);
}
// splits a CSV row
......
......@@ -4,39 +4,40 @@ using UnityEngine;
public class CompareGestureMean : MonoBehaviour
{
List<TemporaryGesture> gestures = new List<TemporaryGesture> ();
TemporaryGesture gestureToCompare;
List<Gesture> gestures = new List<Gesture> ();
Gesture gestureToCompare;
void Start ()
{
LoadGestures ();
TemporaryGesture meanGesture = ComputeMeanGesture ();
Gesture meanGesture = ComputeMeanGesture ();
CompareGestureWithMeanGesture (gestureToCompare, meanGesture);
}
void LoadGestures ()
{
//gesture to compare
gestureToCompare = new TemporaryGesture ("2");
gestureToCompare = new Gesture ("swing/1");
//gestures from data
gestures.Add (new TemporaryGesture ("1"));
gestures.Add (new TemporaryGesture ("3"));
gestures.Add (new TemporaryGesture ("4"));
gestures.Add (new TemporaryGesture ("5"));
gestures.Add (new Gesture ("swing/2"));
gestures.Add (new Gesture ("swing/3"));
gestures.Add (new Gesture ("swing/4"));
gestures.Add (new Gesture ("swing/5"));
}
TemporaryGesture ComputeMeanGesture()
Gesture ComputeMeanGesture()
{
//we assume that all gestures have same length
TemporaryGesture meanGesture = new TemporaryGesture ();
for (int i = 0; i < gestures [0].states.Count; i++)
Gesture meanGesture = new Gesture ();
for (int i = 0; i < gestures [0].states.Count * 0 + 10; i++)
{
Vector3 meanPosition = new Vector3(0, 0, 0);
foreach (TemporaryGesture gesture in gestures)
foreach (Gesture gesture in gestures)
meanPosition += gesture.states [i].position;
meanPosition /= gestures.Count;
TemporaryGestureState meanState = new TemporaryGestureState ();
GestureState meanState = new GestureState ();
meanState.timestamp = gestures [0].states [i].timestamp;
meanState.position = meanPosition;
......@@ -48,11 +49,11 @@ public class CompareGestureMean : MonoBehaviour
return meanGesture;
}
void CompareGestureWithMeanGesture(TemporaryGesture gesture, TemporaryGesture meanGesture)
void CompareGestureWithMeanGesture(Gesture gesture, Gesture meanGesture)
{
float score = 0;
for (int i = 0; i < gesture.states.Count; i++)
for (int i = 0; i < gesture.states.Count*0 + 10; i++)
{
Vector3 difference = gesture.states [i].position - meanGesture.states [i].position;
score -= Mathf.Abs(difference.x) + Mathf.Abs(difference.y) + Mathf.Abs(difference.z);
......
......@@ -3,18 +3,18 @@ using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class TemporaryGesture
public class Gesture
{
static string directoryPath = "Assets/Compare/TemporaryGestures/data/";
public List<TemporaryGestureState> states;
static string directoryPath = "Assets/Record/Recorded/";
public List<GestureState> states;
string name;
public TemporaryGesture()
public Gesture()
{
states = new List<TemporaryGestureState> ();
states = new List<GestureState> ();
}
public TemporaryGesture(string name)
public Gesture(string name)
{
this.name = name;
Load ();
......@@ -28,18 +28,18 @@ public class TemporaryGesture
//set 0 as origin/centroid
//find mean position
Vector3 meanPosition = new Vector3(0, 0, 0);
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
meanPosition += state.position;
meanPosition /= states.Count;
//subtract mean position to all positions
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
state.position -= meanPosition;
//have furthest point have distance 1
//find furthest point length
float furthestDistance = 0;
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
{
float length = state.position.magnitude;
if (length > furthestDistance)
......@@ -47,21 +47,49 @@ public class TemporaryGesture
}
//divide length to all points
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
state.position /= furthestDistance;
//time normalization: have 100 points.
/*float timeNormalizationFactor = 100.0f / states.Count;
List<GestureState> normalizedStates = new List<GestureState>();
for(int i = 0; i < states.Count; i ++)
{
GestureState normalizedState = new GestureState ();
if (i == 0 || i == states.Count - 1) //first and last elements have the same values
{
normalizedState.position = states [i].position;
normalizedState.timestamp = states [i].timestamp;
}
else
{
GestureState statePrevious = states [i - 1];
GestureState stateCurrent = states [i];
float timestampDifference = stateCurrent.timestamp - statePrevious.timestamp;
Vector3 positionDifference = stateCurrent.position - statePrevious.position;
float newTimeStamp = normalizedStates [normalizedStates.Count - 1].timestamp + timestampDifference * timeNormalizationFactor;
Vector3 newPosition = normalizedStates [normalizedStates.Count - 1].position + positionDifference * timeNormalizationFactor;
normalizedState.timestamp = newTimeStamp;
normalizedState.position = newPosition;
}
normalizedStates.Add (normalizedState);
}
Debug.Log ("Time normalization done: " + normalizedStates.Count);*/
}
public void VerifyNormalization ()
{
Vector3 meanPosition = new Vector3(0, 0, 0);
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
meanPosition += state.position;
meanPosition /= states.Count;
Debug.Log ("[VerifyNormalization] mean position: " + meanPosition);
float furthestDistance = -1;
foreach (TemporaryGestureState state in states)
foreach (GestureState state in states)
{
float length = state.position.sqrMagnitude;
if (length > furthestDistance)
......@@ -73,11 +101,12 @@ public class TemporaryGesture
public void Load ()
{
StreamReader reader = new StreamReader(directoryPath + name + ".txt");
string[,] csvStrings = CSVReader.SplitCsvGrid (reader.ReadToEnd ());
//Debug.Log("csvStrings " + name + " length:" + csvStrings.Length);
CSVOutputGrid csvGrid = CSVReader.SplitCsvGrid (reader.ReadToEnd ());
string[,] csvStrings = csvGrid.grid;
Debug.Log("csvStrings " + name + " length:" + csvGrid.linesLength);
states = new List<TemporaryGestureState>();
for (int i = 0; i < 100; i++)
states = new List<GestureState>();
for (int i = 0; i < csvGrid.linesLength; i++)
{
if (i < 2) //dont take 2 first lines into account
continue;
......@@ -88,11 +117,11 @@ public class TemporaryGesture
//we need timestamp, x, y, z of palm
string[] line = csvStrings[0,i].Split (' ');
TemporaryGestureState state = new TemporaryGestureState ();
state.timestamp = int.Parse(line [2]);
state.position.x = float.Parse(line [13]);
state.position.y = float.Parse(line [14]);
state.position.z = float.Parse(line [15]);
GestureState state = new GestureState ();
state.timestamp = float.Parse(line [0]);
state.position.x = float.Parse(line [1]);
state.position.y = float.Parse(line [2]);
state.position.z = float.Parse(line [3]);
states.Add (state);
//Debug.Log(state);
......
fileFormatVersion: 2
guid: ee5ae9629eb5b5f439afcd95ba6e0655
guid: 028d06b34758d8747bb191981dabd299
timeCreated: 1511960149
licenseType: Free
MonoImporter:
......
......@@ -2,9 +2,9 @@
using System.Collections.Generic;
using UnityEngine;
public class TemporaryGestureState {
public class GestureState {
public int timestamp = 0;
public float timestamp = 0;
public Vector3 position = new Vector3(0, 0, 0);
public override string ToString()
......
fileFormatVersion: 2
guid: fa855f9ff91cb9444aa07c03f15c1ae3
guid: b3a705ff935f173409f36717340c1f6e
timeCreated: 1511959669
licenseType: Free
MonoImporter:
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
fileFormatVersion: 2
guid: 9d14b81c24767b746ae1704214752f0d
timeCreated: 1511954655
licenseType: Free
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 02bb12a352e7d6d45bb18e20e5ba85e1
timeCreated: 1511954655
licenseType: Free
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 170f16928fb69c94e99b0c426e1bb40c
timeCreated: 1511954655
licenseType: Free
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 2d24e1f18cd3871488304aa344594454
timeCreated: 1511954655
licenseType: Free
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment