|
@@ -12,14 +12,8 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
class FingerSliceTrail
|
|
|
{
|
|
|
private LineSegment2D lineSegment;
|
|
|
- private Contour<Point> contour;
|
|
|
- private Contour<Point> innerContour;
|
|
|
- private Contour<Point> outerContour;
|
|
|
private Vector2D fittedDirection;
|
|
|
private bool lineSegmentUpToDate;
|
|
|
- private bool contourUpToDate;
|
|
|
- private bool innerContourUpToDate;
|
|
|
- private bool outerContourUpToDate;
|
|
|
private bool fittedDirectionUpToDate;
|
|
|
|
|
|
public List<FingerSlice> Slices { get; private set; }
|
|
@@ -29,9 +23,6 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
public FingerSlice this[int index] { get { return Slices[index]; } }
|
|
|
public int NumSlices { get { return Slices.Count; } }
|
|
|
public LineSegment2D LineSegment { get { if (!lineSegmentUpToDate) updateLineSegment(); return lineSegment; } }
|
|
|
- public Contour<Point> Contour { get { if (!contourUpToDate) updateContour(); return contour; } }
|
|
|
- public Contour<Point> InnerContour { get { if (!innerContourUpToDate) updateInnerContour(); return innerContour; } }
|
|
|
- public Contour<Point> OuterContour { get { if (!outerContourUpToDate) updateOuterContour(); return outerContour; } }
|
|
|
public Vector2D FittedDirection { get { if (!fittedDirectionUpToDate) updateFittedDirection(); return fittedDirection; } }
|
|
|
|
|
|
public FingerSliceTrail(FingerSlice slice)
|
|
@@ -39,7 +30,6 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
Slices = new List<FingerSlice>();
|
|
|
addSlice(slice);
|
|
|
lineSegmentUpToDate = false;
|
|
|
- contourUpToDate = false;
|
|
|
fittedDirectionUpToDate = false;
|
|
|
}
|
|
|
|
|
@@ -47,13 +37,12 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
{
|
|
|
Slices.Add(slice);
|
|
|
lineSegmentUpToDate = false;
|
|
|
- contourUpToDate = false;
|
|
|
fittedDirectionUpToDate = false;
|
|
|
}
|
|
|
|
|
|
public Vector2D getStartDirection()
|
|
|
{
|
|
|
- int innerStartIndex = Math.Min(NumSlices, Parameters.FingerNumSlicesForRelativeDirection);
|
|
|
+ int innerStartIndex = Math.Min(NumSlices-1, Parameters.FingerNumSlicesForRelativeDirection);
|
|
|
return (StartSlice.Mid - Slices[innerStartIndex].Mid).normalize();
|
|
|
}
|
|
|
|
|
@@ -67,7 +56,6 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
{
|
|
|
Slices.RemoveRange(0, numSlices);
|
|
|
lineSegmentUpToDate = false;
|
|
|
- contourUpToDate = false;
|
|
|
fittedDirectionUpToDate = false;
|
|
|
}
|
|
|
|
|
@@ -75,101 +63,52 @@ namespace bbiwarg.Recognition.FingerRecognition
|
|
|
{
|
|
|
Slices.Reverse();
|
|
|
lineSegmentUpToDate = false;
|
|
|
- contourUpToDate = false;
|
|
|
fittedDirectionUpToDate = false;
|
|
|
}
|
|
|
|
|
|
- private void updateLineSegment()
|
|
|
- {
|
|
|
- lineSegment = new LineSegment2D(EndSlice.Mid, StartSlice.Mid);
|
|
|
-
|
|
|
- lineSegmentUpToDate = true;
|
|
|
- }
|
|
|
-
|
|
|
- private void updateFittedDirection()
|
|
|
- {
|
|
|
- List<PointF> midPoints = new List<PointF>();
|
|
|
- foreach (FingerSlice slice in Slices)
|
|
|
- midPoints.Add(slice.Mid);
|
|
|
-
|
|
|
- PointF pointOnLine, direction;
|
|
|
- PointCollection.Line2DFitting(midPoints.ToArray(), Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_FAIR, out direction, out pointOnLine);
|
|
|
- fittedDirection = new Vector2D(direction).normalize();
|
|
|
-
|
|
|
- if (fittedDirection.isInOppositeDirection(LineSegment.Direction))
|
|
|
- fittedDirection = fittedDirection.getInverse();
|
|
|
-
|
|
|
- fittedDirectionUpToDate = true;
|
|
|
- }
|
|
|
-
|
|
|
- private void updateContour()
|
|
|
- {
|
|
|
+ public Contour<Point> getContour(float margin) {
|
|
|
List<Point> pointsA = new List<Point>();
|
|
|
List<Point> pointsB = new List<Point>();
|
|
|
|
|
|
foreach (FingerSlice slice in Slices)
|
|
|
{
|
|
|
- pointsA.Add(slice.ContourStart);
|
|
|
- pointsB.Add(slice.ContourEnd);
|
|
|
+ Vector2D direction = slice.Direction;
|
|
|
+ pointsA.Add(slice.Start.moveWithinBound(direction.getInverse(), margin));
|
|
|
+ pointsB.Add(slice.End.moveWithinBound(direction, margin));
|
|
|
}
|
|
|
|
|
|
pointsA.Reverse();
|
|
|
pointsA.AddRange(pointsB);
|
|
|
|
|
|
- contour = new Contour<Point>(new MemStorage());
|
|
|
+ Contour<Point> contour = new Contour<Point>(new MemStorage());
|
|
|
foreach (Point p in pointsA)
|
|
|
{
|
|
|
contour.Push(p);
|
|
|
}
|
|
|
- contourUpToDate = true;
|
|
|
+ return contour;
|
|
|
}
|
|
|
|
|
|
- private void updateInnerContour()
|
|
|
+ private void updateLineSegment()
|
|
|
{
|
|
|
- List<Point> pointsA = new List<Point>();
|
|
|
- List<Point> pointsB = new List<Point>();
|
|
|
-
|
|
|
- foreach (FingerSlice slice in Slices)
|
|
|
- {
|
|
|
- pointsA.Add(slice.Start);
|
|
|
- pointsB.Add(slice.End);
|
|
|
- }
|
|
|
-
|
|
|
- pointsA.Reverse();
|
|
|
- pointsA.AddRange(pointsB);
|
|
|
-
|
|
|
- innerContour = new Contour<Point>(new MemStorage());
|
|
|
- foreach (Point p in pointsA)
|
|
|
- {
|
|
|
- innerContour.Push(p);
|
|
|
- }
|
|
|
- innerContourUpToDate = true;
|
|
|
+ lineSegment = new LineSegment2D(EndSlice.Mid, StartSlice.Mid);
|
|
|
+ lineSegmentUpToDate = true;
|
|
|
}
|
|
|
|
|
|
- private void updateOuterContour()
|
|
|
+ private void updateFittedDirection()
|
|
|
{
|
|
|
- List<Point> pointsA = new List<Point>();
|
|
|
- List<Point> pointsB = new List<Point>();
|
|
|
-
|
|
|
+ List<PointF> midPoints = new List<PointF>();
|
|
|
foreach (FingerSlice slice in Slices)
|
|
|
- {
|
|
|
- pointsA.Add(slice.OutStart);
|
|
|
- pointsB.Add(slice.OutEnd);
|
|
|
- }
|
|
|
-
|
|
|
- pointsA.Reverse();
|
|
|
- pointsA.AddRange(pointsB);
|
|
|
-
|
|
|
- outerContour = new Contour<Point>(new MemStorage());
|
|
|
- foreach (Point p in pointsA)
|
|
|
- {
|
|
|
- outerContour.Push(p);
|
|
|
- }
|
|
|
- outerContourUpToDate = true;
|
|
|
- }
|
|
|
+ midPoints.Add(slice.Mid);
|
|
|
|
|
|
+ PointF pointOnLine, direction;
|
|
|
+ PointCollection.Line2DFitting(midPoints.ToArray(), Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_FAIR, out direction, out pointOnLine);
|
|
|
+ fittedDirection = new Vector2D(direction).normalize();
|
|
|
|
|
|
+ if (fittedDirection.isInOppositeDirection(LineSegment.Direction))
|
|
|
+ fittedDirection = fittedDirection.getInverse();
|
|
|
|
|
|
+ fittedDirectionUpToDate = true;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|