我正在用 Java 为 Leap 开发自定义手势创建应用程序。在 onFrame 函数中,代码被执行到某个点,其余代码被跳过。
onFrame 的代码如下:
public void onFrame(Controller controller) {
Frame frame = controller.frame();
if (recordableFrame(frame, minRecordingVelocity)){
/*
* If this is the first frame in a gesture, we clean up some running values
*/
if (!recording) {
recording = true;
frameCount = 0;
}
frameCount++;
System.out.println("in frame... " + Integer.toString(frameCount));
recordFrame(frame);
System.out.println("Recording Frame...");
}
}
一切正常,直到调用“recordFrame(frame) 函数。此函数和此函数之后 onFrame 中的任何代码都被忽略/未执行。我似乎没有跳帧,而是在跳过代码。
recordFrame的代码如下:
/**
* This function is called for each frame during gesture recording,
* and it is responsible for adding values in frames using the provided
* recordPoint function (which accepts a Vector).
*/
public void recordFrame(Frame frame) {
HandList hands = frame.hands();
int handCount = hands.count();
Hand hand;
Finger finger;
FingerList fingers;
int fingerCount;
int l = handCount;
for (int i = 0; i < l; i++) { //for each hand in the frame
hand = hands.get(i);
recordPoint(hand.stabilizedPalmPosition()); //record the palm position
fingers = hand.fingers();
fingerCount = fingers.count();
int k = fingerCount;
for (int j = 0; j < k; j++) { //for each finger in the hand
finger = fingers.get(j);
recordPoint(finger.stabilizedTipPosition();//record fingertip position.
}
}
System.out.println("Recording Frame...");
}
最佳答案
来自 Leap Motion 论坛:
“我发现了这个问题。在手势类中我声明了 ArrayList 但从未使用 = new ArrayList(); 初始化它(很奇怪它没有抛出编译器错误)
完成后一切正常。我现在已经让它工作并运行了。”
https://community.leapmotion.com/t/listener-onframe-is-skipping-code/3108/7
关于java - Leap Motion Listener onFrame 正在跳过/忽略代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31391392/