|
@@ -49,7 +49,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
Vector2D edgeDirection = getEdgeDirection(edgePoint);
|
|
Vector2D edgeDirection = getEdgeDirection(edgePoint);
|
|
if (edgeDirection != null)
|
|
if (edgeDirection != null)
|
|
{
|
|
{
|
|
- Vector2D dir = edgeDirection.getOrthogonal(true);
|
|
|
|
|
|
+ Vector2D dir = edgeDirection.getOrthogonal();
|
|
if (depthImage.getDepthAt(edgePoint - dir) < depthImage.getDepthAt(edgePoint + dir))
|
|
if (depthImage.getDepthAt(edgePoint - dir) < depthImage.getDepthAt(edgePoint + dir))
|
|
dir = dir.getInverse();
|
|
dir = dir.getInverse();
|
|
|
|
|
|
@@ -99,7 +99,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
{
|
|
{
|
|
trail.removeFirstSlices(Constants.FingerRemoveNumSlicesForCorrection);
|
|
trail.removeFirstSlices(Constants.FingerRemoveNumSlicesForCorrection);
|
|
trail.reverse();
|
|
trail.reverse();
|
|
- trail = expandTrail(trail, true);
|
|
|
|
|
|
+ trail = expandTrail(trail);
|
|
trail.reverse();
|
|
trail.reverse();
|
|
return trail;
|
|
return trail;
|
|
}
|
|
}
|
|
@@ -110,7 +110,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private FingerSliceTrail expandTrail(FingerSliceTrail trail, bool reversed = false)
|
|
|
|
|
|
+ private FingerSliceTrail expandTrail(FingerSliceTrail trail)
|
|
{
|
|
{
|
|
Vector2D currentDirection = trail.getEndDirection();
|
|
Vector2D currentDirection = trail.getEndDirection();
|
|
Vector2D currentPosition = trail.EndSlice.Mid + Constants.FingerStepSize * currentDirection;
|
|
Vector2D currentPosition = trail.EndSlice.Mid + Constants.FingerStepSize * currentDirection;
|
|
@@ -123,10 +123,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
while (currentPosition.isInBound(Vector2D.Zero, depthImage.BottomRight) && 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());
|
|
|
|
- else
|
|
|
|
- nextSlice = findFingerSliceFromMid(currentPosition, currentDirection);
|
|
|
|
|
|
+ nextSlice = findFingerSliceFromMid(currentPosition, currentDirection);
|
|
|
|
|
|
if (nextSlice != null && Math.Abs(nextSlice.Length - lastSlice.Length) <= Constants.FingerMaxSliceDifferencePerStep)
|
|
if (nextSlice != null && Math.Abs(nextSlice.Length - lastSlice.Length) <= Constants.FingerMaxSliceDifferencePerStep)
|
|
{
|
|
{
|
|
@@ -155,66 +152,23 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
Vector2D dirStart = direction.getOrthogonal(true);
|
|
Vector2D dirStart = direction.getOrthogonal(true);
|
|
Vector2D dirEnd = direction.getOrthogonal(false);
|
|
Vector2D dirEnd = direction.getOrthogonal(false);
|
|
|
|
|
|
- Vector2D start = findNextEdge(position, dirStart);
|
|
|
|
|
|
+ Vector2D start = edgeImageAdapted.findNextEdge(position, dirStart, Constants.FingerMaxSize);
|
|
if (start == null) return null;
|
|
if (start == null) return null;
|
|
|
|
|
|
- Vector2D end = findNextEdge(position, dirEnd);
|
|
|
|
|
|
+ Vector2D end = edgeImageAdapted.findNextEdge(position, dirEnd, Constants.FingerMaxSize);
|
|
if (end == null) return null;
|
|
if (end == null) return null;
|
|
|
|
|
|
return getFingerSlice(start, end);
|
|
return getFingerSlice(start, end);
|
|
}
|
|
}
|
|
private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
|
|
private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
|
|
{
|
|
{
|
|
- Vector2D end = findNextEdge(start + Constants.FingerSliceOverlapFactor * direction, direction);
|
|
|
|
|
|
+ Vector2D searchStart = start + Constants.FingerSliceOverlapFactor * direction;
|
|
|
|
+ Vector2D end = edgeImageAdapted.findNextEdge(searchStart, direction, Constants.FingerMaxSize);
|
|
if (end == null) return null;
|
|
if (end == null) return null;
|
|
|
|
|
|
return getFingerSlice(start, end);
|
|
return getFingerSlice(start, end);
|
|
}
|
|
}
|
|
|
|
|
|
- private Vector2D findNextEdge(Vector2D start, Vector2D direction, bool adaptedEdgeImage = true, bool stopAtMaxFingerSize = true, bool returnBoundIfNoEdge = false)
|
|
|
|
- {
|
|
|
|
- Vector2D max = depthImage.BottomRight;
|
|
|
|
- Vector2D maxGrow = (max - start) / direction;
|
|
|
|
- Vector2D maxDecline = start / direction.getAbsolute();
|
|
|
|
-
|
|
|
|
- int maxStepsX;
|
|
|
|
- if (direction.X > 0)
|
|
|
|
- maxStepsX = maxGrow.IntX;
|
|
|
|
- else if (direction.X < 0)
|
|
|
|
- maxStepsX = maxDecline.IntX;
|
|
|
|
- else
|
|
|
|
- maxStepsX = int.MaxValue;
|
|
|
|
-
|
|
|
|
- int maxStepsY;
|
|
|
|
- if (direction.Y > 0)
|
|
|
|
- maxStepsY = maxGrow.IntY;
|
|
|
|
- else if (direction.Y < 0)
|
|
|
|
- maxStepsY = maxDecline.IntY;
|
|
|
|
- else
|
|
|
|
- maxStepsY = int.MaxValue;
|
|
|
|
-
|
|
|
|
- int maxSteps = 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++)
|
|
|
|
- {
|
|
|
|
- end += direction;
|
|
|
|
-
|
|
|
|
- if ((adaptedEdgeImage && edgeImageAdapted.isRoughEdgeAt(end)) || (!adaptedEdgeImage && edgeImageOriginal.isRoughEdgeAt(end)))
|
|
|
|
- {
|
|
|
|
- return end;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (returnBoundIfNoEdge)
|
|
|
|
- return end;
|
|
|
|
- else
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private FingerSlice getFingerSlice(Vector2D start, Vector2D end)
|
|
private FingerSlice getFingerSlice(Vector2D start, Vector2D end)
|
|
{
|
|
{
|
|
int maxX = depthImage.Width - 1;
|
|
int maxX = depthImage.Width - 1;
|
|
@@ -284,8 +238,8 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
|
|
|
|
Vector2D outPoint = (start + Constants.FingerOutSliceFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction.getInverse());
|
|
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);
|
|
|
|
|
|
+ Vector2D p1 = edgeImageOriginal.findNextEdge(outPoint, dirOrth1, 0, true, false);
|
|
|
|
+ Vector2D p2 = edgeImageOriginal.findNextEdge(outPoint, dirOrth2, 0, true, false);
|
|
|
|
|
|
FingerSlice slice = new FingerSlice(p1, p2);
|
|
FingerSlice slice = new FingerSlice(p1, p2);
|
|
|
|
|