TouchTracker.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using bbiwarg.Images;
  8. using bbiwarg.Output;
  9. using bbiwarg.Recognition.Tracking;
  10. using bbiwarg.Utility;
  11. using bbiwarg.Input.InputHandling;
  12. namespace bbiwarg.Recognition.TouchRecognition
  13. {
  14. class TouchTracker : Tracker<Touch, TrackedTouch>
  15. {
  16. private List<TouchEvent> touchEvents;
  17. public TouchTracker(ImageSize imageSize)
  18. : base(imageSize)
  19. {
  20. touchEvents = new List<TouchEvent>();
  21. }
  22. public void trackTouches(FrameData frameData)
  23. {
  24. trackObjects(frameData.DetectedTouches);
  25. frameData.TrackedTouches = getOptimizedTouches();
  26. frameData.TouchEvents = flushTouchEvents();
  27. }
  28. public override float calculateSimilarity(TrackedTouch trackedTouch, Touch detectedTouch)
  29. {
  30. return (trackedTouch.FingerID == detectedTouch.Finger.TrackID) ? 1 : 0;
  31. }
  32. protected override TrackedTouch createTrackedObject(Touch detectedObject)
  33. {
  34. TrackedTouch tt = new TrackedTouch(idPool.getNextUnusedID(), detectedObject, Parameters.TouchTrackerNumFramesDetectedUntilTracked, Parameters.TouchTrackerNumFramesLostUntilDeleted);
  35. tt.TouchEvent += touchEvent;
  36. return tt;
  37. }
  38. private List<Touch> getOptimizedTouches()
  39. {
  40. List<Touch> optimizedTouchs = new List<Touch>();
  41. foreach (TrackedTouch tp in TrackedObjects)
  42. {
  43. if (tp.IsTouchActive)
  44. optimizedTouchs.Add(tp.OptimizedTouch);
  45. }
  46. return optimizedTouchs;
  47. }
  48. private void touchEvent(object sender, TouchEvent e)
  49. {
  50. touchEvents.Add(e);
  51. }
  52. public List<TouchEvent> flushTouchEvents()
  53. {
  54. List<TouchEvent> flushedTouchEvents = touchEvents;
  55. touchEvents = new List<TouchEvent>();
  56. return flushedTouchEvents;
  57. }
  58. }
  59. }