|
@@ -50,12 +50,18 @@ namespace bbiwarg.Detectors.TouchDetection
|
|
|
|
|
|
private float getFloodValue(Point touchPoint)
|
|
|
{
|
|
|
- Int16 depthAtTouch = (Int16)(depthImage.getDepthAt(touchPoint) + Constants.TouchEventFingerDiameter);
|
|
|
+ int minX = Math.Max(touchPoint.X - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
|
+ int maxX = Math.Min(touchPoint.X + Constants.TouchEventAreaSize / 3, depthImage.Width-1);
|
|
|
+ int minY = Math.Max(touchPoint.Y - 2*Constants.TouchEventAreaSize / 3, 0);
|
|
|
+ int maxY = Math.Min(touchPoint.Y + Constants.TouchEventAreaSize / 3, depthImage.Height-1);
|
|
|
|
|
|
- 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);
|
|
|
+
|
|
|
+ Vector2D relTouch = new Vector2D(touchPoint.X - minX, touchPoint.Y - minY);
|
|
|
+ Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
|
|
|
+ Image<Gray, byte> touchArea = depthImage.Image.Copy(rect);
|
|
|
+
|
|
|
+ MCvConnectedComp comp = new MCvConnectedComp();
|
|
|
+ CvInvoke.cvFloodFill(touchArea, relTouch, new MCvScalar(255), new MCvScalar(0), new MCvScalar(1), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, IntPtr.Zero);
|
|
|
|
|
|
int matchedPixels = 0;
|
|
|
int countedPixels = 0;
|
|
@@ -63,10 +69,10 @@ namespace bbiwarg.Detectors.TouchDetection
|
|
|
{
|
|
|
for (int y = minY; y <= maxY; y++)
|
|
|
{
|
|
|
- Int16 depth = depthImage.getDepthAt(x, y);
|
|
|
Color color = outputImage.getColotAt(x, y);
|
|
|
+ byte depth = touchArea.Data[y - minY, x - minX, 0];
|
|
|
Color subtractColor;
|
|
|
- if (depthAtTouch < depth && Math.Abs(depthAtTouch - depth) < Constants.TouchEventMaxDepthDifference)
|
|
|
+ if(depth == 255)
|
|
|
{
|
|
|
matchedPixels++;
|
|
|
subtractColor = Constants.TouchEventAreaMatchedSubtractColor;
|