Leap Motion Controller(モーションセンサー) -性能テスト1-
Leap Motion Controllerのサンプルプログラムを用いて性能テストを実施!!
Leap Motion Controllerのサンプルプログラムを元に編集
モーションセンサーがどのくらいの感覚でデータを取得するのかを調べるコード
import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.lang.Math; import java.util.ArrayList; import java.util.List; import com.leapmotion.leap.*; import com.leapmotion.leap.Gesture.State; /** * リスナークラス */ class SampleListener extends Listener { public List<Frame> frameList = new ArrayList<Frame>(); /** * 初期化メソッド */ public void onInit(Controller controller) { System.out.println("Initialized"); } /** * Leap Motion Controllerに接続 */ public void onConnect(Controller controller) { System.out.println("Connected"); 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); } /** * Leap Motion Controllerの接続切断 */ public void onDisconnect(Controller controller) { // Note: not dispatched when running in a debugger. System.out.println("Disconnected"); } /** * Leap Motion Controller終了 */ public void onExit(Controller controller) { System.out.println("Exited"); } public void onFrame(Controller controller) { // Get the most recent frame and report some basic information Frame frame = controller.frame(); frameList.add(frame); } } class Sample { public static void main(String[] args) { // Create a sample listener and controller SampleListener listener = new SampleListener(); Controller controller = new Controller(); // Have the sample listener receive events from the controller controller.addListener(listener); // Keep this process running until Enter is pressed System.out.println("Press Enter to quit..."); try { //leap motion controller読み取り開始 System.in.read(); } catch (IOException e) { e.printStackTrace(); } // Remove the sample listener when done controller.removeListener(listener); // 取得した合計数 System.out.println(listener.frameList.size()); File file = new File("/Users/nagataryou/Documents/leapmotion.csv"); try (PrintWriter pw = new PrintWriter(new BufferedWriter( new FileWriter(file)));) { float time = 0; // 1/10^6秒 float oldTime = 0;// 1/10^6秒 for (Frame frame : listener.frameList) { time = frame.timestamp(); pw.println(frame.id() + "," + String.valueOf(time) +"," + String.valueOf(time - oldTime)); System.out.println(frame.id() + "," +String.valueOf(time) +"," + String.valueOf(time - oldTime)); oldTime = time; } pw.close(); } catch (IOException e) { e.printStackTrace(); } } }
出力結果
Initialized Press Enter to quit... Connected Exited 262 103870,1.19077437E10,1.19077437E10 103871,1.19077519E10,8192.0 103872,1.19077612E10,9216.0 103873,1.19077693E10,8192.0 103874,1.19077847E10,15360.0 103875,1.19078001E10,15360.0 103876,1.19078154E10,15360.0 103877,1.19078308E10,15360.0 103878,1.19078461E10,15360.0 103879,1.19078615E10,15360.0 103880,1.19078769E10,15360.0 103881,1.19078912E10,14336.0 103882,1.19079055E10,14336.0 103883,1.19079188E10,13312.0 103884,1.19079322E10,13312.0 103885,1.19079455E10,13312.0 103886,1.19079588E10,13312.0 103887,1.19079721E10,13312.0 103888,1.19079844E10,12288.0
平均すると0.13秒ごとに1回取得
調子がいい時だと0.1秒ごとに1回くらい
なので8fps(1秒間に8回取得)くらい
映画のコマ数が24fps、現在のテレビのコマが1秒に30fpsなのでスムーズとは言えない感じですね!
公式サイトの性能は平均120fpsとのことなのであれ!?って感じ
(今回はデータの書き出しとかは別途行っており、描画も行っていないので、、)
Javaは遅いってよく言うし、次はCかC++で性能確認してみようと思います。
何かアドバイスとかやってほしいことがある人はコメントとかください!