1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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
- {
- class TouchTracker : Tracker<Touch, TrackedTouch>
- {
- private List<TouchEvent> touchEvents;
- public TouchTracker(ImageSize imageSize)
- : base(imageSize)
- {
- touchEvents = new List<TouchEvent>();
- }
- public void trackTouches(FrameData frameData)
- {
- trackObjects(frameData.DetectedTouches);
- frameData.TrackedTouches = getOptimizedTouches();
- frameData.TouchEvents = flushTouchEvents();
- }
- public override float calculateSimilarity(TrackedTouch trackedTouch, Touch detectedTouch)
- {
- return (trackedTouch.FingerID == detectedTouch.Finger.TrackID) ? 1 : 0;
- }
- protected override TrackedTouch createTrackedObject(Touch detectedObject)
- {
- TrackedTouch tt = new TrackedTouch(idPool.getNextUnusedID(), detectedObject, Parameters.TouchTrackerNumFramesDetectedUntilTracked, Parameters.TouchTrackerNumFramesLostUntilDeleted);
- tt.TouchEvent += touchEvent;
- return tt;
- }
- private List<Touch> getOptimizedTouches()
- {
- List<Touch> optimizedTouchs = new List<Touch>();
- 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<TouchEvent> flushTouchEvents()
- {
- List<TouchEvent> flushedTouchEvents = touchEvents;
- touchEvents = new List<TouchEvent>();
- return flushedTouchEvents;
- }
- }
- }
|