PalmDetection.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MathNet.Numerics.LinearAlgebra.Single;
  7. using bbiwarg.InputProviders;
  8. using bbiwarg.VideoHandles;
  9. using bbiwarg.Helpers;
  10. namespace bbiwarg.Detectors
  11. {
  12. class PalmDetection
  13. {
  14. private IInputProvider input;
  15. private VideoHandle videoHandle;
  16. private ForeFingerDetection foreFingerDetection;
  17. public PalmDetection(IInputProvider input, VideoHandle videoHandle)
  18. {
  19. this.input = input;
  20. this.videoHandle = videoHandle;
  21. this.foreFingerDetection = new ForeFingerDetection(input, videoHandle);
  22. }
  23. public Palm getPalm(uint handIndex)
  24. {
  25. DenseVector palmMiddle = (DenseVector) input.getPalmPosition3D(handIndex);
  26. DenseVector tipPosition = (DenseVector)input.getTipPosition3D(handIndex);
  27. DenseVector palmNormal = (DenseVector)input.getPalmNormal3D(handIndex);
  28. //DenseVector thumbPosition = (DenseVector) input.getFingerTipPositions3D(handIndex)[0];
  29. //DenseVector palmToThumb_2 = (thumbPosition - palmMiddle) / 2.0f;
  30. DenseVector tipToForeFinger = tipPosition - palmMiddle;
  31. DenseVector palmToThumb_2 = (DenseVector) tipToForeFinger.Cross(palmNormal) / 3.0f;
  32. return new Palm(palmMiddle + palmToThumb_2 + tipToForeFinger,
  33. palmMiddle - palmToThumb_2 + tipToForeFinger,
  34. palmMiddle - palmToThumb_2 - tipToForeFinger / 2.0f,
  35. palmMiddle + palmToThumb_2 - tipToForeFinger / 2.0f);
  36. }
  37. }
  38. }