|
@@ -36,7 +36,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
Fingers = new List<Finger>();
|
|
|
|
|
|
- for (int y = 1; y < maxY; y+=5) //y++ for 100% coverage, but y+=5 for 99% coverage and 3 times better perfomance
|
|
|
+ for (int y = 1; y < maxY; y += 5) //y++ for 100% coverage, but y+=5 for 99% coverage and 3 times better perfomance
|
|
|
{
|
|
|
for (int x = 1; x < maxX; x++)
|
|
|
{
|
|
@@ -169,7 +169,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
return getFingerSlice(start, end);
|
|
|
}
|
|
|
|
|
|
- private Vector2D findNextEdge(Vector2D start, Vector2D direction)
|
|
|
+ private Vector2D findNextEdge(Vector2D start, Vector2D direction, bool stopAtMaxFingerSize = true, bool returnBoundIfNoEdge = false)
|
|
|
{
|
|
|
int maxX = depthImage.Width - 1;
|
|
|
int maxY = depthImage.Height - 1;
|
|
@@ -190,9 +190,10 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
else
|
|
|
maxStepsY = int.MaxValue;
|
|
|
|
|
|
- int maxStepsLength = (int)(Constants.FingerMaxSize / direction.Length);
|
|
|
+ int maxSteps = Math.Min(maxStepsX, maxStepsY);
|
|
|
|
|
|
- int maxSteps = Math.Min(maxStepsLength, Math.Min(maxStepsX, maxStepsY));
|
|
|
+ if (stopAtMaxFingerSize)
|
|
|
+ maxSteps = Math.Min(maxSteps, (int)(Constants.FingerMaxSize / direction.Length));
|
|
|
|
|
|
Vector2D end = new Vector2D(start);
|
|
|
for (int i = 0; i < maxSteps; i++)
|
|
@@ -204,7 +205,11 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
return end;
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ if (returnBoundIfNoEdge)
|
|
|
+ return end;
|
|
|
+ else
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private FingerSlice getFingerSlice(Vector2D start, Vector2D end)
|
|
@@ -233,6 +238,10 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private void createFingerFromTrail(FingerSliceTrail trail)
|
|
|
{
|
|
|
+ //bring finger in correct direction Tip->Hand
|
|
|
+ trail = orderTrailTipToHand(trail);
|
|
|
+
|
|
|
+ //create finger
|
|
|
Finger finger = new Finger(trail);
|
|
|
|
|
|
//add finger
|
|
@@ -245,6 +254,53 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
edgeImage.removeFingerEdges(finger);
|
|
|
}
|
|
|
|
|
|
+ private FingerSlice findOutSlice(Vector2D start, Vector2D direction)
|
|
|
+ {
|
|
|
+ int maxX = depthImage.Width - 1;
|
|
|
+ int maxY = depthImage.Height - 1;
|
|
|
+
|
|
|
+ Vector2D dirOrth1 = direction.getOrthogonal(true);
|
|
|
+ Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
|
+
|
|
|
+ Vector2D outPoint = (start + Constants.FingerOutSliceFactor * Constants.FingerStepSize * direction).moveInBound(0, 0, maxX, maxY);
|
|
|
+ Vector2D p1 = findNextEdge(outPoint, dirOrth1, false, true);
|
|
|
+ Vector2D p2 = findNextEdge(outPoint, dirOrth2, false, true);
|
|
|
+
|
|
|
+ FingerSlice slice = new FingerSlice(p1, p2);
|
|
|
+
|
|
|
+ outputImage.drawLineSegment(slice.LineSegment, Constants.FingerOutSliceColor);
|
|
|
+
|
|
|
+ return slice;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FingerSliceTrail orderTrailTipToHand(FingerSliceTrail trail)
|
|
|
+ {
|
|
|
+ int maxX = depthImage.Width - 1;
|
|
|
+ int maxY = depthImage.Height - 1;
|
|
|
+
|
|
|
+ FingerSlice start = trail.Start;
|
|
|
+ FingerSlice end = trail.End;
|
|
|
+
|
|
|
+ Vector2D direction = (end.Mid - start.Mid).normalize();
|
|
|
+
|
|
|
+ FingerSlice startOutSlice = findOutSlice(start.Mid, -1 * direction);
|
|
|
+ FingerSlice endOutSlice = findOutSlice(end.Mid, direction);
|
|
|
+
|
|
|
+ float startOutLength = float.MaxValue;
|
|
|
+ float endOutLength = float.MaxValue;
|
|
|
+
|
|
|
+ if (!startOutSlice.Start.isOnBound(0, 0, maxX, maxY) && startOutSlice.End.isOnBound(0, 0, maxX, maxY))
|
|
|
+ startOutLength = startOutSlice.Length;
|
|
|
+
|
|
|
+ if (!endOutSlice.Start.isOnBound(0, 0, maxX, maxY) && endOutSlice.End.isOnBound(0, 0, maxX, maxY))
|
|
|
+ endOutLength = endOutSlice.Length;
|
|
|
+
|
|
|
+ if (startOutLength < endOutLength)
|
|
|
+ trail.Slices.Reverse();
|
|
|
+
|
|
|
+ return trail;
|
|
|
+ }
|
|
|
+
|
|
|
private void drawDetectedFinger(Finger finger)
|
|
|
{
|
|
|
FingerSliceTrail trail = finger.SliceTrail;
|