|
@@ -16,14 +16,16 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
class FingerDetector
|
|
class FingerDetector
|
|
{
|
|
{
|
|
private DepthImage depthImage;
|
|
private DepthImage depthImage;
|
|
- private EdgeImage edgeImage;
|
|
|
|
|
|
+ private EdgeImage edgeImageOriginal;
|
|
|
|
+ private EdgeImage edgeImageAdapted;
|
|
private OutputImage outputImage;
|
|
private OutputImage outputImage;
|
|
public List<Finger> Fingers { get; private set; }
|
|
public List<Finger> Fingers { get; private set; }
|
|
|
|
|
|
public FingerDetector(DepthImage depthImage, EdgeImage edgeImage, OutputImage outputImage)
|
|
public FingerDetector(DepthImage depthImage, EdgeImage edgeImage, OutputImage outputImage)
|
|
{
|
|
{
|
|
this.depthImage = depthImage;
|
|
this.depthImage = depthImage;
|
|
- this.edgeImage = edgeImage.copy();
|
|
|
|
|
|
+ this.edgeImageOriginal = edgeImage;
|
|
|
|
+ this.edgeImageAdapted = edgeImage.copy();
|
|
this.outputImage = outputImage;
|
|
this.outputImage = outputImage;
|
|
|
|
|
|
findFingers();
|
|
findFingers();
|
|
@@ -40,7 +42,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
{
|
|
{
|
|
for (int x = 1; x < maxX; x++)
|
|
for (int x = 1; x < maxX; x++)
|
|
{
|
|
{
|
|
- if (edgeImage.isEdgeAt(x, y))
|
|
|
|
|
|
+ if (edgeImageAdapted.isEdgeAt(x, y))
|
|
{
|
|
{
|
|
Vector2D edgePoint = new Vector2D(x, y);
|
|
Vector2D edgePoint = new Vector2D(x, y);
|
|
Vector2D edgeDirection = getEdgeDirection(edgePoint);
|
|
Vector2D edgeDirection = getEdgeDirection(edgePoint);
|
|
@@ -68,10 +70,10 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
int x = edgePoint.IntX;
|
|
int x = edgePoint.IntX;
|
|
int y = edgePoint.IntY;
|
|
int y = edgePoint.IntY;
|
|
|
|
|
|
- if (edgeImage.isEdgeAt(x, y - 1) && edgeImage.isEdgeAt(x, y + 1)) return new Vector2D(0, 1);
|
|
|
|
- else if (edgeImage.isEdgeAt(x - 1, y) && edgeImage.isEdgeAt(x + 1, y)) return new Vector2D(1, 0);
|
|
|
|
- else if (edgeImage.isEdgeAt(x - 1, y - 1) && edgeImage.isEdgeAt(x + 1, y + 1)) return new Vector2D(1, 1).normalize();
|
|
|
|
- else if (edgeImage.isEdgeAt(x + 1, y - 1) && edgeImage.isEdgeAt(x - 1, y + 1)) return new Vector2D(1, -1).normalize();
|
|
|
|
|
|
+ if (edgeImageAdapted.isEdgeAt(x, y - 1) && edgeImageAdapted.isEdgeAt(x, y + 1)) return new Vector2D(0, 1);
|
|
|
|
+ else if (edgeImageAdapted.isEdgeAt(x - 1, y) && edgeImageAdapted.isEdgeAt(x + 1, y)) return new Vector2D(1, 0);
|
|
|
|
+ else if (edgeImageAdapted.isEdgeAt(x - 1, y - 1) && edgeImageAdapted.isEdgeAt(x + 1, y + 1)) return new Vector2D(1, 1).normalize();
|
|
|
|
+ else if (edgeImageAdapted.isEdgeAt(x + 1, y - 1) && edgeImageAdapted.isEdgeAt(x - 1, y + 1)) return new Vector2D(1, -1).normalize();
|
|
else return null;
|
|
else return null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -148,7 +150,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
|
|
|
|
private FingerSlice findFingerSliceFromMid(Vector2D position, Vector2D direction)
|
|
private FingerSlice findFingerSliceFromMid(Vector2D position, Vector2D direction)
|
|
{
|
|
{
|
|
- if (edgeImage.isEdgeAt(position)) return null;
|
|
|
|
|
|
+ if (edgeImageAdapted.isRoughEdgeAt(position)) return null;
|
|
|
|
|
|
Vector2D dirStart = direction.getOrthogonal(true);
|
|
Vector2D dirStart = direction.getOrthogonal(true);
|
|
Vector2D dirEnd = direction.getOrthogonal(false);
|
|
Vector2D dirEnd = direction.getOrthogonal(false);
|
|
@@ -163,13 +165,13 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
}
|
|
}
|
|
private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
|
|
private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
|
|
{
|
|
{
|
|
- Vector2D end = findNextEdge(start, direction);
|
|
|
|
|
|
+ Vector2D end = findNextEdge(start+3*direction, direction);
|
|
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 stopAtMaxFingerSize = true, bool returnBoundIfNoEdge = false)
|
|
|
|
|
|
+ private Vector2D findNextEdge(Vector2D start, Vector2D direction, bool adaptedEdgeImage = true, bool stopAtMaxFingerSize = true, bool returnBoundIfNoEdge = false)
|
|
{
|
|
{
|
|
int maxX = depthImage.Width - 1;
|
|
int maxX = depthImage.Width - 1;
|
|
int maxY = depthImage.Height - 1;
|
|
int maxY = depthImage.Height - 1;
|
|
@@ -200,7 +202,7 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
{
|
|
{
|
|
end += direction;
|
|
end += direction;
|
|
|
|
|
|
- if (edgeImage.isEdgeAt(end))
|
|
|
|
|
|
+ if ((adaptedEdgeImage && edgeImageAdapted.isRoughEdgeAt(end)) || (!adaptedEdgeImage && edgeImageOriginal.isRoughEdgeAt(end)))
|
|
{
|
|
{
|
|
return end;
|
|
return end;
|
|
}
|
|
}
|
|
@@ -251,7 +253,8 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
drawDetectedFinger(finger);
|
|
drawDetectedFinger(finger);
|
|
|
|
|
|
//remove edges around detected finger to improve performance
|
|
//remove edges around detected finger to improve performance
|
|
- edgeImage.removeFingerEdges(finger);
|
|
|
|
|
|
+ Point[] polygon = finger.getBoundingPolygon();
|
|
|
|
+ edgeImageAdapted.removeEdgesInsidePolygon(polygon);
|
|
}
|
|
}
|
|
|
|
|
|
private FingerSlice findOutSlice(Vector2D start, Vector2D direction)
|
|
private FingerSlice findOutSlice(Vector2D start, Vector2D direction)
|
|
@@ -263,8 +266,8 @@ namespace bbiwarg.Detectors.FingerDetection
|
|
Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
Vector2D dirOrth2 = direction.getOrthogonal(false);
|
|
|
|
|
|
Vector2D outPoint = (start + Constants.FingerOutSliceFactor * Constants.FingerStepSize * direction).moveInBound(0, 0, maxX, maxY);
|
|
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);
|
|
|
|
|
|
+ Vector2D p1 = findNextEdge(outPoint, dirOrth1, false, false, true);
|
|
|
|
+ Vector2D p2 = findNextEdge(outPoint, dirOrth2, false, false, true);
|
|
|
|
|
|
FingerSlice slice = new FingerSlice(p1, p2);
|
|
FingerSlice slice = new FingerSlice(p1, p2);
|
|
|
|
|