1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using bbiwarg.Utility;
- using Emgu.CV;
- namespace bbiwarg.Detectors.FingerDetection
- {
- class FingerSliceTrail
- {
- private List<FingerSlice> slices;
- private List<Point> pointsA;
- private List<Point> pointsB;
- public FingerSlice StartSlice { get { return slices[0]; } }
- public FingerSlice MidSlice { get { return slices[NumSlices / 2]; } }
- public FingerSlice EndSlice { get { return slices[slices.Count - 1]; } }
- public FingerSlice this[int index] { get { return slices[index]; } }
- public int NumSlices { get { return slices.Count; } }
- public LineSegment2D LineSegment { get; private set; }
- public FingerSliceTrail(FingerSlice slice)
- {
- slices = new List<FingerSlice>();
- pointsA = new List<Point>();
- pointsB = new List<Point>();
- addSlice(slice);
- }
- public void addSlice(FingerSlice slice)
- {
- slices.Add(slice);
- pointsA.Add(slice.Start - Constants.FingerContourMargin * slice.Direction);
- pointsB.Add(slice.End + Constants.FingerContourMargin * slice.Direction);
- pointsA.Add(slice.Start);
- LineSegment = new LineSegment2D(StartSlice.Mid, slice.Mid);
- }
- public Vector2D getStartDirection()
- {
- int innerStartIndex = Math.Min(NumSlices, Constants.FingerNumSlicesForRelativeDirection);
- return (EndSlice.Mid - slices[innerStartIndex].Mid).normalize();
- }
- public Vector2D getEndDirection()
- {
- int innerEndIndex = Math.Max(0, NumSlices - Constants.FingerNumSlicesForRelativeDirection);
- return (EndSlice.Mid - slices[innerEndIndex].Mid).normalize();
- }
- public void removeFirstSlices(int numSlices) {
- slices.RemoveRange(0, numSlices);
- LineSegment = new LineSegment2D(StartSlice.Mid, EndSlice.Mid);
- }
- public void reverse() {
- slices.Reverse();
- pointsA.Reverse();
- pointsB.Reverse();
- LineSegment = new LineSegment2D(StartSlice.Mid, EndSlice.Mid);
- }
- public Contour<Point> getContour()
- {
- pointsA.Reverse();
- List<Point> points = new List<Point>();
- points.AddRange(pointsA);
- points.AddRange(pointsB);
- pointsA.Reverse();
- Contour<Point> contour = new Contour<Point>(new MemStorage());
- foreach (Point p in points)
- {
- contour.Push(p);
- }
- return contour;
- }
- }
- }
|