#DEV/Python
需要安装好Leapmotion SDK (windows or Mac)都行已经下载好了leapJSPython3pip3 install websockets werbsockets_server这个网页的作用就是将Leapmotion识别到的数据Debug出来。然后通过websocket发送到使用Python建立的服务器上面。
<html> <head> <title>Dumper - Leap</title> <script src="../leap-0.6.4.js"></script> <script> var paused = false; //自己服务器地址,也可以是树莓派的地址 var wsServer = 'ws://localhost:5678'; var websocket = new WebSocket(wsServer); //创建WebSocket对象 window.onkeypress = function(e) { if (e.charCode == 32) { if (paused == false) { paused = true; } else { paused = false; } } }; var yaw = 0 var controller = new Leap.Controller({enableGestures: true}); controller.loop(function(frame) { latestFrame = frame; if (paused) { document.getElementById('pause').innerHTML = "<strong>PAUSED</strong>"; return; } var str = ""; for (var i in frame.handsMap) { var hand = frame.handsMap[i]; yaw = hand.yaw(); str += "<p>" + "<strong>Roll:</strong> " + hand.roll() + "<br/><strong>Pitch:</strong> " + hand.pitch() + "<br/><strong>Yaw:</strong> " + hand.yaw() + "</p>"; } console.log(str); document.getElementById('yaw').innerHTML = yaw; //document.getElementById('out').innerHTML = str; // document.getElementById('yaw').innerHTML = yaw; }); setInterval(function(){ //websocket.send()是将yaw数据发送到服务器上 websocket.send(yaw) },500) </script> </head> <body> <div id="pause"></div> <div id="out"></div> <div id='yaw'></div> </body> </html>