Commit f02c6f43 authored by Alexander Krause's avatar Alexander Krause

increased error robustness

parent a96ed0e1
......@@ -79,14 +79,14 @@ namespace ExplorVizGestureControl.Gestures
(GestureDatabase.Joints[(int)JointType.HandRight].Y <= maxY && GestureDatabase.Joints[(int)JointType.HandRight].Y >= minY) ? true : false;
}
public void updateDynamicValues(string key, double value)
{
dynamicValues[key] = value;
if (key.Equals("zoomVelocity")) scrollTimer.changeTimerCycle(value);
}
private int oldX = 0;
private void HandleRotation()
{
......@@ -101,14 +101,17 @@ namespace ExplorVizGestureControl.Gestures
}
else { return; }
}
if (GestureDatabase.BothHandsParallel(2.0f))
if (!GestureDatabase.LeftHandClosed() &&
!GestureDatabase.HandsCrossed())
{
/*if (!rotationActive)
if (rotationActive && !GestureDatabase.HandsAboveSpineBase(1))
{
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
rotationActive = true;
} */
rotationActive = false;
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
return;
}
double distanceZ = 0;
double distanceY = 0;
......@@ -117,32 +120,17 @@ namespace ExplorVizGestureControl.Gestures
double distanceYHands = GestureDatabase.Joints[(int)JointType.HandLeft].Y - GestureDatabase.Joints[(int)JointType.HandRight].Y;
int yDetection = 0;
double handsAbsDistanceY = Math.Abs(Math.Abs(GestureDatabase.Joints[(int)JointType.HandLeft].Y) - Math.Abs(GestureDatabase.Joints[(int)JointType.HandRight].Y));
float handsAbsDistanceY = Math.Abs(Math.Abs(GestureDatabase.Joints[(int)JointType.HandLeft].Y) - Math.Abs(GestureDatabase.Joints[(int)JointType.HandRight].Y));
if (handsAbsDistanceY > 0.12f) yDetection = 500;
if (handsAbsDistanceY > 0.12) yDetection = 500;
//Console.WriteLine(handsAbsDistanceY);
distanceZ = distanceZHands - (GestureDatabase.PreviousFrameJoints[(int)JointType.HandLeft].Z - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Z);
distanceY = distanceYHands - (GestureDatabase.PreviousFrameJoints[(int)JointType.HandLeft].Y - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Y);
int moveX = (int)(distanceZ * 1000);
int moveY = (int)(distanceY * yDetection);
//////
//Console.WriteLine(distanceZ);
/* if (!rotationActive) oldX = moveX;
if (Math.Abs(Math.Abs(moveX) - Math.Abs(oldX)) > 20)
{
Console.WriteLine("active");
oldX = moveX;
moveX = 0;
}
oldX = moveX;*/
//////
int moveY = (int)(distanceY * yDetection);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y) + new Size(moveX, moveY);
}
......
......@@ -13,7 +13,7 @@ namespace ExplorVizGestureControl.Gestures
{
public static class GestureDatabase
{
public struct PhIZ
public struct PhIZ
{
public Point center;
public Point topRightCorner;
......@@ -70,16 +70,16 @@ namespace ExplorVizGestureControl.Gestures
int flagIndex = 0;
if (flags[flagIndex] == 0)
{
previousFrameJoints = (CameraSpacePoint[])filteredJoints.Clone();
{
previousFrameJoints = (CameraSpacePoint[])filteredJoints.Clone();
flags[flagIndex] = 1;
}
else
{
CopyCameraSpacePoints(joints, ref previousFrameJoints);
CopyCameraSpacePoints(joints, ref previousFrameJoints);
}
CopyCameraSpacePoints(filteredJoints, ref joints);
CopyCameraSpacePoints(filteredJoints, ref joints);
joints[(int)JointType.ShoulderRight].X = (float)accumulatedJoint[(int)JointType.ShoulderRight].X;
joints[(int)JointType.ShoulderRight].Y = (float)accumulatedJoint[(int)JointType.ShoulderRight].Y;
......@@ -111,7 +111,7 @@ namespace ExplorVizGestureControl.Gestures
dest[i].X = source[i].X;
dest[i].Y = source[i].Y;
dest[i].Z = source[i].Z;
}
}
}
#region HandStates
......@@ -125,6 +125,16 @@ namespace ExplorVizGestureControl.Gestures
{
return handLeftState == HandState.Closed ? true : false;
}
public static Boolean BothHandsOpen()
{
return !LeftHandClosed() && !RightHandClosed();
}
public static Boolean BothHandsClosed()
{
return LeftHandClosed() && RightHandClosed();
}
#endregion
#region Joint comparison
......@@ -169,48 +179,60 @@ namespace ExplorVizGestureControl.Gestures
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
}
public static Boolean BothHandsOpen()
public static Boolean BothHandsParallel(float maxDistanceInX = 0.05f)
{
return !LeftHandClosed() && !RightHandClosed();
return (Math.Abs(Math.Abs(joints[(int)JointType.HandRight].X) - Math.Abs(joints[(int)JointType.HandLeft].X)) < maxDistanceInX &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.05f);
}
public static Boolean BothHandsClosed()
public static Boolean BothHandsAboveHead()
{
return LeftHandClosed() && RightHandClosed();
return joints[(int)JointType.HandRight].Y >= joints[(int)JointType.Head].Y &&
joints[(int)JointType.HandLeft].Y >= joints[(int)JointType.Head].Y;
}
public static Boolean BothHandsParallel(float maxDistanceInX)
public static Boolean HandsAboveSpineBase(int cases = 2)
{
return (Math.Abs(joints[(int)JointType.HandRight].X - joints[(int)JointType.HandLeft].X) < maxDistanceInX &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.3 &&
Math.Abs(joints[(int)JointType.HandRight].Z - joints[(int)JointType.HandLeft].Z) < 0.3);
}
if (cases == 1) return joints[(int)JointType.HandLeft].Y >
joints[(int)JointType.SpineBase].Y ||
joints[(int)JointType.HandRight].Y >
joints[(int)JointType.SpineBase].Y;
public static Boolean BothHandsAboveHead()
{
return joints[(int)JointType.HandRight].Y >= joints[(int)JointType.Head].Y &&
joints[(int)JointType.HandLeft].Y >= joints[(int)JointType.Head].Y;
if (cases == 2) return joints[(int)JointType.HandLeft].Y >
joints[(int)JointType.SpineBase].Y &&
joints[(int)JointType.HandRight].Y >
joints[(int)JointType.SpineBase].Y;
if (cases == 3) return joints[(int)JointType.HandLeft].Y >
joints[(int)JointType.SpineBase].Y ^
joints[(int)JointType.HandRight].Y >
joints[(int)JointType.SpineBase].Y;
return false;
}
public static Boolean BothHandsAboveSpineBase()
public static Boolean HandsCrossed()
{
return joints[(int)JointType.HandLeft].Y > joints[(int)JointType.SpineBase].Y &&
joints[(int)JointType.HandRight].Y > joints[(int)JointType.SpineBase].Y;
Console.WriteLine(joints[(int)JointType.HandLeft].X - joints[(int)JointType.HandRight].X);
return joints[(int)JointType.HandLeft].X >= joints[(int)JointType.HandRight].X ? true : false;
}
public static Boolean HandsHaveAcceptableDistance(double offset = 0.0, char axis = 'x')
public static Boolean HandsHaveAcceptableDistance(float offset = 0.0f, char axis = 'x')
{
if (axis.Equals('x')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].X) -
Math.Abs(joints[(int)JointType.HandRight].X)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].X) - Math.Abs(joints[(int)JointType.ShoulderRight].X)) + offset;
Math.Abs(joints[(int)JointType.HandRight].X)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].X) -
Math.Abs(joints[(int)JointType.ShoulderRight].X)) + offset;
if (axis.Equals('y')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].Y) -
Math.Abs(joints[(int)JointType.HandRight].Y)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].Y) - Math.Abs(joints[(int)JointType.ShoulderRight].Y)) + offset;
Math.Abs(joints[(int)JointType.HandRight].Y)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].Y) -
Math.Abs(joints[(int)JointType.ShoulderRight].Y)) + offset;
if (axis.Equals('z')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].Z) -
Math.Abs(joints[(int)JointType.HandRight].Z)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].Z) - Math.Abs(joints[(int)JointType.ShoulderRight].Z)) + offset;
Math.Abs(joints[(int)JointType.HandRight].Z)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].Z) -
Math.Abs(joints[(int)JointType.ShoulderRight].Z)) + offset;
return false;
......@@ -233,8 +255,12 @@ namespace ExplorVizGestureControl.Gestures
public static Boolean ActivateRotation(float maxDistanceX = 1.0f)
{
return (Math.Abs(Math.Abs(joints[(int)JointType.HandRight].X) - Math.Abs(joints[(int)JointType.HandLeft].X)) < maxDistanceX &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.05f &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Z) - Math.Abs(joints[(int)JointType.HandLeft].Z)) < 0.05f);
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Y) - Math.Abs(joints[(int)JointType.HandLeft].Y)) < 0.05f &&
Math.Abs(Math.Abs(joints[(int)JointType.HandRight].Z) - Math.Abs(joints[(int)JointType.HandLeft].Z)) < 0.05f) &&
HandsAboveSpineBase() &&
RightHandBelowRightShoulder() &&
LeftHandBelowLeftShoulder() &&
!HandsCrossed();
}
public static Boolean StartOrReset()
......@@ -249,7 +275,6 @@ namespace ExplorVizGestureControl.Gestures
for (int i = 0; i < arrayLength; i++)
{
if (joints[(int)JointType.Head].Y > headsStack[i].Y + 0.05f)
{
confidenceArray[i] = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment