|
@@ -14,12 +14,14 @@ namespace bbiwarg.Detectors.Touch
|
|
class TouchDetector
|
|
class TouchDetector
|
|
{
|
|
{
|
|
private DepthImage depthImage;
|
|
private DepthImage depthImage;
|
|
|
|
+ private TouchImage touchImage;
|
|
private List<Finger> fingers;
|
|
private List<Finger> fingers;
|
|
private List<TouchEvent> touchEvents;
|
|
private List<TouchEvent> touchEvents;
|
|
|
|
|
|
- public TouchDetector(DepthImage depthImage, List<Finger> fingers) {
|
|
|
|
|
|
+ public TouchDetector(DepthImage depthImage, List<Finger> fingers, TouchImage touchImage) {
|
|
this.depthImage = depthImage;
|
|
this.depthImage = depthImage;
|
|
this.fingers = fingers;
|
|
this.fingers = fingers;
|
|
|
|
+ this.touchImage = touchImage;
|
|
this.touchEvents = new List<TouchEvent>();
|
|
this.touchEvents = new List<TouchEvent>();
|
|
float touchValueThreshold = 0.5f;
|
|
float touchValueThreshold = 0.5f;
|
|
|
|
|
|
@@ -37,7 +39,7 @@ namespace bbiwarg.Detectors.Touch
|
|
float touchValue = getTouchValueAt(fp.getX(), fp.getY());
|
|
float touchValue = getTouchValueAt(fp.getX(), fp.getY());
|
|
if (touchValue > touchValueThreshold)
|
|
if (touchValue > touchValueThreshold)
|
|
{
|
|
{
|
|
- TouchEvent touchEvent = new TouchEvent(fp.getX(), fp.getY(), touchValue);
|
|
|
|
|
|
+ TouchEvent touchEvent = new TouchEvent(fp.getX(), fp.getY(), touchValue, finger);
|
|
touchEvents.Add(touchEvent);
|
|
touchEvents.Add(touchEvent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -50,7 +52,7 @@ namespace bbiwarg.Detectors.Touch
|
|
private float getTouchValueAt(int touchX, int touchY) {
|
|
private float getTouchValueAt(int touchX, int touchY) {
|
|
int searchSize = 15;
|
|
int searchSize = 15;
|
|
int maxDepthDifference = 20;
|
|
int maxDepthDifference = 20;
|
|
- Int16 fingerDiameter = 10;
|
|
|
|
|
|
+ Int16 fingerDiameter = 7;
|
|
Int16 depthAtTouch = (Int16) (depthImage.getDepthAt(touchX, touchY) + fingerDiameter);
|
|
Int16 depthAtTouch = (Int16) (depthImage.getDepthAt(touchX, touchY) + fingerDiameter);
|
|
|
|
|
|
int minX = Math.Max(touchX - searchSize, 0);
|
|
int minX = Math.Max(touchX - searchSize, 0);
|
|
@@ -63,10 +65,10 @@ namespace bbiwarg.Detectors.Touch
|
|
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);
|
|
Int16 depth = depthImage.getDepthAt(x,y);
|
|
- depthImage.setDepthAt(x, y, Int16.MaxValue - 1);//counted pixels -> red
|
|
|
|
|
|
+ touchImage.setTouchAt(x, y, TouchImageState.touchArea);
|
|
if (Math.Abs(depthAtTouch - depth) < maxDepthDifference) {
|
|
if (Math.Abs(depthAtTouch - depth) < maxDepthDifference) {
|
|
matchedPixels++;
|
|
matchedPixels++;
|
|
- depthImage.setDepthAt(x, y, Int16.MaxValue);//matched pixels -> blue
|
|
|
|
|
|
+ touchImage.setTouchAt(x, y, TouchImageState.touchAreaMatched);
|
|
}
|
|
}
|
|
countedPixels++;
|
|
countedPixels++;
|
|
}
|
|
}
|
|
@@ -76,7 +78,7 @@ namespace bbiwarg.Detectors.Touch
|
|
|
|
|
|
//status bar (% of matched pixels) -> green
|
|
//status bar (% of matched pixels) -> green
|
|
for (int x = minX; x < minX + (maxX-minX)*rel; x++) {
|
|
for (int x = minX; x < minX + (maxX-minX)*rel; x++) {
|
|
- depthImage.setDepthAt(x, maxY-1, Int16.MaxValue-2);
|
|
|
|
|
|
+ touchImage.setTouchAt(x, maxY - 1, TouchImageState.touchAreaStatusBar);
|
|
}
|
|
}
|
|
|
|
|
|
return rel;
|
|
return rel;
|