|
@@ -31,36 +31,38 @@ namespace bbiwarg.Recognition.TouchRecognition
|
|
foreach (Finger finger in fingers)
|
|
foreach (Finger finger in fingers)
|
|
{
|
|
{
|
|
Vector2D tipPoint = finger.TipPoint;
|
|
Vector2D tipPoint = finger.TipPoint;
|
|
|
|
+ Vector2D direction = finger.TipDirection;
|
|
|
|
+ Vector2D directionInv = direction.getInverse();
|
|
|
|
+ Vector2D tipPointInside = (tipPoint + Constants.TouchEventTipInsideFactor * directionInv).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction);
|
|
|
|
+ Vector2D tipPointOutside = (tipPoint + Constants.TouchEventTipOutsideFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, directionInv);
|
|
|
|
+
|
|
outputImage.fillCircle(tipPoint.IntX, tipPoint.IntY, 3, Constants.TouchEventTipColor);
|
|
outputImage.fillCircle(tipPoint.IntX, tipPoint.IntY, 3, Constants.TouchEventTipColor);
|
|
|
|
|
|
- float floodValue = getFloodValue(tipPoint);
|
|
|
|
- if (floodValue > Constants.TouchEventMinFloodValue)
|
|
|
|
|
|
+ float floodValue = getTouchValue(tipPointInside);
|
|
|
|
+ if (floodValue > Constants.TouchEventMinTouchValue)
|
|
{
|
|
{
|
|
- //correct touchEvent position
|
|
|
|
- Vector2D direction = finger.Direction;
|
|
|
|
- Vector2D tep = (tipPoint + Constants.TouchEventTipCorrectionFactor * direction.getInverse()).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction);
|
|
|
|
-
|
|
|
|
- outputImage.fillCircle(tep.IntX, tep.IntY, 5, Constants.TouchEventDetectedColor);
|
|
|
|
- TouchEvent touchEvent = new TouchEvent(tep, floodValue, finger);
|
|
|
|
|
|
+ outputImage.fillCircle(tipPointOutside.IntX, tipPointOutside.IntY, 5, Constants.TouchEventDetectedColor);
|
|
|
|
+ TouchEvent touchEvent = new TouchEvent(tipPointOutside, floodValue, finger);
|
|
TouchEvents.Add(touchEvent);
|
|
TouchEvents.Add(touchEvent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private float getFloodValue(Point touchPoint)
|
|
|
|
|
|
+ private float getTouchValue(Point touchPoint)
|
|
{
|
|
{
|
|
|
|
+ int floodValue = 255;
|
|
|
|
+
|
|
int minX = Math.Max(touchPoint.X - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
int minX = Math.Max(touchPoint.X - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 3, depthImage.Width-1);
|
|
int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 3, depthImage.Width-1);
|
|
int minY = Math.Max(touchPoint.Y - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
int minY = Math.Max(touchPoint.Y - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 3, depthImage.Height-1);
|
|
int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 3, depthImage.Height-1);
|
|
|
|
|
|
-
|
|
|
|
Vector2D relTouch = new Vector2D(touchPoint.X - minX, touchPoint.Y - minY);
|
|
Vector2D relTouch = new Vector2D(touchPoint.X - minX, touchPoint.Y - minY);
|
|
Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
|
|
Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
|
|
Image<Gray, byte> touchArea = depthImage.Image.Copy(rect);
|
|
Image<Gray, byte> touchArea = depthImage.Image.Copy(rect);
|
|
|
|
|
|
MCvConnectedComp comp = new MCvConnectedComp();
|
|
MCvConnectedComp comp = new MCvConnectedComp();
|
|
- CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(255), new MCvScalar(0), new MCvScalar(2), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
|
|
|
|
|
|
+ CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(floodValue), new MCvScalar(Constants.TouchEventFloodfillLowDiff), new MCvScalar(Constants.TouchEventFloodfillHighDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
|
|
|
|
|
|
int matchedPixels = 0;
|
|
int matchedPixels = 0;
|
|
int countedPixels = 0;
|
|
int countedPixels = 0;
|
|
@@ -71,7 +73,7 @@ namespace bbiwarg.Recognition.TouchRecognition
|
|
Color color = outputImage.getColotAt(x, y);
|
|
Color color = outputImage.getColotAt(x, y);
|
|
byte depth = touchArea.Data[y - minY, x - minX, 0];
|
|
byte depth = touchArea.Data[y - minY, x - minX, 0];
|
|
Color subtractColor;
|
|
Color subtractColor;
|
|
- if(depth == 255)
|
|
|
|
|
|
+ if(depth == floodValue)
|
|
{
|
|
{
|
|
matchedPixels++;
|
|
matchedPixels++;
|
|
subtractColor = Constants.TouchEventAreaMatchedSubtractColor;
|
|
subtractColor = Constants.TouchEventAreaMatchedSubtractColor;
|
|
@@ -88,8 +90,7 @@ namespace bbiwarg.Recognition.TouchRecognition
|
|
|
|
|
|
float rel = (float)matchedPixels / (float)countedPixels;
|
|
float rel = (float)matchedPixels / (float)countedPixels;
|
|
|
|
|
|
- outputImage.drawLineSegment(new Utility.LineSegment2D(new Vector2D(minX, maxY), new Vector2D(minX + rel * Constants.TouchEventAreaSize, maxY)), Constants.TouchEventStatusBarColor);
|
|
|
|
- outputImage.drawLineSegment(new Utility.LineSegment2D(new Vector2D(minX, maxY-1), new Vector2D(minX + rel * Constants.TouchEventAreaSize, maxY-1)), Constants.TouchEventStatusBarColor);
|
|
|
|
|
|
+ outputImage.drawLineSegment(new Utility.LineSegment2D(new Vector2D(minX, maxY), new Vector2D(minX + rel * Constants.TouchEventAreaSize, maxY)), Constants.TouchEventStatusBarColor, 2);
|
|
|
|
|
|
return rel;
|
|
return rel;
|
|
}
|
|
}
|