Java LeapMotion不识别任何手势

Java LeapMotion不识别任何手势,java,gesture,leap-motion,Java,Gesture,Leap Motion,我正在创建一个Java程序来识别LeapMotion的一些特性 我正在关注这一点 代码 import com.leapmotion.leap.*; import com.leapmotion.leap.Gesture.State; import java.io.IOException; //Listener class LeapListener extends Listener { public void onInit(Controller controller) { S

我正在创建一个Java程序来识别LeapMotion的一些特性

我正在关注这一点

代码

import com.leapmotion.leap.*;
import com.leapmotion.leap.Gesture.State;
import java.io.IOException;
//Listener
class LeapListener extends Listener {
    public void onInit(Controller controller) {
        System.out.println("Initialized");
    }

    public void onConnect(Controller controller) {
        System.out.println("Connected to Motion Sensor");
        controller.enableGesture(Gesture.Type.TYPE_SWIPE);
        controller.enableGesture(Gesture.Type.TYPE_CIRCLE);
        controller.enableGesture(Gesture.Type.TYPE_SCREEN_TAP);
        controller.enableGesture(Gesture.Type.TYPE_KEY_TAP);
    }

    public void onDisconnect(Controller controller) {
        System.out.println("Motion Sensor disconnected");
    }

    public void onExit(Controller controller) {
        System.out.println("Exited");
    }

    //Method for detection 
    public void onFrame(Controller controller) {
        Frame frame = controller.frame();
        //FRAME DATA always
        /*System.out.println("Frame id: "+ frame.id()
                            + ", Timestamp: " + frame.timestamp()
                            + ", Hands: " + frame.hands().count()
                            + ", Fingers: " + frame.fingers().count()
                            + ", Tools: " + frame.tools().count()
                            + ", Gestures: " + frame.gestures().count());*/

        //HAND DATE shown when hand is detected
        /*for (Hand hand: frame.hands()) {
            String handType = hand.isLeft() ? "Left Hand" : "Right hand";
            System.out.println(handType + " " + ", id: " + hand.id()
                                + ", Palm position: " + hand.palmPosition());

            Vector normal = hand.palmNormal();
            Vector direction = hand.direction();

            System.out.println("Pitch: " + Math.toDegrees(direction.pitch())
                                        + "Roll: " + Math.toDegrees(normal.roll())
                                        + "Yaw: " + Math.toDegrees(direction.yaw()));
        }*/

        //FINGER DATA shown when hand is detected
        /*for (Finger finger: frame.fingers()) {
            System.out.println("Finger Type: " + finger.type()
                                + " ID: " + finger.id()
                                + " Finger Length (mm): " + finger.length()
                                + " Finger Width (mm): " + finger.width());

            for (Bone.Type boneType : Bone.Type.values()){
                Bone bone = finger.bone(boneType);
                System.out.println("Bone Type: " + bone.type()
                    + " Start: " + bone.prevJoint()
                    + " End : " + bone.nextJoint()
                    + " Direction: " + bone.direction());
            }
        }*/

        //TOOL DATA
        /*for (Tool tool: frame.tools()) {
            System.out.println("Tool ID: " + tool.id()
                                + " Tip Position: " + tool.tipPosition()
                                + " Direction: " + tool.direction()
                                + " Width (mm): " + tool.width()
                                + " Touch Distance (mm): " + tool.touchDistance());
        }*/

        //GESTURE
        GestureList gestures = frame.gestures();
        for (int i = 0; i < gestures.count(); i++) {
            Gesture gesture = gestures.get(i);

            switch (gesture.type()) {
            case TYPE_CIRCLE:
                CircleGesture circle = new CircleGesture(gesture);

                String clockWiseness;
                if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI/4 ) {
                    clockWiseness = "clockwise";
                } else {
                    clockWiseness = "counter-clockwise";
                }

                double sweptAngle = 0;
                if (circle.state() != State.STATE_START) {
                    CircleGesture previous = new CircleGesture(controller.frame(1).gesture(circle.id()));
                    sweptAngle = (circle.progress() - previous.progress()) * 2 * Math.PI;
                } 

                System.out.println("Circle ID: " + circle.id()
                                    + " State: " + circle.state()
                                    // Progress = how many times did you make the circle
                                    + " Progress " + circle.progress()
                                    + " Radius: " + circle.radius()
                                    + " Angle: " + Math.toDegrees(sweptAngle)
                                    + " Direction: " + clockWiseness);

                break;

            case TYPE_SWIPE:
                SwipeGesture swipe = new SwipeGesture(gesture);
                System.out.println("Swipe ID: " + swipe.id()
                                + " State: " + swipe.state()
                                + " Swipe Position (mm): " + swipe.position()
                                + " Direction: " + swipe.direction()
                                + " Speed (mm/s): " + swipe.speed());
                break;

            case TYPE_SCREEN_TAP:
                ScreenTapGesture screenTap = new ScreenTapGesture();
                System.out.println("Tap ID: " + screenTap.id()
                                + " State: " + screenTap.state()
                                + " Position: " + screenTap.position()
                                + " Direction: " + screenTap.direction());
                break;

            case TYPE_KEY_TAP:
                KeyTapGesture keyTap = new KeyTapGesture();
                System.out.println("Key ID: " + keyTap.id()
                                    + " State: " + keyTap.state()
                                    + " Position: " + keyTap.position()
                                    + " Direction: " + keyTap.direction());
                break;

            default:
                    System.out.println("Unkown gesture");
                    break;
            }

        }

    }
}

