|
@@ -27,7 +27,6 @@ namespace bbiwarg.Detectors.Touch
|
|
|
this.outputImage = outputImage;
|
|
|
this.fingers = fingers;
|
|
|
this.TouchEvents = new List<TouchEvent>();
|
|
|
- float floodValueThreshold = 0.33f;
|
|
|
|
|
|
foreach (Finger finger in fingers)
|
|
|
{
|
|
@@ -36,12 +35,12 @@ namespace bbiwarg.Detectors.Touch
|
|
|
outputImage.fillCircle(tipPoint.IntX, tipPoint.IntY, 3, Constants.TouchEventTipColor);
|
|
|
|
|
|
float floodValue = getFloodValue(tipPoint);
|
|
|
- if (floodValue > floodValueThreshold)
|
|
|
+ if (floodValue > Constants.TouchEventMinFloodValue)
|
|
|
{
|
|
|
//correct touchEvent position
|
|
|
Vector2D direction = finger.LineSegment.Line.Direction;
|
|
|
- Vector2D tep = (tipPoint + 5 * direction).moveInBound(0,0,depthImage.Width-1,depthImage.Height-1);
|
|
|
-
|
|
|
+ Vector2D tep = (tipPoint + Constants.TouchEventTipCorrectionFactor * direction).moveInBound(0, 0, depthImage.Width - 1, depthImage.Height - 1);
|
|
|
+
|
|
|
outputImage.fillCircle(tep.IntX, tep.IntY, 5, Constants.TouchEventDetectedColor);
|
|
|
TouchEvent touchEvent = new TouchEvent(tep, floodValue, finger);
|
|
|
TouchEvents.Add(touchEvent);
|
|
@@ -51,26 +50,23 @@ namespace bbiwarg.Detectors.Touch
|
|
|
|
|
|
private float getFloodValue(Point touchPoint)
|
|
|
{
|
|
|
- int searchSize = 15;
|
|
|
- int maxDepthDifference = 20;
|
|
|
- Int16 fingerDiameter = 5;
|
|
|
- Int16 depthAtTouch = (Int16)(depthImage.getDepthAt(touchPoint) + fingerDiameter);
|
|
|
+ Int16 depthAtTouch = (Int16)(depthImage.getDepthAt(touchPoint) + Constants.TouchEventFingerDiameter);
|
|
|
|
|
|
- int minX = Math.Max(touchPoint.X - searchSize, 0);
|
|
|
- int maxX = Math.Min(touchPoint.X + searchSize, depthImage.Width);
|
|
|
- int minY = Math.Max(touchPoint.Y - searchSize, 0);
|
|
|
- int maxY = Math.Min(touchPoint.Y + searchSize, depthImage.Height);
|
|
|
+ int minX = Math.Max(touchPoint.X - Constants.TouchEventAreaSize / 2, 0);
|
|
|
+ int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 2, depthImage.Width-1);
|
|
|
+ int minY = Math.Max(touchPoint.Y - Constants.TouchEventAreaSize / 2, 0);
|
|
|
+ int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 2, depthImage.Height-1);
|
|
|
|
|
|
int matchedPixels = 0;
|
|
|
int countedPixels = 0;
|
|
|
- for (int x = minX; x < maxX; x++)
|
|
|
+ for (int x = minX; x <= maxX; x++)
|
|
|
{
|
|
|
- for (int y = minY; y < maxY; y++)
|
|
|
+ for (int y = minY; y <= maxY; y++)
|
|
|
{
|
|
|
Int16 depth = depthImage.getDepthAt(x, y);
|
|
|
Color color = outputImage.getColotAt(x, y);
|
|
|
Color subtractColor;
|
|
|
- if (depthAtTouch < depth && Math.Abs(depthAtTouch - depth) < maxDepthDifference)
|
|
|
+ if (depthAtTouch < depth && Math.Abs(depthAtTouch - depth) < Constants.TouchEventMaxDepthDifference)
|
|
|
{
|
|
|
matchedPixels++;
|
|
|
subtractColor = Constants.TouchEventAreaMatchedSubtractColor;
|
|
@@ -87,12 +83,9 @@ namespace bbiwarg.Detectors.Touch
|
|
|
|
|
|
float rel = (float)matchedPixels / (float)countedPixels;
|
|
|
|
|
|
- //status bar (% of matched pixels) -> green
|
|
|
- for (int x = minX; x < minX + (maxX - minX) * rel; x++)
|
|
|
- {
|
|
|
- outputImage.drawPixel(x, maxY - 1, Constants.TouchEventStatusBarColor);
|
|
|
- }
|
|
|
-
|
|
|
+ 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);
|
|
|
+
|
|
|
return rel;
|
|
|
}
|
|
|
}
|