|
@@ -28,7 +28,7 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
private Vector2D thumbDefectDepth;
|
|
private Vector2D thumbDefectDepth;
|
|
private Kalman2DPositionFilter thumbDefectDepthFilter, thumbDefectStartFilter, thumbDefectEndFilter;
|
|
private Kalman2DPositionFilter thumbDefectDepthFilter, thumbDefectStartFilter, thumbDefectEndFilter;
|
|
private int numFramesNoHandFound;
|
|
private int numFramesNoHandFound;
|
|
- private float lastPalmQuadArea;
|
|
|
|
|
|
+ private Quadrangle lastPalmQuad;
|
|
private List<Hand> hands;
|
|
private List<Hand> hands;
|
|
|
|
|
|
public Quadrangle PalmQuad { get; private set; }
|
|
public Quadrangle PalmQuad { get; private set; }
|
|
@@ -44,7 +44,7 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
Constants.PalmThumbDefectmYY, Constants.PalmThumbDefectProcessNoise);
|
|
Constants.PalmThumbDefectmYY, Constants.PalmThumbDefectProcessNoise);
|
|
}
|
|
}
|
|
|
|
|
|
- public void findPalmQuad(OutputImage outputImage, List<Hand> hands)
|
|
|
|
|
|
+ public void findPalmQuad(OutputImage outputImage, List<Hand> hands, Image<Gray, Byte> foregroundMask)
|
|
{
|
|
{
|
|
this.outputImage = outputImage;
|
|
this.outputImage = outputImage;
|
|
this.hands = hands;
|
|
this.hands = hands;
|
|
@@ -84,7 +84,7 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
findConvexityDefectsSortedByDepth();
|
|
findConvexityDefectsSortedByDepth();
|
|
if (pointingHand != null)
|
|
if (pointingHand != null)
|
|
removeConvexityDefectsCausedByFingers();
|
|
removeConvexityDefectsCausedByFingers();
|
|
- findHandPoints();
|
|
|
|
|
|
+ findHandPoints(foregroundMask);
|
|
}
|
|
}
|
|
|
|
|
|
if (hands.Count == 0)
|
|
if (hands.Count == 0)
|
|
@@ -93,6 +93,10 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
if (numFramesNoHandFound == Constants.PalmNumFramesNoHandReset)
|
|
if (numFramesNoHandFound == Constants.PalmNumFramesNoHandReset)
|
|
reset();
|
|
reset();
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ numFramesNoHandFound = 0;
|
|
|
|
+ }
|
|
|
|
|
|
draw();
|
|
draw();
|
|
}
|
|
}
|
|
@@ -106,7 +110,7 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
PalmQuad = null;
|
|
PalmQuad = null;
|
|
PalmHandSide = Hand.HandSide.Left;
|
|
PalmHandSide = Hand.HandSide.Left;
|
|
numFramesNoHandFound = 0;
|
|
numFramesNoHandFound = 0;
|
|
- lastPalmQuadArea = 0.0f;
|
|
|
|
|
|
+ lastPalmQuad = null;
|
|
}
|
|
}
|
|
|
|
|
|
private void findLongestPalmContour()
|
|
private void findLongestPalmContour()
|
|
@@ -199,7 +203,15 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- private void findHandPoints()
|
|
|
|
|
|
+ float getForegroundPixelPercentage(Quadrangle quad, Image<Gray, Byte> foregroundMask)
|
|
|
|
+ {
|
|
|
|
+ float numPixelsInMask = quad.Mask.CountNonzero()[0];
|
|
|
|
+ float numPixelsInMaskInForeground = (quad.Mask & foregroundMask).CountNonzero()[0];
|
|
|
|
+
|
|
|
|
+ return numPixelsInMaskInForeground / numPixelsInMask;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void findHandPoints(Image<Gray, Byte> foregroundMask)
|
|
{
|
|
{
|
|
MCvConvexityDefect? thumbDefect = findThumbDefect();
|
|
MCvConvexityDefect? thumbDefect = findThumbDefect();
|
|
|
|
|
|
@@ -262,15 +274,20 @@ namespace bbiwarg.Recognition.PalmRecognition
|
|
bottomRight = bottomLeft + handWidth;
|
|
bottomRight = bottomLeft + handWidth;
|
|
topRight = bottomRight + 1.2f * handLength - 0.3f * handWidth;
|
|
topRight = bottomRight + 1.2f * handLength - 0.3f * handWidth;
|
|
|
|
|
|
- Quadrangle quad = new Quadrangle(bottomLeft, topLeft, topRight, bottomRight);
|
|
|
|
- if (lastPalmQuadArea == 0.0f ||
|
|
|
|
- (quad.Area / lastPalmQuadArea >= Constants.PalmMinAreaQuotient && quad.Area / lastPalmQuadArea <= Constants.PalmMaxAreaQuotient))
|
|
|
|
|
|
+ Quadrangle quad = new Quadrangle(bottomLeft, topLeft, topRight, bottomRight, foregroundMask.Width, foregroundMask.Height);
|
|
|
|
+
|
|
|
|
+ if ((lastPalmQuad == null ||
|
|
|
|
+ (quad.Area / lastPalmQuad.Area >= Constants.PalmMinAreaQuotient && quad.Area / lastPalmQuad.Area <= Constants.PalmMaxAreaQuotient)) &&
|
|
|
|
+ getForegroundPixelPercentage(quad, foregroundMask) >= Constants.PalmMinPrecentageQuadForeground)
|
|
{
|
|
{
|
|
PalmQuad = quad;
|
|
PalmQuad = quad;
|
|
PalmHandSide = palmHand.Side;
|
|
PalmHandSide = palmHand.Side;
|
|
- lastPalmQuadArea = PalmQuad.Area;
|
|
|
|
|
|
+ lastPalmQuad = PalmQuad;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (lastPalmQuad != null && getForegroundPixelPercentage(lastPalmQuad, foregroundMask) <= Constants.PalmMaxPrecentageQuadForegroundReset)
|
|
|
|
+ reset();
|
|
}
|
|
}
|
|
|
|
|
|
private void draw()
|
|
private void draw()
|