public class LeapController {

    public static void main(String[] args) {
        //Initialize the listener
        LeapListener listener = new LeapListener();
        Controller controller = new Controller();

        controller.addListener(listener);

        System.out.println("Press enter to quit");

        try {
            System.in.read();
        } catch (IOException e){
            e.printStackTrace();
        }

        controller.removeListener(listener);
    }

}
导入com.leapmotion.leap.*;
导入com.leapmotion.leap.signature.State;
导入java.io.IOException;
//听众
类LeapListener扩展了Listener{
公共无效onInit(控制器){
System.out.println(“已初始化”);
}
公用void onConnect(控制器){
System.out.println(“连接到运动传感器”);
控制器.启用手势(手势.类型.类型\u滑动);
控制器.启用手势(手势.类型.类型\u圆圈);
控制器.启用手势(手势.类型.类型\屏幕\点击);
控制器.启用手势(手势.类型.类型\按键\轻触);
}
公共无效断开连接(控制器){
System.out.println(“运动传感器断开”);
}
public void onExit(控制器){
System.out.println(“退出”);
}
//检测方法
公共void onFrame(控制器){
Frame=controller.Frame();
//帧数据始终
/*System.out.println(“帧id:+Frame.id()
+,时间戳:“+frame.Timestamp()
+,Hands:“+frame.Hands().count()
+,Fingers:“+frame.Fingers().count()
+,Tools:“+frame.Tools().count()
+,手势:“+frame.signals().count())*/
//检测到手时显示的手日期
/*for(Hand-Hand:frame.hands()){
字符串handType=hand.isLeft()?“左手”:“右手”;
System.out.println(handType++,id:“+hand.id()
+,手掌位置:“+hand.palmPosition());
向量法线=hand.palmNormal();
向量方向=手的方向();
System.out.println(“Pitch:+Math.toDegrees(direction.Pitch())
+“滚动:”+Math.toDegrees(normal.Roll())
+“偏航:”+数学。toDegrees(direction.Yaw());
}*/
//检测到手时显示的手指数据
/*对于(Finger-Finger:frame.fingers()){
System.out.println(“Finger类型:“+Finger.Type()
+ID:“+finger.ID()
+“手指长度(mm):“+手指长度()
+“手指宽度(mm):“+Finger.Width());
对于(Bone.Type boneType:Bone.Type.values()){
骨头=手指骨头(骨头类型);
System.out.println(“骨骼类型:+Bone.Type()
+“开始:”+bone.prevJoint()
+“结束:”+bone.nextJoint()
+方向:“+bone.Direction());
}
}*/
//刀具数据
/*对于(工具:frame.tools()){
System.out.println(“工具ID:+Tool.ID()
+“尖端位置:”+tool.tiposition()
+“方向:”+刀具方向()
+“宽度(mm):“+刀具宽度()
+“接触距离(mm):“+tool.touchDistance());
}*/
//姿态
手势列表手势=frame.signatures();
对于(int i=0;i