using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using bbiwarg.Utility; using bbiwarg.Recognition.HandRecognition; using bbiwarg.Recognition.Tracking; namespace bbiwarg.Recognition.PalmRecognition { /// /// The handedness of the palm. /// public enum HandSide { Undefined = 0, Right = 1, Left = 2 } /// /// Represents a palm (each hand with one finger (thumb) has palm) /// public class Palm : TrackableObject { /// /// the hand belonging to this palm /// public Hand Hand { get; private set; } /// /// the thumb's convexity defect /// public ConvexityDefect ThumbDefect { get; private set; } /// /// the handedness /// public HandSide HandSide { get; private set; } /// /// the position of the upper wrist (top left corner for left hand, top right for right hand) /// public Vector2D WristUpper { get; private set; } /// /// the position of the upper fingers (top right for left hand, top left for left hannd) /// public Vector2D FingersUpper { get; private set; } /// /// the position of the fingers lower (bottom right for left hand, bottom left for right hand) /// public Vector2D FingersLower { get; private set; } /// /// the position of the wrist lower (bottom left for left hand, bottom right for right hand) /// public Vector2D WristLower { get; private set; } /// /// the quadrangle of the four palm points /// public Quadrangle Quad { get; private set; } /// /// Initializes a new instance of the Palm class. /// /// The hand. /// The thumb defect. /// The handedness. /// The wrist upper position. /// The fingers upper positition. /// The fingers lower position. /// The wrist lower position. public Palm(Hand hand, ConvexityDefect thumbDefect, HandSide handSide, Vector2D wristUpper, Vector2D fingersUpper, Vector2D fingersLower, Vector2D wristLower) { Hand = hand; ThumbDefect = thumbDefect; HandSide = handSide; WristUpper = wristUpper; FingersUpper = fingersUpper; FingersLower = fingersLower; WristLower = wristLower; hand.Palm = this; createQuad(); } /// /// Gets the relative position [0-1;0-1] from an absolue position. /// /// the absolute position /// the relative position public Vector2D getRelativePosition(Vector2D absolutePosition) { Vector2D relativePosition = Quad.getRelativePosition(absolutePosition); float x = Math.Max(0, Math.Min(1, relativePosition.X)); float y = Math.Max(0, Math.Min(1, relativePosition.Y)); return new Vector2D(x, y); } /// /// Checks if the position is inside the palm (with a tolerance) /// /// the absolute position /// wether the position is inside the palm public bool isInside(Vector2D position) { return Quad.isInside(position, Parameters.PalmInsideTolerance); } /// /// Creates the palm quadrangle /// private void createQuad() { if (HandSide == HandSide.Left) Quad = new Quadrangle(WristUpper, FingersUpper, FingersLower, WristLower); else Quad = new Quadrangle(FingersUpper, WristUpper, WristLower, FingersLower); } } }