|
@@ -14,14 +14,14 @@ namespace bbiwarg.Detectors.Fingers
|
|
{
|
|
{
|
|
private DepthImage depthImage;
|
|
private DepthImage depthImage;
|
|
private EdgeImage edgeImage;
|
|
private EdgeImage edgeImage;
|
|
- private bool[,] possibleFingerPoints;
|
|
|
|
- private bool[,] fingerPoints;
|
|
|
|
|
|
+ private FingerImage fingerImage;
|
|
private List<Finger> possibleFingers;
|
|
private List<Finger> possibleFingers;
|
|
private List<Finger> fingers;
|
|
private List<Finger> fingers;
|
|
|
|
|
|
- public FingerDetector(DepthImage depthImage, EdgeImage edgeImage) {
|
|
|
|
|
|
+ public FingerDetector(DepthImage depthImage, EdgeImage edgeImage, FingerImage fingerImage) {
|
|
this.depthImage = depthImage;
|
|
this.depthImage = depthImage;
|
|
this.edgeImage = edgeImage;
|
|
this.edgeImage = edgeImage;
|
|
|
|
+ this.fingerImage = fingerImage;
|
|
|
|
|
|
findPossibleFingerPoints();
|
|
findPossibleFingerPoints();
|
|
findPossibleFingers();
|
|
findPossibleFingers();
|
|
@@ -29,14 +29,6 @@ namespace bbiwarg.Detectors.Fingers
|
|
setFingerPoints();
|
|
setFingerPoints();
|
|
}
|
|
}
|
|
|
|
|
|
- public bool isPossibleFingerPointAt(int x, int y) {
|
|
|
|
- return possibleFingerPoints[x, y];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public bool isFingerPointAt(int x, int y) {
|
|
|
|
- return fingerPoints[x, y];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public List<Finger> getFingers() {
|
|
public List<Finger> getFingers() {
|
|
return fingers;
|
|
return fingers;
|
|
}
|
|
}
|
|
@@ -47,7 +39,6 @@ namespace bbiwarg.Detectors.Fingers
|
|
int height = depthImage.getHeight();
|
|
int height = depthImage.getHeight();
|
|
int maxFingerSize = 30;
|
|
int maxFingerSize = 30;
|
|
int minFingerSize = 10;
|
|
int minFingerSize = 10;
|
|
- possibleFingerPoints = new bool[width, height];
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
for (int y = 0; y < height; y++) {
|
|
for (int x = 0; x < width; x++) {
|
|
for (int x = 0; x < width; x++) {
|
|
@@ -69,7 +60,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
Int16 depthRight = depthImage.getDepthAt(edgeRightX, y);
|
|
Int16 depthRight = depthImage.getDepthAt(edgeRightX, y);
|
|
|
|
|
|
if ((edgeRightX - x) < maxFingerSize && depthLeft > depthMid && depthMid < depthRight) {
|
|
if ((edgeRightX - x) < maxFingerSize && depthLeft > depthMid && depthMid < depthRight) {
|
|
- possibleFingerPoints[midX, y] = true;
|
|
|
|
|
|
+ fingerImage.setFingerAt(midX, y, FingerImageState.possibleFinger);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -90,7 +81,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
Int16 depthBottom = depthImage.getDepthAt(x, edgeBottomY);
|
|
Int16 depthBottom = depthImage.getDepthAt(x, edgeBottomY);
|
|
|
|
|
|
if ((edgeBottomY - y) < maxFingerSize && depthTop > depthMid && depthMid < depthBottom) {
|
|
if ((edgeBottomY - y) < maxFingerSize && depthTop > depthMid && depthMid < depthBottom) {
|
|
- possibleFingerPoints[x, midY] = true;
|
|
|
|
|
|
+ fingerImage.setFingerAt(x, midY, FingerImageState.possibleFinger);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -110,7 +101,7 @@ namespace bbiwarg.Detectors.Fingers
|
|
{
|
|
{
|
|
for (int x = 0; x < width; x++)
|
|
for (int x = 0; x < width; x++)
|
|
{
|
|
{
|
|
- if (possibleFingerPoints[x, y])
|
|
|
|
|
|
+ if (fingerImage.getStateAt(x,y) == FingerImageState.possibleFinger)
|
|
{
|
|
{
|
|
Int16 depth = depthImage.getDepthAt(x, y);
|
|
Int16 depth = depthImage.getDepthAt(x, y);
|
|
FingerPoint fingerPoint = new FingerPoint(x,y,depth);
|
|
FingerPoint fingerPoint = new FingerPoint(x,y,depth);
|
|
@@ -158,78 +149,11 @@ namespace bbiwarg.Detectors.Fingers
|
|
private void setFingerPoints() {
|
|
private void setFingerPoints() {
|
|
int width = depthImage.getWidth();
|
|
int width = depthImage.getWidth();
|
|
int height = depthImage.getHeight();
|
|
int height = depthImage.getHeight();
|
|
- fingerPoints = new bool[width, height];
|
|
|
|
|
|
|
|
foreach (Finger finger in fingers) {
|
|
foreach (Finger finger in fingers) {
|
|
PointF lineEndPoint1 = finger.getLineEndPoint1();
|
|
PointF lineEndPoint1 = finger.getLineEndPoint1();
|
|
PointF lineEndPoint2 = finger.getLineEndPoint2();
|
|
PointF lineEndPoint2 = finger.getLineEndPoint2();
|
|
- drawFingerPointLine(lineEndPoint1, lineEndPoint2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private void drawFingerPointLine(PointF start, PointF end)
|
|
|
|
- {
|
|
|
|
- int width = depthImage.getWidth();
|
|
|
|
- int height = depthImage.getHeight();
|
|
|
|
-
|
|
|
|
- // bresenham from wikipedia
|
|
|
|
- int xstart = (int)start.X, xend = (int)end.X, ystart = (int)start.Y, yend = (int)end.Y;
|
|
|
|
- int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
|
|
|
|
-
|
|
|
|
- /* Entfernung in beiden Dimensionen berechnen */
|
|
|
|
- dx = xend - xstart;
|
|
|
|
- dy = yend - ystart;
|
|
|
|
-
|
|
|
|
- /* Vorzeichen des Inkrements bestimmen */
|
|
|
|
- incx = dx < 0 ? -1 : 1;
|
|
|
|
- incy = dy < 0 ? -1 : 1;
|
|
|
|
- if (dx < 0) dx = -dx;
|
|
|
|
- if (dy < 0) dy = -dy;
|
|
|
|
-
|
|
|
|
- /* feststellen, welche Entfernung größer ist */
|
|
|
|
- if (dx > dy)
|
|
|
|
- {
|
|
|
|
- /* x ist schnelle Richtung */
|
|
|
|
- pdx = incx; pdy = 0; /* pd. ist Parallelschritt */
|
|
|
|
- ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */
|
|
|
|
- es = dy; el = dx; /* Fehlerschritte schnell, langsam */
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- /* y ist schnelle Richtung */
|
|
|
|
- pdx = 0; pdy = incy; /* pd. ist Parallelschritt */
|
|
|
|
- ddx = incx; ddy = incy; /* dd. ist Diagonalschritt */
|
|
|
|
- es = dx; el = dy; /* Fehlerschritte schnell, langsam */
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* Initialisierungen vor Schleifenbeginn */
|
|
|
|
- x = xstart;
|
|
|
|
- y = ystart;
|
|
|
|
- err = el / 2;
|
|
|
|
- fingerPoints[Math.Min(width - 1, Math.Max(0, x)), Math.Min(height - 1, Math.Max(0, y))] = true;
|
|
|
|
-
|
|
|
|
- /* Pixel berechnen */
|
|
|
|
- for (t = 0; t < el; ++t) /* t zaehlt die Pixel, el ist auch Anzahl */
|
|
|
|
- {
|
|
|
|
- /* Aktualisierung Fehlerterm */
|
|
|
|
- err -= es;
|
|
|
|
- if (err < 0)
|
|
|
|
- {
|
|
|
|
- /* Fehlerterm wieder positiv (>=0) machen */
|
|
|
|
- err += el;
|
|
|
|
- /* Schritt in langsame Richtung, Diagonalschritt */
|
|
|
|
- x += ddx;
|
|
|
|
- y += ddy;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- /* Schritt in schnelle Richtung, Parallelschritt */
|
|
|
|
- x += pdx;
|
|
|
|
- y += pdy;
|
|
|
|
- }
|
|
|
|
- fingerPoints[Math.Min(width - 1, Math.Max(0, x)), Math.Min(height - 1, Math.Max(0, y))] = true;
|
|
|
|
|
|
+ fingerImage.drawLine(lineEndPoint1, lineEndPoint2, FingerImageState.fingerDetected);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|