|
@@ -32,7 +32,7 @@ namespace bbiwarg.Detectors.Palm
|
|
private List<MCvConvexityDefect> convexityDefects;
|
|
private List<MCvConvexityDefect> convexityDefects;
|
|
private Vector2D wristPoint, wristDirection;
|
|
private Vector2D wristPoint, wristDirection;
|
|
private LineSegment2DF wristLine, thumbLine;
|
|
private LineSegment2DF wristLine, thumbLine;
|
|
- private MCvBox2D palmRect;
|
|
|
|
|
|
+ private Quad2D palmRect;
|
|
|
|
|
|
public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, FingerDetector fingerDetector, PalmImage palmImage)
|
|
public PalmDetector(DepthImage depthImage, EdgeImage edgeImage, FingerDetector fingerDetector, PalmImage palmImage)
|
|
{
|
|
{
|
|
@@ -54,9 +54,9 @@ namespace bbiwarg.Detectors.Palm
|
|
findConvexityDefactsSortedByDepth();
|
|
findConvexityDefactsSortedByDepth();
|
|
removeConvexityDefectsNearFingerTips();
|
|
removeConvexityDefectsNearFingerTips();
|
|
|
|
|
|
- findWristLine();
|
|
|
|
findThumbLine();
|
|
findThumbLine();
|
|
-
|
|
|
|
|
|
+ findWristLine();
|
|
|
|
+
|
|
removePointsFromContour(wristLine, 1);
|
|
removePointsFromContour(wristLine, 1);
|
|
removePointsFromContour(thumbLine, 1);
|
|
removePointsFromContour(thumbLine, 1);
|
|
|
|
|
|
@@ -179,6 +179,7 @@ namespace bbiwarg.Detectors.Palm
|
|
}
|
|
}
|
|
PointF direction, tmp;
|
|
PointF direction, tmp;
|
|
PointCollection.Line2DFitting(points, Emgu.CV.CvEnum.DIST_TYPE.CV_DIST_L2, out direction, out 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);
|
|
wristDirection = new Vector2D(-direction.Y, direction.X);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -261,7 +262,45 @@ namespace bbiwarg.Detectors.Palm
|
|
|
|
|
|
private void findPalmRect()
|
|
private void findPalmRect()
|
|
{
|
|
{
|
|
- palmRect = palmContour.GetMinAreaRect();
|
|
|
|
|
|
+ //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()
|
|
@@ -271,11 +310,15 @@ namespace bbiwarg.Detectors.Palm
|
|
palmImage.drawLine(wristLine, PalmImageState.wristLine);
|
|
palmImage.drawLine(wristLine, PalmImageState.wristLine);
|
|
palmImage.drawLine(thumbLine, PalmImageState.thumbLine);
|
|
palmImage.drawLine(thumbLine, PalmImageState.thumbLine);
|
|
|
|
|
|
- PointF[] vertices = palmRect.GetVertices();
|
|
|
|
- for (int i = 0; i < 4; ++i)
|
|
|
|
- palmImage.drawLine(new LineSegment2DF(vertices[i], vertices[(i + 1) % 4]), PalmImageState.palmRect);
|
|
|
|
|
|
+ if (palmRect != null)
|
|
|
|
+ {
|
|
|
|
+ PointF[] vertices = palmRect.getVertices();
|
|
|
|
+ for (int i = 0; i < 4; ++i)
|
|
|
|
+ palmImage.drawLine(new LineSegment2DF(vertices[i], vertices[(i + 1) % 4]), PalmImageState.palmRect);
|
|
|
|
+
|
|
|
|
|
|
- palmImage.drawGrid(new Vector2D(vertices[0]),new Vector2D(vertices[1]),new Vector2D(vertices[2]),new Vector2D(vertices[3]));
|
|
|
|
|
|
+ palmImage.drawGrid(new Vector2D(vertices[0]), new Vector2D(vertices[1]), new Vector2D(vertices[2]), new Vector2D(vertices[3]));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|