FingerSliceTrail.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using bbiwarg.Utility;
  8. using Emgu.CV;
  9. namespace bbiwarg.Recognition.FingerRecognition
  10. {
  11. class FingerSliceTrail
  12. {
  13. private List<FingerSlice> slices;
  14. private List<Point> pointsA;
  15. private List<Point> pointsB;
  16. public FingerSlice StartSlice { get { return slices[0]; } }
  17. public FingerSlice MidSlice { get { return slices[NumSlices / 2]; } }
  18. public FingerSlice EndSlice { get { return slices[slices.Count - 1]; } }
  19. public FingerSlice this[int index] { get { return slices[index]; } }
  20. public int NumSlices { get { return slices.Count; } }
  21. public LineSegment2D LineSegment { get; private set; }
  22. public FingerSliceTrail(FingerSlice slice)
  23. {
  24. slices = new List<FingerSlice>();
  25. pointsA = new List<Point>();
  26. pointsB = new List<Point>();
  27. addSlice(slice);
  28. }
  29. public void addSlice(FingerSlice slice)
  30. {
  31. slices.Add(slice);
  32. pointsA.Add(slice.Start + Constants.FingerContourMargin * slice.Direction.getInverse());
  33. pointsB.Add(slice.End + Constants.FingerContourMargin * slice.Direction);
  34. pointsA.Add(slice.Start);
  35. createLineSegment();
  36. }
  37. private void createLineSegment()
  38. {
  39. LineSegment = new LineSegment2D(EndSlice.Mid, StartSlice.Mid);
  40. }
  41. public Vector2D getStartDirection()
  42. {
  43. int innerStartIndex = Math.Min(NumSlices, Constants.FingerNumSlicesForRelativeDirection);
  44. return (StartSlice.Mid - slices[innerStartIndex].Mid).normalize();
  45. }
  46. public Vector2D getEndDirection()
  47. {
  48. int innerEndIndex = Math.Max(0, NumSlices - Constants.FingerNumSlicesForRelativeDirection);
  49. return (EndSlice.Mid - slices[innerEndIndex].Mid).normalize();
  50. }
  51. public void removeFirstSlices(int numSlices)
  52. {
  53. slices.RemoveRange(0, numSlices);
  54. pointsA.RemoveRange(0, numSlices);
  55. pointsB.RemoveRange(0, numSlices);
  56. createLineSegment();
  57. }
  58. public void reverse() {
  59. slices.Reverse();
  60. pointsA.Reverse();
  61. pointsB.Reverse();
  62. List<Point> dummy = pointsA;
  63. pointsA = pointsB;
  64. pointsB = dummy;
  65. createLineSegment();
  66. }
  67. public Contour<Point> getContour()
  68. {
  69. pointsA.Reverse();
  70. List<Point> points = new List<Point>();
  71. points.AddRange(pointsA);
  72. points.AddRange(pointsB);
  73. pointsA.Reverse();
  74. Contour<Point> contour = new Contour<Point>(new MemStorage());
  75. foreach (Point p in points)
  76. {
  77. contour.Push(p);
  78. }
  79. return contour;
  80. }
  81. }
  82. }