TouchEvent.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }
  29. public float getTouchValue()
  30. {
  31. int touchPixels = TouchMask.CountNonzero()[0];
  32. int numPixels = TouchMask.Width * TouchMask.Height;
  33. float touchValue = touchPixels / (float)numPixels;
  34. return touchValue;
  35. }
  36. }
  37. }