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

Tweak algorithm

parent b457a8a5
No related branches found
No related tags found
No related merge requests found
...@@ -150,21 +150,14 @@ public class Gesture ...@@ -150,21 +150,14 @@ public class Gesture
timestampVariance += (gesture.states [i].timestamp - gestureMean.states [i].timestamp) * timestampVariance += (gesture.states [i].timestamp - gestureMean.states [i].timestamp) *
(gesture.states [i].timestamp - gestureMean.states [i].timestamp); (gesture.states [i].timestamp - gestureMean.states [i].timestamp);
positionVariance.x += (gesture.states [i].position.x - gestureMean.states [i].position.x) * positionVariance.x += Mathf.Abs(gesture.states [i].position.x - gestureMean.states [i].position.x);
(gesture.states [i].position.x - gestureMean.states [i].position.x); positionVariance.y += Mathf.Abs(gesture.states [i].position.y - gestureMean.states [i].position.y);
positionVariance.y += (gesture.states [i].position.y - gestureMean.states [i].position.y) * positionVariance.z += Mathf.Abs(gesture.states [i].position.z - gestureMean.states [i].position.z);
(gesture.states [i].position.y - gestureMean.states [i].position.y);
positionVariance.z += (gesture.states [i].position.z - gestureMean.states [i].position.z) * rotationVariance.x += Mathf.Abs(gesture.states [i].rotation.x - gestureMean.states [i].rotation.x);
(gesture.states [i].position.z - gestureMean.states [i].position.z); rotationVariance.y += Mathf.Abs(gesture.states [i].rotation.y - gestureMean.states [i].rotation.y);
rotationVariance.z += Mathf.Abs(gesture.states [i].rotation.z - gestureMean.states [i].rotation.z);
rotationVariance.x += (gesture.states [i].rotation.x - gestureMean.states [i].rotation.x) * rotationVariance.w += Mathf.Abs(gesture.states [i].rotation.w - gestureMean.states [i].rotation.w);
(gesture.states [i].rotation.x - gestureMean.states [i].rotation.x);
rotationVariance.y += (gesture.states [i].rotation.y - gestureMean.states [i].rotation.y) *
(gesture.states [i].rotation.y - gestureMean.states [i].rotation.y);
rotationVariance.z += (gesture.states [i].rotation.z - gestureMean.states [i].rotation.z) *
(gesture.states [i].rotation.z - gestureMean.states [i].rotation.z);
rotationVariance.w += (gesture.states [i].rotation.w - gestureMean.states [i].rotation.w) *
(gesture.states [i].rotation.w - gestureMean.states [i].rotation.w);
gestureCount ++; gestureCount ++;
} }
......
This diff is collapsed.
fileFormatVersion: 2 fileFormatVersion: 2
guid: 761c35c7651e4d24a8e2c0172ee58f86 guid: 761c35c7651e4d24a8e2c0172ee58f86
timeCreated: 1515946978 timeCreated: 1515950200
licenseType: Free licenseType: Free
TextScriptImporter: TextScriptImporter:
externalObjects: {} externalObjects: {}
......
...@@ -11,6 +11,7 @@ public class LiveComparer : MonoBehaviour ...@@ -11,6 +11,7 @@ public class LiveComparer : MonoBehaviour
public GameObject totalScoreLabel = null; public GameObject totalScoreLabel = null;
public Replay replay = null; public Replay replay = null;
public LeapServiceProvider LeapService = null; public LeapServiceProvider LeapService = null;
public float scoreOffset = 70.0f;
float acceptableScore = 150.0f; float acceptableScore = 150.0f;
float totalScore = 0.0f; float totalScore = 0.0f;
...@@ -30,17 +31,6 @@ public class LiveComparer : MonoBehaviour ...@@ -30,17 +31,6 @@ public class LiveComparer : MonoBehaviour
totalScore = 0.0f; totalScore = 0.0f;
frameScore = 0.0f; frameScore = 0.0f;
sumScore = 0.0f; sumScore = 0.0f;
UpdateOffsetPosition ();
}
void UpdateOffsetPosition ()
{
if (replay.currentFrame >= 0 && replay.currentFrame < 100)
{
FetchPalmsCoordinates ();
offsetPosition = leftPalmPosition - replay.gestureToReplay.states [replay.currentFrame].position;
}
} }
void Update () void Update ()
...@@ -48,6 +38,10 @@ public class LiveComparer : MonoBehaviour ...@@ -48,6 +38,10 @@ public class LiveComparer : MonoBehaviour
if (replay.currentFrame >= 0 && replay.currentFrame < 100) if (replay.currentFrame >= 0 && replay.currentFrame < 100)
{ {
FetchPalmsCoordinates (); FetchPalmsCoordinates ();
if (replay.currentFrame == 0)
UpdateOffsetPosition ();
ComputeFrameScore (); ComputeFrameScore ();
if (replay.currentFrame != lastFrame) if (replay.currentFrame != lastFrame)
...@@ -60,49 +54,26 @@ public class LiveComparer : MonoBehaviour ...@@ -60,49 +54,26 @@ public class LiveComparer : MonoBehaviour
} }
} }
void UpdateOffsetPosition ()
{
offsetPosition = replay.gestureToReplay.states [replay.currentFrame].position - leftPalmPosition;
}
void ComputeFrameScore() void ComputeFrameScore()
{ {
//for now we only consider the left hand //for now we only consider the left hand
frameScore = 100.0f; frameScore = scoreOffset;
acceptableScore = 100.0f; float scoreFactor = 100.0f;
float generalFactor = 1; Vector3 differencePosition = offsetPosition + leftPalmPosition - replay.gestureToReplay.states [replay.currentFrame].position;
Vector4 differenceRotation = leftPalmRotation - replay.gestureToReplay.states [replay.currentFrame].rotation;
float positionFactor = 15.0f; Vector3 variancePosition = replay.gestureVariance.states [replay.currentFrame].position;
float rotationFactor = 15.0f; Vector4 varianceRotation = replay.gestureVariance.states [replay.currentFrame].rotation;
Vector3 differencePosition = offsetPosition + leftPalmPosition - float scorePosition = variancePosition.magnitude - differencePosition.magnitude;
replay.gestureToReplay.states [replay.currentFrame].position; float scoreRotation = varianceRotation.magnitude - differenceRotation.magnitude;
Vector4 differenceRotation = leftPalmRotation -
replay.gestureToReplay.states [replay.currentFrame].rotation; frameScore += (scorePosition + scoreRotation) * scoreFactor;
float absoluteDifferencePosition = Mathf.Abs(generalFactor * differencePosition.x) +
Mathf.Abs(generalFactor * differencePosition.y) +
Mathf.Abs(generalFactor * differencePosition.z) * positionFactor;
float absoluteDifferenceRotation = Mathf.Abs(generalFactor * differenceRotation.x) +
Mathf.Abs(generalFactor * differenceRotation.y) +
Mathf.Abs(generalFactor * differenceRotation.z) +
Mathf.Abs(generalFactor * differenceRotation.w) * rotationFactor;
//use variance
Vector3 variancePosition = leftPalmPosition -
replay.gestureVariance.states [replay.currentFrame].position;
Vector4 varianceRotation = leftPalmRotation -
replay.gestureVariance.states [replay.currentFrame].rotation;
float absoluteDifferencePositionVariance = Mathf.Abs(generalFactor * variancePosition.x) +
Mathf.Abs(generalFactor * variancePosition.y) +
Mathf.Abs(generalFactor * variancePosition.z);
float absoluteDifferenceRotationVariance = Mathf.Abs(generalFactor * varianceRotation.x) +
Mathf.Abs(generalFactor * varianceRotation.y) +
Mathf.Abs(generalFactor * varianceRotation.z) +
Mathf.Abs(generalFactor * varianceRotation.w);
//compute score based on difference with variance
float scorePosition = absoluteDifferencePositionVariance - absoluteDifferencePosition;
float scoreRotation = absoluteDifferenceRotation - absoluteDifferenceRotationVariance;
frameScore -= scorePosition + scoreRotation;
} }
void ComputeTotalScore() void ComputeTotalScore()
...@@ -145,12 +116,12 @@ public class LiveComparer : MonoBehaviour ...@@ -145,12 +116,12 @@ public class LiveComparer : MonoBehaviour
else else
{ {
//Debug.Log ("[UpdateScoreLabels] acc: " + acceptableScore); //Debug.Log ("[UpdateScoreLabels] acc: " + acceptableScore);
if (frameScore > acceptableScore) if (frameScore > 0)
frameScoreLabel.GetComponent<Text> ().color = new Color (0.0f, 0.7f, 0.0f); frameScoreLabel.GetComponent<Text> ().color = new Color (0.0f, 0.7f, 0.0f);
else else
frameScoreLabel.GetComponent<Text> ().color = new Color (0.7f, 0.0f, 0.0f); frameScoreLabel.GetComponent<Text> ().color = new Color (0.7f, 0.0f, 0.0f);
if (totalScore > acceptableScore) if (totalScore > 0)
totalScoreLabel.GetComponent<Text> ().color = new Color (0.0f, 0.7f, 0.0f); totalScoreLabel.GetComponent<Text> ().color = new Color (0.0f, 0.7f, 0.0f);
else else
totalScoreLabel.GetComponent<Text> ().color = new Color (0.7f, 0.0f, 0.0f); totalScoreLabel.GetComponent<Text> ().color = new Color (0.7f, 0.0f, 0.0f);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment