|
@@ -23,7 +23,6 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
public FingerDetector(DepthImage depthImage, EdgeImage edgeImage, OutputImage outputImage)
|
|
|
{
|
|
|
- Console.WriteLine("---");
|
|
|
this.depthImage = depthImage;
|
|
|
this.edgeImageOriginal = edgeImage;
|
|
|
this.edgeImageAdapted = edgeImage.copy();
|
|
@@ -35,8 +34,8 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private void detectFingers()
|
|
|
{
|
|
|
- int maxX = depthImage.Width - 1;
|
|
|
- int maxY = depthImage.Height - 1;
|
|
|
+ int maxX = depthImage.BottomRight.IntX;
|
|
|
+ int maxY = depthImage.BottomRight.IntY;
|
|
|
|
|
|
Fingers = new List<Finger>();
|
|
|
|
|
@@ -83,15 +82,12 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private FingerSliceTrail findFingerSliceTrail(FingerSlice startSlice, Vector2D startDirection)
|
|
|
{
|
|
|
- int maxX = depthImage.Width - 1;
|
|
|
- int maxY = depthImage.Height - 1;
|
|
|
-
|
|
|
FingerSliceTrail trail = new FingerSliceTrail(startSlice);
|
|
|
|
|
|
Vector2D direction = startDirection;
|
|
|
Vector2D position = startSlice.Mid + Constants.FingerStepSize * direction;
|
|
|
|
|
|
- if (position.isWithin(0, 0, maxX, maxY))
|
|
|
+ if (position.isInBound(Vector2D.Zero, depthImage.BottomRight))
|
|
|
{
|
|
|
FingerSlice nextSlice = findFingerSliceFromMid(position, direction);
|
|
|
if (nextSlice != null)
|
|
@@ -116,9 +112,6 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private FingerSliceTrail expandTrail(FingerSliceTrail trail, bool reversed = false)
|
|
|
{
|
|
|
- int maxX = depthImage.Width - 1;
|
|
|
- int maxY = depthImage.Height - 1;
|
|
|
-
|
|
|
Vector2D currentDirection = trail.getEndDirection();
|
|
|
Vector2D currentPosition = trail.EndSlice.Mid + Constants.FingerStepSize * currentDirection;
|
|
|
|
|
@@ -128,7 +121,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
FingerSlice lastSlice = trail.EndSlice;
|
|
|
FingerSlice nextSlice;
|
|
|
|
|
|
- while (currentPosition.isWithin(0, 0, maxX, maxY) && gapCounter <= Math.Min(numSlices, Constants.FingerMaxGapCounter))
|
|
|
+ while (currentPosition.isInBound(Vector2D.Zero, depthImage.BottomRight) && gapCounter <= Math.Min(numSlices, Constants.FingerMaxGapCounter))
|
|
|
{
|
|
|
if (reversed)
|
|
|
nextSlice = findFingerSliceFromMid(currentPosition, currentDirection.getInverse());
|
|
@@ -180,22 +173,23 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private Vector2D findNextEdge(Vector2D start, Vector2D direction, bool adaptedEdgeImage = true, bool stopAtMaxFingerSize = true, bool returnBoundIfNoEdge = false)
|
|
|
{
|
|
|
- int maxX = depthImage.Width - 1;
|
|
|
- int maxY = depthImage.Height - 1;
|
|
|
+ Vector2D max = depthImage.BottomRight;
|
|
|
+ Vector2D maxGrow = (max - start) / direction;
|
|
|
+ Vector2D maxDecline = start / direction.getAbsolute();
|
|
|
|
|
|
int maxStepsX;
|
|
|
if (direction.X > 0)
|
|
|
- maxStepsX = (int)((maxX - start.X) / direction.X);
|
|
|
+ maxStepsX = maxGrow.IntX;
|
|
|
else if (direction.X < 0)
|
|
|
- maxStepsX = (int)(start.X / Math.Abs(direction.X));
|
|
|
+ maxStepsX = maxDecline.IntX;
|
|
|
else
|
|
|
maxStepsX = int.MaxValue;
|
|
|
|
|
|
int maxStepsY;
|
|
|
if (direction.Y > 0)
|
|
|
- maxStepsY = (int)((maxY - start.Y) / direction.Y);
|
|
|
+ maxStepsY = maxGrow.IntY;
|
|
|
else if (direction.Y < 0)
|
|
|
- maxStepsY = (int)(start.Y / Math.Abs(direction.Y));
|
|
|
+ maxStepsY = maxDecline.IntY;
|
|
|
else
|
|
|
maxStepsY = int.MaxValue;
|
|
|
|
|
@@ -227,8 +221,9 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
int maxY = depthImage.Height - 1;
|
|
|
|
|
|
Vector2D direction = (end - start).normalize();
|
|
|
- Vector2D beforeStart = (start - Constants.FingerSliceOverlapFactor * direction).moveInBound(0, 0, maxX, maxY);
|
|
|
- Vector2D behindEnd = (end + Constants.FingerSliceOverlapFactor * direction).moveInBound(0, 0, maxY, maxY);
|
|
|
+ Vector2D directionInv = direction.getInverse();
|
|
|
+ Vector2D beforeStart = (start + Constants.FingerSliceOverlapFactor * directionInv).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction);
|
|
|
+ Vector2D behindEnd = (end + Constants.FingerSliceOverlapFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, directionInv);
|
|
|
|
|
|
FingerSlice slice = new FingerSlice(beforeStart, behindEnd);
|
|
|
if (slice.Length >= Constants.FingerMinSize && slice.Length <= Constants.FingerMaxSize && fingerSliceDepthTest(slice))
|
|
@@ -256,8 +251,6 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
//add finger
|
|
|
if (!isCrippleFinger(finger))
|
|
|
Fingers.Add(finger);
|
|
|
- else
|
|
|
- Console.WriteLine("cripple");
|
|
|
|
|
|
//remove edges around detected finger to improve performance
|
|
|
edgeImageAdapted.removeEdgesInsidePolygon(finger.Contour.ToArray());
|
|
@@ -270,8 +263,9 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
FingerSlice midSlice = finger.SliceTrail.MidSlice;
|
|
|
Vector2D direction = midSlice.Direction;
|
|
|
- Vector2D out1 = (midSlice.Start - Constants.FingerCrippleOutFactor * direction).moveInBound(0, 0, maxX, maxY);
|
|
|
- Vector2D out2 = (midSlice.End + Constants.FingerCrippleOutFactor * direction).moveInBound(0, 0, maxX, maxY);
|
|
|
+ Vector2D directionInv = direction.getInverse();
|
|
|
+ Vector2D out1 = (midSlice.Start + Constants.FingerCrippleOutFactor * directionInv).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction);
|
|
|
+ Vector2D out2 = (midSlice.End + Constants.FingerCrippleOutFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, directionInv);
|
|
|
|
|
|
Int16 depthAtFinger = depthImage.getDepthAt(midSlice.Mid);
|
|
|
Int16 depthAtOut1 = depthImage.getDepthAt(out1);
|
|
@@ -289,7 +283,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
Vector2D dirOrth1 = direction.getOrthogonal(true);
|
|
|
Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
|
|
|
|
- Vector2D outPoint = (start + Constants.FingerOutSliceFactor * direction).moveInBound(0, 0, maxX, maxY);
|
|
|
+ Vector2D outPoint = (start + Constants.FingerOutSliceFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction.getInverse());
|
|
|
Vector2D p1 = findNextEdge(outPoint, dirOrth1, false, false, true);
|
|
|
Vector2D p2 = findNextEdge(outPoint, dirOrth2, false, false, true);
|
|
|
|
|
@@ -314,10 +308,10 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
float startOutLength = float.MaxValue;
|
|
|
float endOutLength = float.MaxValue;
|
|
|
|
|
|
- if (startOutSlice.Start.isWithin(1, 1, maxX, maxY) && startOutSlice.End.isWithin(1, 1, maxX, maxY))
|
|
|
+ if (startOutSlice.Start.isInBound(Vector2D.Zero, depthImage.BottomRight) && startOutSlice.End.isInBound(Vector2D.Zero, depthImage.BottomRight))
|
|
|
startOutLength = startOutSlice.Length;
|
|
|
|
|
|
- if (endOutSlice.Start.isWithin(1, 1, maxX, maxY) && endOutSlice.End.isWithin(1, 1, maxX, maxY))
|
|
|
+ if (endOutSlice.Start.isInBound(Vector2D.Zero, depthImage.BottomRight) && endOutSlice.End.isInBound(Vector2D.Zero, depthImage.BottomRight))
|
|
|
endOutLength = endOutSlice.Length;
|
|
|
|
|
|
if (startOutLength <= endOutLength)
|