|
@@ -1,5 +1,6 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
@@ -30,7 +31,7 @@ namespace bbiwarg
|
|
|
findMinDepth();
|
|
|
|
|
|
//maxDepth
|
|
|
- maxDepth = (Int16) (minDepth + 200);
|
|
|
+ maxDepth = (Int16)(minDepth + 200);
|
|
|
thresholdDepth(minDepth, maxDepth);
|
|
|
|
|
|
//edges
|
|
@@ -66,7 +67,7 @@ namespace bbiwarg
|
|
|
}
|
|
|
|
|
|
public bool isFingerPoint(int x, int y) {
|
|
|
- return fingerPoints[x,y];
|
|
|
+ return fingerPoints[x, y];
|
|
|
}
|
|
|
|
|
|
private void setDepthAt(int x, int y, Int16 value) {
|
|
@@ -103,7 +104,7 @@ namespace bbiwarg
|
|
|
|
|
|
private void calculateEdges() {
|
|
|
Image<Gray, Byte> tmp = image.Convert<Byte>(delegate(Int16 depth) { return (byte)(((depth - minDepth) * Byte.MaxValue) / (maxDepth - minDepth)); });
|
|
|
- Image<Gray, byte> tmp2 = tmp.Canny(100, 75, 3);
|
|
|
+ Image<Gray, byte> tmp2 = tmp.Canny(150, 75, 3);
|
|
|
edges = tmp2.Convert<Int16>(delegate(byte depth) { if(depth > 0) {return Int16.MaxValue;} else {return 0;}});//((depth * Int16.MaxValue) / Byte.MaxValue); });
|
|
|
}
|
|
|
|
|
@@ -112,65 +113,54 @@ namespace bbiwarg
|
|
|
int maxFingerSize = 30;
|
|
|
int minFingerSize = 10;
|
|
|
fingerPoints = new bool[width, height];
|
|
|
- bool[,] pixelsCheckedHorizontal = new bool[width, height];
|
|
|
- bool[,] pixelsCheckedVertical = new bool[width, height];
|
|
|
-
|
|
|
- for (int x = 0; x < width; x++) {
|
|
|
- for (int y = 0; y < height; y++) {
|
|
|
- if (pixelsCheckedHorizontal[x,y] == false && getDepthAt(x, y) < maxDepth && getEdgeAt(x,y) == 0) {
|
|
|
- pixelsCheckedHorizontal[x, y] = true;
|
|
|
- pixelsCheckedVertical[x, y] = true;
|
|
|
-
|
|
|
- //check horizontal
|
|
|
- int edgeLeftX = x-1;
|
|
|
- int edgeRightX = x+1;
|
|
|
- bool edgeLeftFound = false;
|
|
|
+
|
|
|
+ for (int y = 0; y < height; y++) {
|
|
|
+ for (int x = 0; x < width; x++) {
|
|
|
+ if (getEdgeAt(x, y) > 0) {
|
|
|
+ //search horizontal
|
|
|
bool edgeRightFound = false;
|
|
|
- while (edgeLeftFound == false && (x-edgeLeftX) < maxFingerSize && edgeLeftX > 0)
|
|
|
- {
|
|
|
- if (getEdgeAt(edgeLeftX, y) > 0)
|
|
|
- edgeLeftFound = true;
|
|
|
- edgeLeftX--;
|
|
|
- }
|
|
|
- while (edgeRightFound == false && (edgeRightX - x) < maxFingerSize && edgeRightX < width)
|
|
|
- {
|
|
|
+ int edgeRightX = x + minFingerSize;
|
|
|
+ while (!edgeRightFound && edgeRightX < width) {
|
|
|
if (getEdgeAt(edgeRightX, y) > 0)
|
|
|
edgeRightFound = true;
|
|
|
- edgeRightX++;
|
|
|
+ else
|
|
|
+ edgeRightX++;
|
|
|
}
|
|
|
|
|
|
- if (edgeLeftFound && edgeRightFound && (edgeRightX - edgeLeftX) < maxFingerSize && (edgeRightX - edgeLeftX) > minFingerSize) {
|
|
|
- for (int i = edgeLeftX; i < edgeRightX; i++) {
|
|
|
- pixelsCheckedHorizontal[i, y] = true;
|
|
|
- }
|
|
|
- fingerPoints[(edgeLeftX+edgeRightX)/2, y] = true;
|
|
|
+ if (edgeRightFound){
|
|
|
+ int midX = (edgeRightX + x) / 2;
|
|
|
+ Int16 depthLeft = getDepthAt(x, y);
|
|
|
+ Int16 depthMid = getDepthAt(midX, y);
|
|
|
+ Int16 depthRight = getDepthAt(edgeRightX, y);
|
|
|
+
|
|
|
+ if ((edgeRightX - x) < maxFingerSize && depthLeft > depthMid && depthMid < depthRight) {
|
|
|
+ fingerPoints[midX, y] = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //check vertical
|
|
|
- int edgeTopY = y-1;
|
|
|
- int edgeBottomY = y+1;
|
|
|
- bool edgeTopFound = false;
|
|
|
+ //search vertical
|
|
|
bool edgeBottomFound = false;
|
|
|
- while (edgeTopFound == false && (y-edgeTopY) < maxFingerSize && edgeTopY > 0)
|
|
|
- {
|
|
|
- if (getEdgeAt(x, edgeTopY) > 0)
|
|
|
- edgeTopFound = true;
|
|
|
- edgeTopY--;
|
|
|
- }
|
|
|
- while (edgeBottomFound == false && (edgeBottomY-y) < maxFingerSize && edgeBottomY < height)
|
|
|
- {
|
|
|
+ int edgeBottomY = y + minFingerSize;
|
|
|
+ while (!edgeBottomFound && edgeBottomY < height) {
|
|
|
if (getEdgeAt(x, edgeBottomY) > 0)
|
|
|
edgeBottomFound = true;
|
|
|
- edgeBottomY++;
|
|
|
+ else
|
|
|
+ edgeBottomY++;
|
|
|
}
|
|
|
- if (edgeBottomFound && edgeTopFound && (edgeBottomY - edgeTopY) < maxFingerSize && (edgeBottomY - edgeTopY) > minFingerSize)
|
|
|
- {
|
|
|
- for (int i = edgeTopY; i < edgeBottomY; i++)
|
|
|
- {
|
|
|
- pixelsCheckedVertical[x, i] = true;
|
|
|
+
|
|
|
+ if (edgeBottomFound) {
|
|
|
+ int midY = (edgeBottomY + y) / 2;
|
|
|
+ Int16 depthTop = getDepthAt(x, y);
|
|
|
+ Int16 depthMid = getDepthAt(x, midY);
|
|
|
+ Int16 depthBottom = getDepthAt(x, edgeBottomY);
|
|
|
+
|
|
|
+ if ((edgeBottomY - y) < maxFingerSize && depthTop > depthMid && depthMid < depthBottom) {
|
|
|
+ fingerPoints[x, midY] = true;
|
|
|
}
|
|
|
- fingerPoints[x, (edgeTopY+edgeBottomY)/2] = true;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ x = edgeRightX - 1;
|
|
|
}
|
|
|
}
|
|
|
}
|