|
@@ -31,11 +31,8 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
|
|
|
private void findFingers()
|
|
|
{
|
|
|
- int minNumSlices = 7;
|
|
|
- int width = depthImage.Width;
|
|
|
- int height = depthImage.Height;
|
|
|
- int maxX = width - 1;
|
|
|
- int maxY = height - 1;
|
|
|
+ int maxX = depthImage.Width - 1;
|
|
|
+ int maxY = depthImage.Height - 1;
|
|
|
|
|
|
Fingers = new List<Finger>();
|
|
|
|
|
@@ -57,7 +54,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
if (slice != null)
|
|
|
{
|
|
|
FingerSliceTrail trail = findFingerSliceTrail(slice, edgeDirection);
|
|
|
- if (trail != null && trail.NumSlices > minNumSlices)
|
|
|
+ if (trail != null && trail.NumSlices > Constants.FingerMinNumSlices)
|
|
|
createFingerFromTrail(trail);
|
|
|
}
|
|
|
}
|
|
@@ -80,16 +77,13 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
|
|
|
private FingerSliceTrail findFingerSliceTrail(FingerSlice startSlice, Vector2D startDirection)
|
|
|
{
|
|
|
- int minNumSlicesForCorrection = 7;
|
|
|
- int numRemoveForCorrection = 3;
|
|
|
-
|
|
|
int maxX = depthImage.Width - 1;
|
|
|
int maxY = depthImage.Height - 1;
|
|
|
|
|
|
FingerSliceTrail trail = new FingerSliceTrail(startSlice);
|
|
|
|
|
|
Vector2D direction = startDirection;
|
|
|
- Vector2D position = startSlice.Mid + 2*direction;
|
|
|
+ Vector2D position = startSlice.Mid + Constants.FingerStepSize * direction;
|
|
|
|
|
|
if (position.isWithin(0, 0, maxX, maxY))
|
|
|
{
|
|
@@ -99,9 +93,9 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
trail.addSlice(nextSlice);
|
|
|
trail = expandTrail(trail);
|
|
|
|
|
|
- if (trail.NumSlices > minNumSlicesForCorrection)
|
|
|
+ if (trail.NumSlices > Constants.FingerMinNumSlices)
|
|
|
{
|
|
|
- trail.Slices.RemoveRange(0, numRemoveForCorrection);
|
|
|
+ trail.Slices.RemoveRange(0, Constants.FingerRemoveNumSlicesForCorrection);
|
|
|
trail.Slices.Reverse();
|
|
|
trail = expandTrail(trail);
|
|
|
trail.Slices.Reverse();
|
|
@@ -120,7 +114,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
int maxY = depthImage.Height - 1;
|
|
|
|
|
|
Vector2D currentDirection = trail.getEndDirection();
|
|
|
- Vector2D currentPosition = trail.End.Mid + 2*currentDirection;
|
|
|
+ Vector2D currentPosition = trail.End.Mid + Constants.FingerStepSize * currentDirection;
|
|
|
|
|
|
int gapCounter = 0;
|
|
|
int numSlices = trail.NumSlices;
|
|
@@ -128,16 +122,17 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
FingerSlice lastSlice = trail.End;
|
|
|
FingerSlice nextSlice;
|
|
|
|
|
|
- while (currentPosition.isWithin(0, 0, maxX, maxY) && gapCounter <= Math.Min(numSlices, 10))
|
|
|
+ while (currentPosition.isWithin(0, 0, maxX, maxY) && gapCounter <= Math.Min(numSlices, Constants.FingerMaxGapCounter))
|
|
|
{
|
|
|
nextSlice = findFingerSliceFromMid(currentPosition, currentDirection);
|
|
|
- if (nextSlice != null && (nextSlice.Length < lastSlice.Length + 8 && nextSlice.Length > lastSlice.Length - 8))
|
|
|
+
|
|
|
+ if (nextSlice != null && Math.Abs(nextSlice.Length - lastSlice.Length) <= Constants.FingerMaxSliceDifferencePerStep)
|
|
|
{
|
|
|
gapCounter = 0;
|
|
|
numSlices++;
|
|
|
trail.addSlice(nextSlice);
|
|
|
currentDirection = trail.getEndDirection();
|
|
|
- currentPosition = nextSlice.Mid + 2*currentDirection;
|
|
|
+ currentPosition = nextSlice.Mid + Constants.FingerStepSize * currentDirection;
|
|
|
|
|
|
lastSlice = nextSlice;
|
|
|
}
|
|
@@ -168,7 +163,6 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
}
|
|
|
private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
|
|
|
{
|
|
|
-
|
|
|
Vector2D end = findNextEdge(start, direction);
|
|
|
if (end == null) return null;
|
|
|
|
|
@@ -180,8 +174,6 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
int maxX = depthImage.Width - 1;
|
|
|
int maxY = depthImage.Height - 1;
|
|
|
|
|
|
- int maxFingerSize = 35;
|
|
|
-
|
|
|
int maxStepsX;
|
|
|
if (direction.X > 0)
|
|
|
maxStepsX = (int)((maxX - start.X) / direction.X);
|
|
@@ -198,7 +190,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
else
|
|
|
maxStepsY = int.MaxValue;
|
|
|
|
|
|
- int maxStepsLength = (int)(maxFingerSize / direction.Length);
|
|
|
+ int maxStepsLength = (int)(Constants.FingerMaxSize / direction.Length);
|
|
|
|
|
|
int maxSteps = Math.Min(maxStepsLength, Math.Min(maxStepsX, maxStepsY));
|
|
|
|
|
@@ -220,18 +212,12 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
int maxX = depthImage.Width - 1;
|
|
|
int maxY = depthImage.Height - 1;
|
|
|
|
|
|
- int minFingerSize = 5;
|
|
|
- int maxFingerSize = 35;
|
|
|
-
|
|
|
Vector2D direction = (end - start).normalize();
|
|
|
- Vector2D beforeStart = start - direction;
|
|
|
- Vector2D behindEnd = end + direction;
|
|
|
+ Vector2D beforeStart = (start - direction).moveInBound(0, 0, maxX, maxY);
|
|
|
+ Vector2D behindEnd = (end + direction).moveInBound(0, 0, maxY, maxY);
|
|
|
|
|
|
- start = beforeStart.isWithin(0, 0, maxX, maxY) ? beforeStart : start;
|
|
|
- end = behindEnd.isWithin(0, 0, maxX, maxY) ? behindEnd : end;
|
|
|
-
|
|
|
- FingerSlice slice = new FingerSlice(start, end);
|
|
|
- if (slice.Length >= minFingerSize && slice.Length <= maxFingerSize && fingerSliceDepthTest(slice))
|
|
|
+ FingerSlice slice = new FingerSlice(beforeStart, behindEnd);
|
|
|
+ if (slice.Length >= Constants.FingerMinSize && slice.Length <= Constants.FingerMaxSize && fingerSliceDepthTest(slice))
|
|
|
return slice;
|
|
|
|
|
|
return null;
|
|
@@ -254,7 +240,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
|
|
|
|
//draw finger
|
|
|
drawDetectedFinger(finger);
|
|
|
-
|
|
|
+
|
|
|
//remove edges around detected finger to improve performance
|
|
|
edgeImage.removeFingerEdges(finger);
|
|
|
}
|