using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using bbiwarg.Images; using bbiwarg.Output; using bbiwarg.Recognition.Tracking; using bbiwarg.Utility; using bbiwarg.Input.InputHandling; namespace bbiwarg.Recognition.TouchRecognition { /// /// Keeps track of touches over a period of time and generates touch events /// class TouchTracker : Tracker { /// /// the touch events in the current frame /// private List touchEvents; /// /// Initializes a new instance of the TouchTracker class. /// /// Size of the input image. public TouchTracker(ImageSize imageSize) : base(imageSize) { touchEvents = new List(); } /// /// Updates the tracked touches, and stores the (optimized) touches in frameData.trackedTouches and the touch events in frameData.touchEvents. /// /// public void trackTouches(FrameData frameData) { trackObjects(frameData.DetectedTouches); frameData.TrackedTouches = getOptimizedTouches(); frameData.TouchEvents = flushTouchEvents(); } /// /// Calculates the similarity [0-1] of a tracked touch and a detected touch. /// /// the tracked touch /// the detected touch /// the similarity public override float calculateSimilarity(TrackedTouch trackedTouch, Touch detectedTouch) { return (trackedTouch.FingerID == detectedTouch.Finger.TrackID) ? 1 : 0; } /// /// Creates a new TrackedTouch /// /// the detected touch /// a new TrackedTouch protected override TrackedTouch createTrackedObject(Touch detectedObject) { TrackedTouch tt = new TrackedTouch(idPool.getNextUnusedID(), detectedObject, Parameters.TouchTrackerNumFramesDetectedUntilTracked, Parameters.TouchTrackerNumFramesLostUntilDeleted); tt.TouchEvent += touchEvent; return tt; } /// /// Get all optimized representations of all tracked touches /// /// all optimized tracked touches private List getOptimizedTouches() { List optimizedTouchs = new List(); foreach (TrackedTouch tp in TrackedObjects) { if (tp.IsTouchActive) optimizedTouchs.Add(tp.OptimizedTouch); } return optimizedTouchs; } private void touchEvent(object sender, TouchEvent e) { touchEvents.Add(e); } public List flushTouchEvents() { List flushedTouchEvents = touchEvents; touchEvents = new List(); return flushedTouchEvents; } } }