|
@@ -15,33 +15,42 @@ namespace bbiwarg.Detectors.Touch
|
|
{
|
|
{
|
|
private DepthImage depthImage;
|
|
private DepthImage depthImage;
|
|
private List<Finger> fingers;
|
|
private List<Finger> fingers;
|
|
|
|
+ private List<TouchEvent> touchEvents;
|
|
|
|
|
|
public TouchDetector(DepthImage depthImage, List<Finger> fingers) {
|
|
public TouchDetector(DepthImage depthImage, List<Finger> fingers) {
|
|
this.depthImage = depthImage;
|
|
this.depthImage = depthImage;
|
|
this.fingers = fingers;
|
|
this.fingers = fingers;
|
|
|
|
+ this.touchEvents = new List<TouchEvent>();
|
|
|
|
+ float touchValueThreshold = 0.5f;
|
|
|
|
|
|
foreach (Finger finger in fingers) {
|
|
foreach (Finger finger in fingers) {
|
|
- //farthest
|
|
|
|
FingerPoint fp1 = finger.getFarthest();
|
|
FingerPoint fp1 = finger.getFarthest();
|
|
- float touchFP1 = isTouchAt(fp1.getX(), fp1.getY());
|
|
|
|
-
|
|
|
|
- //nearest
|
|
|
|
FingerPoint fp2 = finger.getNearest();
|
|
FingerPoint fp2 = finger.getNearest();
|
|
- float touchFP2 = isTouchAt(fp2.getX(), fp2.getY());
|
|
|
|
-
|
|
|
|
- int depthDifference = fp1.getDepth() - fp2.getDepth();
|
|
|
|
|
|
+ FingerPoint fp;
|
|
|
|
|
|
|
|
|
|
- if(touchFP1 > 0.6f && touchFP2 > 0.6f && depthDifference > 20 && depthDifference < 50)
|
|
|
|
- Console.WriteLine("TouchEvent bei x:" + fp1.getX() + " y:" + fp1.getY() + " [FP1:" + Math.Round(touchFP1, 1) + " FP2:" + Math.Round(touchFP2, 1) + "]");
|
|
|
|
|
|
+ if (fp1.getY() < fp2.getY())
|
|
|
|
+ fp = fp1;
|
|
|
|
+ else
|
|
|
|
+ fp = fp2;
|
|
|
|
|
|
|
|
+ float touchValue = getTouchValueAt(fp.getX(), fp.getY());
|
|
|
|
+ if (touchValue > touchValueThreshold)
|
|
|
|
+ {
|
|
|
|
+ TouchEvent touchEvent = new TouchEvent(fp.getX(), fp.getY(), touchValue);
|
|
|
|
+ touchEvents.Add(touchEvent);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private float isTouchAt(int touchX, int touchY) {
|
|
|
|
|
|
+ public List<TouchEvent> getTouchEvents() {
|
|
|
|
+ return touchEvents;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private float getTouchValueAt(int touchX, int touchY) {
|
|
int searchSize = 15;
|
|
int searchSize = 15;
|
|
int maxDepthDifference = 20;
|
|
int maxDepthDifference = 20;
|
|
- Int16 fingerDiameter = 5;
|
|
|
|
|
|
+ Int16 fingerDiameter = 10;
|
|
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);
|