|
@@ -34,6 +34,12 @@ namespace bbiwarg.Detectors.Palm
|
|
private LineSegment2DF wristLine, thumbLine;
|
|
private LineSegment2DF wristLine, thumbLine;
|
|
private Quad2D palmRect;
|
|
private Quad2D palmRect;
|
|
|
|
|
|
|
|
+ private bool valid = false;
|
|
|
|
+ private Vector2D topLeft;
|
|
|
|
+ private Vector2D topRight;
|
|
|
|
+ private Vector2D bottomLeft;
|
|
|
|
+ private Vector2D bottomRight;
|
|
|
|
+
|
|
public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, FingerDetector fingerDetector, PalmImage palmImage)
|
|
public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, FingerDetector fingerDetector, PalmImage palmImage)
|
|
{
|
|
{
|
|
width = depthImage.getWidth();
|
|
width = depthImage.getWidth();
|
|
@@ -54,15 +60,12 @@ namespace bbiwarg.Detectors.Palm
|
|
findConvexityDefactsSortedByDepth();
|
|
findConvexityDefactsSortedByDepth();
|
|
removeConvexityDefectsNearFingerTips();
|
|
removeConvexityDefectsNearFingerTips();
|
|
|
|
|
|
- findThumbLine();
|
|
|
|
- findWristLine();
|
|
|
|
-
|
|
|
|
- removePointsFromContour(wristLine, 1);
|
|
|
|
- removePointsFromContour(thumbLine, 1);
|
|
|
|
|
|
+ findHandPoints();
|
|
|
|
|
|
- if (palmContour.Count<Point>() != 0)
|
|
|
|
|
|
+ if (valid)
|
|
{
|
|
{
|
|
- findPalmRect();
|
|
|
|
|
|
+ removePointsFromContour(wristLine, 1);
|
|
|
|
+ removePointsFromContour(thumbLine, 1);
|
|
|
|
|
|
draw();
|
|
draw();
|
|
}
|
|
}
|
|
@@ -168,21 +171,6 @@ namespace bbiwarg.Detectors.Palm
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void findWristDirection()
|
|
|
|
- {
|
|
|
|
- PointF[] points = new PointF[palmContour.Count<Point>()];
|
|
|
|
- int index = 0;
|
|
|
|
- foreach (Point p in palmContour)
|
|
|
|
- {
|
|
|
|
- points[index] = new PointF(p.X, p.Y);
|
|
|
|
- ++index;
|
|
|
|
- }
|
|
|
|
- PointF direction, tmp;
|
|
|
|
- PointCollection.Line2DFitting(points, Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_L2, out direction, out tmp);
|
|
|
|
- //Vector2D direction = new Vector2D(thumbLine.Direction);
|
|
|
|
- wristDirection = new Vector2D(-direction.Y, direction.X);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void findConvexityDefactsSortedByDepth()
|
|
private void findConvexityDefactsSortedByDepth()
|
|
{
|
|
{
|
|
convexityDefects = new List<MCvConvexityDefect>(palmContour.GetConvexityDefacts(new MemStorage(), Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE));
|
|
convexityDefects = new List<MCvConvexityDefect>(palmContour.GetConvexityDefacts(new MemStorage(), Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE));
|
|
@@ -214,34 +202,31 @@ namespace bbiwarg.Detectors.Palm
|
|
convexityDefects = newDefects;
|
|
convexityDefects = newDefects;
|
|
}
|
|
}
|
|
|
|
|
|
- private void findWristPoint()
|
|
|
|
- {
|
|
|
|
- if (convexityDefects.Count > 1)
|
|
|
|
- wristPoint = new Vector2D(convexityDefects[1].DepthPoint);
|
|
|
|
- else
|
|
|
|
- wristPoint = new Vector2D(-1, -1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void findWristLine()
|
|
|
|
- {
|
|
|
|
- findWristPoint();
|
|
|
|
- findWristDirection();
|
|
|
|
- wristLine = new LineSegment2DF(wristPoint - 1000 * wristDirection, wristPoint + 1000 * wristDirection);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void findThumbLine()
|
|
|
|
- {
|
|
|
|
|
|
+ private void findHandPoints() {
|
|
if (convexityDefects.Count > 0)
|
|
if (convexityDefects.Count > 0)
|
|
{
|
|
{
|
|
MCvConvexityDefect thumbDefect = convexityDefects[0];
|
|
MCvConvexityDefect thumbDefect = convexityDefects[0];
|
|
- Vector2D p1 = new Vector2D(thumbDefect.DepthPoint);
|
|
|
|
- Vector2D p2 = new Vector2D(thumbDefect.StartPoint);
|
|
|
|
- Vector2D direction = (p1 - p2).normalize();
|
|
|
|
- thumbLine = new LineSegment2DF(p1 - 1000 * direction, p1 + 1000 * direction);
|
|
|
|
|
|
+ Vector2D thumb = new Vector2D(thumbDefect.DepthPoint);
|
|
|
|
+ Vector2D thumbDefectStart = new Vector2D(thumbDefect.StartPoint);
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ palmRect = new Quad2D(bottomLeft, topLeft, topRight, bottomRight);
|
|
|
|
+
|
|
|
|
+ valid = true;
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- thumbLine = new LineSegment2DF(new PointF(-1, -1), new PointF(-1, -1));
|
|
|
|
|
|
+ else {
|
|
|
|
+ palmRect = null;
|
|
|
|
+ valid = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -260,49 +245,6 @@ namespace bbiwarg.Detectors.Palm
|
|
palmContour = newContour;
|
|
palmContour = newContour;
|
|
}
|
|
}
|
|
|
|
|
|
- private void findPalmRect()
|
|
|
|
- {
|
|
|
|
- //palmRect = palmContour.GetMinAreaRect();
|
|
|
|
-
|
|
|
|
- Line2D thumbLine2 = new Line2D(new Vector2D(thumbLine.P1), new Vector2D(thumbLine.P2));
|
|
|
|
- Line2D wristLine2 = new Line2D(new Vector2D(wristLine.P1), new Vector2D(wristLine.P2));
|
|
|
|
-
|
|
|
|
- Vector2D intersection = thumbLine2.intersection(wristLine2);
|
|
|
|
- if (intersection != null)
|
|
|
|
- {
|
|
|
|
- Vector2D maxThumb = new Vector2D(0, 0), maxWrist = new Vector2D(0, 0);
|
|
|
|
- float maxDistanceThumb = 0, maxDistanceWrist = 0;
|
|
|
|
- foreach (Point p in palmContour)
|
|
|
|
- {
|
|
|
|
- Vector2D v = new Vector2D(p);
|
|
|
|
- Vector2D projected = thumbLine2.projectToLine(v);
|
|
|
|
-
|
|
|
|
- float dist = projected.getDistanceTo(intersection);
|
|
|
|
- if (dist > maxDistanceThumb)
|
|
|
|
- {
|
|
|
|
- maxDistanceThumb = dist;
|
|
|
|
- maxThumb = projected;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- projected = wristLine2.projectToLine(v);
|
|
|
|
-
|
|
|
|
- dist = projected.getDistanceTo(intersection);
|
|
|
|
- if (dist > maxDistanceWrist)
|
|
|
|
- {
|
|
|
|
- maxDistanceWrist = dist;
|
|
|
|
- maxWrist = projected;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Vector2D origin = intersection;
|
|
|
|
- palmRect = new Quad2D(origin, (maxThumb - origin), (maxWrist - origin));
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- palmRect = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void draw()
|
|
private void draw()
|
|
{
|
|
{
|
|
palmImage.drawContour(palmContour);
|
|
palmImage.drawContour(palmContour);
|