PalmDetection.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace bbiwarg.DataSource
  8. {
  9. class PalmDetection
  10. {
  11. private IInputProvider input;
  12. private IVideoHandle videoHandle;
  13. private ForeFingerDetection foreFingerDetection;
  14. public PalmDetection(IInputProvider input, IVideoHandle videoHandle)
  15. {
  16. this.input = input;
  17. this.videoHandle = videoHandle;
  18. this.foreFingerDetection = new ForeFingerDetection(input, videoHandle);
  19. }
  20. public Palm getPalm(uint handIndex)
  21. {
  22. DenseVector palmMiddle = (DenseVector) input.getPalmPosition3D(handIndex);
  23. DenseVector tipPosition = (DenseVector)input.getTipPosition3D(handIndex);
  24. DenseVector palmNormal = (DenseVector)input.getPalmNormal3D(handIndex);
  25. //DenseVector thumbPosition = (DenseVector) input.getFingerTipPositions3D(handIndex)[0];
  26. //DenseVector palmToThumb_2 = (thumbPosition - palmMiddle) / 2.0f;
  27. DenseVector tipToForeFinger = tipPosition - palmMiddle;
  28. DenseVector palmToThumb_2 = (DenseVector) tipToForeFinger.Cross(palmNormal) / 3.0f;
  29. return new Palm(palmMiddle + palmToThumb_2 + tipToForeFinger,
  30. palmMiddle - palmToThumb_2 + tipToForeFinger,
  31. palmMiddle - palmToThumb_2 - tipToForeFinger / 2.0f,
  32. palmMiddle + palmToThumb_2 - tipToForeFinger / 2.0f);
  33. }
  34. }
  35. }