InputHandler.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using bbiwarg.Images;
  2. using bbiwarg.Input.InputProviding;
  3. using bbiwarg.Recognition.FingerRecognition;
  4. using bbiwarg.Recognition.HandRecognition;
  5. using bbiwarg.Recognition.PalmRecognition;
  6. using bbiwarg.Recognition.TouchRecognition;
  7. using bbiwarg.Utility;
  8. using System;
  9. namespace bbiwarg.Input.InputHandling
  10. {
  11. public delegate void NewProcessedFrameEventHandler(InputHandler sender, EventArgs e);
  12. public class InputHandler
  13. {
  14. private FingerDetector fingerDetector;
  15. private HandDetector handDetector;
  16. private PalmDetector palmDetector;
  17. private TouchDetector touchDetector;
  18. private FingerTracker fingerTracker;
  19. private HandTracker handTracker;
  20. private PalmTracker palmTracker;
  21. private TouchTracker touchTracker;
  22. public FrameData FrameData { get; private set; }
  23. public event NewProcessedFrameEventHandler NewProcessedFrameEvent;
  24. public InputHandler()
  25. {
  26. initialize();
  27. }
  28. private void initialize()
  29. {
  30. fingerDetector = new FingerDetector();
  31. handDetector = new HandDetector();
  32. palmDetector = new PalmDetector();
  33. touchDetector = new TouchDetector();
  34. fingerTracker = new FingerTracker();
  35. handTracker = new HandTracker();
  36. palmTracker = new PalmTracker();
  37. touchTracker = new TouchTracker();
  38. }
  39. public void reset()
  40. {
  41. touchTracker.reset();
  42. handTracker.reset();
  43. palmTracker.reset();
  44. fingerTracker.reset();
  45. }
  46. public void handleNewFrame(object sender, NewFrameEventArgs e)
  47. {
  48. Timer.start("InputHandler.handleNewFrame");
  49. FrameData frameData = new FrameData();
  50. frameData.FrameID = e.FrameID;
  51. // confidence image
  52. Timer.start("InputHandler.handleNewFrame::createConfidenceImage");
  53. frameData.ConfidenceImage = new ConfidenceImage(e.RawConfidenceData, e.Width, e.Height);
  54. Timer.stop("InputHandler.handleNewFrame::createConfidenceImage");
  55. // depth image
  56. Timer.start("InputHandler.handleNewFrame::createDepthImage");
  57. frameData.DepthImage = new DepthImage(e.RawDepthData, e.Width, e.Height, frameData.ConfidenceImage);
  58. Timer.stop("InputHandler.handleNewFrame::createDepthImage");
  59. // edge image
  60. Timer.start("InputHandler.handleNewFrame::createEdgeImage");
  61. frameData.EdgeImage = new EdgeImage(frameData.DepthImage);
  62. Timer.stop("InputHandler.handleNewFrame::createEdgeImage");
  63. // detect fingers
  64. Timer.start("InputHandler.handleNewFrame::detectFingers");
  65. fingerDetector.detectFingers(frameData);
  66. Timer.stop("InputHandler.handleNewFrame::detectFingers");
  67. // track fingers
  68. Timer.start("InputHandler.handleNewFrame::trackFingers");
  69. fingerTracker.trackFingers(frameData);
  70. Timer.stop("InputHandler.handleNewFrame::trackFingers");
  71. // detect hands
  72. Timer.start("InputHandler.handleNewFrame::detectHands");
  73. handDetector.detectHands(frameData);
  74. Timer.stop("InputHandler.handleNewFrame::detectHands");
  75. // track hands
  76. Timer.start("InputHandler.handleNewFrame::trackHands");
  77. handTracker.trackHands(frameData);
  78. Timer.stop("InputHandler.handleNewFrame::trackHands");
  79. // detect palms
  80. Timer.start("InputHandler.handleNewFrame::detectPalms");
  81. palmDetector.detectPalms(frameData);
  82. Timer.stop("InputHandler.handleNewFrame::detectPalms");
  83. // track palms
  84. Timer.start("InputHandler.handleNewFrame::trackPalms");
  85. palmTracker.trackPalms(frameData);
  86. Timer.stop("InputHandler.handleNewFrame::trackPalms");
  87. // detect touches
  88. Timer.start("InputHandler.handleNewFrame::detectTouches");
  89. touchDetector.detectTouches(frameData);
  90. Timer.stop("InputHandler.handleNewFrame::detectTouches");
  91. //track touches
  92. Timer.start("InputHandler.handleNewFrame::trackTouches");
  93. touchTracker.trackTouches(frameData);
  94. Timer.stop("InputHandler.handleNewFrame::trackTouches");
  95. Timer.start("InputHandler.handleNewFrame::exportResults");
  96. FrameData = frameData;
  97. if (NewProcessedFrameEvent != null)
  98. NewProcessedFrameEvent(this, new EventArgs());
  99. Timer.stop("InputHandler.handleNewFrame::exportResults");
  100. Timer.stop("InputHandler.handleNewFrame");
  101. Timer.outputAll();
  102. }
  103. }
  104. }