|
@@ -30,7 +30,6 @@ namespace bbiwarg.Detectors.Palm
|
|
|
|
|
|
private Contour<Point> palmContour;
|
|
|
private List<MCvConvexityDefect> convexityDefects;
|
|
|
- private LineSegment2DF wristLine, thumbLine;
|
|
|
private Quadrangle palmQuad;
|
|
|
|
|
|
private bool valid = false;
|
|
@@ -48,7 +47,7 @@ namespace bbiwarg.Detectors.Palm
|
|
|
this.palmImage = palmImage;
|
|
|
|
|
|
handImage = depthImage.getImage().Convert<Byte>(delegate(short s) { return (s == depthImage.getMaxDepth()) ? (byte)0 : (byte)1; });
|
|
|
-
|
|
|
+
|
|
|
fingers = getFingersWithoutThumb(detectedFingers);
|
|
|
buildPointingHandMask();
|
|
|
handImage = handImage.And(pointingHandMask);
|
|
@@ -63,9 +62,6 @@ namespace bbiwarg.Detectors.Palm
|
|
|
|
|
|
if (valid)
|
|
|
{
|
|
|
- removePointsFromContour(wristLine, 1);
|
|
|
- removePointsFromContour(thumbLine, 1);
|
|
|
-
|
|
|
draw();
|
|
|
}
|
|
|
}
|
|
@@ -133,7 +129,7 @@ namespace bbiwarg.Detectors.Palm
|
|
|
return new Point(0, 0);
|
|
|
Vector2D direction = (finger.Hand - finger.Tip).normalize();
|
|
|
Vector2D pos = finger.Hand + 20 * direction;
|
|
|
- return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, (int) pos.X), HelperFunctions.thresholdRange<int>(0, height - 1, (int) pos.Y));
|
|
|
+ return new Point(HelperFunctions.thresholdRange<int>(0, width - 1, (int)pos.X), HelperFunctions.thresholdRange<int>(0, height - 1, (int)pos.Y));
|
|
|
}
|
|
|
|
|
|
private void buildPointingHandMask()
|
|
@@ -200,56 +196,52 @@ namespace bbiwarg.Detectors.Palm
|
|
|
convexityDefects = newDefects;
|
|
|
}
|
|
|
|
|
|
- private void findHandPoints() {
|
|
|
+ private void findHandPoints()
|
|
|
+ {
|
|
|
if (convexityDefects.Count > 0)
|
|
|
{
|
|
|
MCvConvexityDefect thumbDefect = convexityDefects[0];
|
|
|
Vector2D thumb = new Vector2D(thumbDefect.DepthPoint);
|
|
|
Vector2D thumbDefectStart = new Vector2D(thumbDefect.StartPoint);
|
|
|
+ Vector2D thumbDefectEnd = new Vector2D(thumbDefect.EndPoint);
|
|
|
|
|
|
- Vector2D handLength = thumbDefectStart - thumb;
|
|
|
- Vector2D handWidth = 0.8f * new Vector2D(handLength.Y, -handLength.X);
|
|
|
-
|
|
|
- topLeft = thumbDefectStart;
|
|
|
- bottomLeft = thumb - 0.3f * handLength;
|
|
|
- bottomRight = bottomLeft + handWidth;
|
|
|
- topRight = bottomRight + 1.5f * handLength;
|
|
|
-
|
|
|
- wristLine = new LineSegment2DF(bottomLeft - 1000 * handWidth, bottomRight + 1000 * handWidth);
|
|
|
- thumbLine = new LineSegment2DF(topLeft + 1000 * handLength, bottomLeft - 1000 * handLength);
|
|
|
+ Vector2D handLength, handWidth;
|
|
|
+ if (thumb.getDistanceTo(thumbDefectStart) > thumb.getDistanceTo(thumbDefectEnd))
|
|
|
+ {
|
|
|
+ //right hand
|
|
|
+ handLength = thumbDefectStart - thumb;
|
|
|
+ handWidth = 0.8f * new Vector2D(-handLength.Y, handLength.X);
|
|
|
+ topLeft = thumbDefectStart;
|
|
|
+ bottomLeft = thumb - 0.4f * handLength;
|
|
|
+ bottomRight = bottomLeft + handWidth;
|
|
|
+ topRight = bottomRight + 1.2f * handLength - 0.3f * handWidth;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //left hand
|
|
|
+ handLength = thumbDefectEnd - thumb;
|
|
|
+ handWidth = 0.8f * new Vector2D(handLength.Y, -handLength.X);
|
|
|
+ topRight = thumbDefectEnd;
|
|
|
+ bottomRight = thumb - 0.4f * handLength;
|
|
|
+ bottomLeft = bottomRight + handWidth;
|
|
|
+ topLeft = bottomLeft + 1.2f * handLength - 0.3f * handWidth;
|
|
|
+ }
|
|
|
|
|
|
- palmQuad = new Quadrangle(new Vector2D[] {bottomLeft, topLeft, topRight, bottomRight});
|
|
|
+ palmQuad = new Quadrangle(new Vector2D[] { bottomLeft, topLeft, topRight, bottomRight });
|
|
|
|
|
|
valid = true;
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
palmQuad = null;
|
|
|
valid = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void removePointsFromContour(LineSegment2DF line, int sideToRemove)
|
|
|
- {
|
|
|
- Contour<Point> newContour = new Contour<Point>(new MemStorage());
|
|
|
- int index = 0;
|
|
|
- foreach (Point p in palmContour)
|
|
|
- {
|
|
|
- if (line.Side(p) != sideToRemove)
|
|
|
- {
|
|
|
- newContour.Insert(index, p);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- }
|
|
|
- palmContour = newContour;
|
|
|
- }
|
|
|
-
|
|
|
private void draw()
|
|
|
{
|
|
|
palmImage.drawContour(palmContour);
|
|
|
|
|
|
- palmImage.drawLine(wristLine, PalmImageState.wristLine);
|
|
|
- palmImage.drawLine(thumbLine, PalmImageState.thumbLine);
|
|
|
-
|
|
|
if (palmQuad != null)
|
|
|
{
|
|
|
Vector2D[] vertices = palmQuad.Vertices;
|