Stap 4: Frame en gebaar gegevens
Sprong Motion framegegevens waarin de gebaren (cirkel, snuifje, Palm gezicht naar beneden en alle andere gebaren)
Sprong beweging heeft twee IR Camera en drie IR Led's. De sprong beweging vormen een 3D-verzameling van gegevens met behulp van de drie IR Led die stak een IR Dot patroon, de IR-Camera van neemt foto's bekend als frames. De frames van de sprong motion-apparaat naar de computer krijgen verzonden en we kunnen het programma.
De sprong bewegings analyse, de foto's en de stip positionering met behulp van ingewikkelde wiskunde en vergelijk de gegevens van de twee foto's genomen door IR Camera en het gebruik van de twee 2D vertegenwoordiging te krijgen van een 3D-weergave.
De sprong motion apparaat vangt op 300 fps. Wij programmeren dan wat gebeurt er met elk van de frames die zijn verzonden naar onze computer.
Code:
public void onFrame(Controller controller) { Frame frame = controller.frame(); // The latest frame // Frame previous = controller.frame(1); //The previous frame // System.out.println("Frame available"); if (!iBoxGet) { iBox = frame.interactionBox(); iBoxGet = true; System.out.println("Interaction box set!"); } // Pointable furthestFront = frame.pointables().frontmost(); Hand rightHand = frame.hands().rightmost(); Vector palmV = rightHand.palmVelocity(); // System.out.println("Velocity: X: " + palmV.getX() + ", Y: " + // palmV.getY() // + ", Z: " + palmV.getZ()); Vector palmN = rightHand.palmNormal(); // System.out.println("Normal: X: " + palmN.getX() + ", Y: " // + palmN.getY() + ", Z: " + palmN.getZ()); Point mouseLoc = MouseInfo.getPointerInfo().getLocation(); int currentMouseX = mouseLoc.x; int currentMouseY = mouseLoc.y; if (readyForControl && rightHand.confidence() > .15) { if (!isMoving && !wasInTabState && frame.hands().count() > 1) { Hand leftHand = frame.hands().leftmost(); if (leftHand.pinchStrength() > .8 && rightHand.pinchStrength() > .8) { if (!isResizing) { System.out.println("Resizing..."); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_S); robot.keyRelease(KeyEvent.VK_S); robot.keyPress(KeyEvent.VK_DOWN); robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_RIGHT); isResizing = true; } }else{ if(isResizing){ System.out.println("Resizing complete!"); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); isResizing = false; } } } // System.out.println("Confidence: " + rightHand.confidence()); if (rightHand.grabStrength() > .99 && !wasInTabState && !isResizing) { if (!isMoving && palmN.getY() < .8) { robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_R); robot.keyRelease(KeyEvent.VK_R);</p><p> robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_M); robot.keyRelease(KeyEvent.VK_M); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); isMoving = true; } // System.out.println(rightHand.grabStrength()); } else { // System.out.println("Not grabbing"); if (isMoving) { robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); isMoving = false; if (palmN.getX() != 0 && palmN.getY() != 0 && palmN.getZ() != 0) { if (palmN.getY() < -.1 && palmN.getZ() > -.8) { if (currentMouseY <= 8) { robot.keyPress(KeyEvent.VK_WINDOWS); robot.keyPress(KeyEvent.VK_UP); robot.keyRelease(KeyEvent.VK_WINDOWS); robot.keyRelease(KeyEvent.VK_UP); } else { if (screenWidth - currentMouseX <= 12) { robot.keyPress(KeyEvent.VK_WINDOWS); robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_WINDOWS); robot.keyRelease(KeyEvent.VK_RIGHT); } else if (currentMouseX <= 12) { robot.keyPress(KeyEvent.VK_WINDOWS); robot.keyPress(KeyEvent.VK_LEFT); robot.keyRelease(KeyEvent.VK_WINDOWS); robot.keyRelease(KeyEvent.VK_LEFT); } } } else { System.out.println("Normal: X: " + palmN.getX() + ", Y: " + palmN.getY() + ", Z: " + palmN.getZ()); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_N); robot.keyRelease(KeyEvent.VK_N); } } } }</p><p> if (!isMoving && !isResizing) { if (palmN.getY() < -.8 && palmN.getZ() > -.5) { wasFacingDown = true; wasTabbing = false; if (wasInTabState) { robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); wasInTabState = false; } } else if (palmN.getY() >= .8 && wasFacingDown && !wasInTabState) { System.out.println("Alt tabbing"); wasFacingDown = false; wasInTabState = true;</p><p> wasTabbing = false; robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_TAB); robot.delay(100); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_ALT); try { Runtime.getRuntime().exec( "cmd /c start " + "C:\\WindowSwitcher.lnk"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } robot.delay(300); } else if (wasInTabState && !wasFacingDown && !wasTabbing && palmN.getY() < .45) {</p><p> wasTabbing = true; } else if (wasInTabState && !wasFacingDown && wasTabbing && palmN.getY() > .75) { robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); wasTabbing = false; } }</p><p> /* * if (!isMoving && !wasInTabState) { /* if(palmN.getZ() <= -.7 && * rightHand.grabStrength() < .1){ * System.out.println("Palm vertical velocity: " + * rightHand.palmVelocity().getY()); //float resultVerticalV = * Math.round(Math.abs(rightHand.palmVelocity().getY()) - 1); * //if(resultVerticalV > 0){ robot.mouseWheel((int) * Math.round(((rightHand.palmVelocity().getY()) / 500))); //} * }else{ */</p><p> if (!isMoving && !wasInTabState && frame.gestures().count() > 0 && frame.hands().count() == 1 && !isResizing) { CircleGesture circleGesture = new CircleGesture(frame .gestures().get(0)); // System.out.println("Pinch strength: " + // rightHand.pinchStrength()); if (circleGesture.durationSeconds() > .5 && !justCircleGestured && rightHand.pinchStrength() > .8) { System.out.println("Closed a window!"); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_F4); robot.keyRelease(KeyEvent.VK_F4); robot.keyRelease(KeyEvent.VK_ALT); justCircleGestured = true; } } else { justCircleGestured = false; }</p><p> float xSpeed = (palmV.getX() / 6); float ySpeed = (palmV.getY() / 6); // System.out.println("xSpeed: " + xSpeed + ", ySpeed: " + ySpeed); robot.mouseMove((int) (currentMouseX + xSpeed), (int) (currentMouseY - ySpeed));</p><p> // } } } }</p>