您的位置:首页 > 编程语言 > Python开发

在window7下,在pycharm中,编写python程序,和leapmotion交互

2017-12-11 14:39 429 查看

在window7下,在pycharm中,编写python程序,和leapmotion交互

相关参考连接:

https://github.com/changkun/LeapDocCN/blob/master/python/devguide/Sample_Tutorial.md#%E8%AE%BE%E7%BD%AE%E6%96%87%E4%BB%B6

找到Leapmotion的SDK,将lib下的leap.py复制到pycharm工程中



将lib中的X64下面的leapPython.pyd和leap.dll复制到pycharm工程下



在day01目录下,新建test01.py文件



#coding=utf-8
import Leap
import sys
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture

class SampleListener(Leap.Listener):
def on_connect(self, controller):
#在你的应用程序中使用手势之前,你必须确保你要用的每一个手势都能够被识别。
#你需要使用 Controller 类中的 enableGesture() 方法使你想用的手势被识别到。
controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
print "Connected"

def on_frame(self, controller):
frame = controller.frame()

print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" \
% ( frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures()))

4000
def main():
# 创建 listener 和 controller
listener = SampleListener()
controller = Leap.Controller()

# 对 controller 添加 listener 事件
controller.add_listener(listener)

# 结束时移除 listener
print "Press Enter to quit..."
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
# Remove the sample listener when done
controller.remove_listener(listener)

if __name__ == "__main__":
main()


将lepamotion_Project工程设置为资源根,将day01设置为来源根

开启leapmotion,运行test01.py程序,结果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: