TouchEvent.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using bbiwarg.Recognition.FingerRecognition;
  7. using bbiwarg.Recognition.PalmRecognition;
  8. using bbiwarg.Recognition.Tracking;
  9. using bbiwarg.Utility;
  10. using Emgu.CV;
  11. using Emgu.CV.Structure;
  12. namespace bbiwarg.Recognition.TouchRecognition
  13. {
  14. class TouchEvent : TrackableObject
  15. {
  16. public Vector2D AbsolutePosition { get; private set; }
  17. public Vector2D RelativePosition { get; private set; }
  18. public Image<Gray, byte> TouchMask { get; private set; }
  19. public Finger Finger { get; private set; }
  20. public Palm Palm { get; private set; }
  21. public TouchEvent(Vector2D absolutePosition, Image<Gray, byte> touchMask, Finger finger, Palm palm)
  22. {
  23. AbsolutePosition = absolutePosition;
  24. RelativePosition = palm.getRelativePosition(absolutePosition);
  25. TouchMask = touchMask;
  26. Finger = finger;
  27. Palm = palm;
  28. finger.TouchEvent = this;
  29. }
  30. public float getTouchValue()
  31. {
  32. int touchPixels = TouchMask.CountNonzero()[0];
  33. int numPixels = TouchMask.Width * TouchMask.Height;
  34. float touchValue = touchPixels / (float)numPixels;
  35. return touchValue;
  36. }
  37. }
  38. }