Leap Motion 开发——Ubuntu 16.04.02 LTS + Python 2.7: Hello World
来源:互联网 发布:学生数据字典 样例 编辑:程序博客网 时间:2024/04/24 00:55
System: Ubuntu 16.04.02
Leap Motion SDK: V2 Tracking
Codes: Python 2.7
下面简要介绍下在Ubuntu 16.04.02下用Python开发Leap Motion的基本方法。更多信息请参考官网文档。
第1步 下载安装V2 Tracking 工具包,地址在这。
第2步 在下载到的LeapSDK文件夹内,找到对应Python开发的相关模块、库文件:
- lib/Leap.py
- lib/x64/LeapPython.so
- lib/x64/libLeap.so
注意跟进你的系统选择相关的库文件,64位系统按照上述方式选择即可,32位系统注意选择x86文件夹下的相关文件。
第3步 构建工作空间。构建工作空间最简单的方式就是首先新建一个文件夹,例如:
mkdir leap_ws
随后将第2步中的相关文件复制到该文件夹下,并添加你的.py文件。
第4步 编写Hello World。官网提供了相关教程。
简述如下,新建一个名为Sample.py的文件,输入如下代码:
import sys, thread, timeimport Leapfrom Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesturedef main(): print "Press Enter to quit..." try: sys.stdin.readline() except KeyboardInterrupt: passif __name__ == "__main__": main()
代码内容此处不作具体解释。上述代码无实际意义,仅仅用来检查环境配置是否正确。
运行即可:
python Sample.py
第5步 运行leapd服务。使用Leap Motion的数据需要运行leapd服务,关于leapd服务的具体安装方法请参考安装配置Leap Motion SDK。具体操作方法如下:
用USB线连接Leap Motion, 启动leapd:
sudo service leapd start
查看服务状态:
sudo service leapd status
如果成功连接Leap Motion服务。则可以看到当前运行状态为active,并且有一个绿色的圆圈。下一步运行控制台:
LeapControlPanel
该控制台可以提供一些参数配置,若成功连接Leap Motion服务,则可以看到左上角的绿色灯亮起:
当然,如果你用完后想关闭Leap Motion 服务,运行:
sudo service leapd stop
如果连接工程中有异常,运行:
sudo service leapd restart
第6步 使用Leap Motion服务。若上述步骤无误,则修改上述代码:
import sys, thread, timeimport Leapfrom Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesturedef main(): controller = Leap.Controller() print "Press Enter to quit..." try: sys.stdin.readline() except KeyboardInterrupt: passif __name__ == "__main__": main()
其中controller对象用于连接Leap Motion硬件模块。此时连接好Leap Motion,运行上述代码。
无误后,继续添加代码:
import sys, thread, timeimport Leapfrom Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGestureclass SampleListener(Leap.Listener): def on_connect(self, controller): print "Connected" controller.enable_gesture(Leap.Gesture.TYPE_SWIPE) 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()))def main(): listener = SampleListener() controller = Leap.Controller() controller.add_listener(listener) print "Press Enter to quit..." try: sys.stdin.readline() except KeyboardInterrupt: pass finally: controller.remove_listener(listener)if __name__ == "__main__": main()
运行上述代码,别忘了连接Leap Motion模块,用手在其上方活动,此时可以观察到数据变化。
- Leap Motion 开发——Ubuntu 16.04.02 LTS + Python 2.7: Hello World
- Develop Leap Motion in Ubuntu 16.04.02 LTS: SDK install
- Qt 加载Leap motion 手势识别软件 二次开发 hello world
- Develop Leap Motion in ROS Kinetic: Hello World
- ubuntu 16.04安装使用leap motion
- 使用C++开发Leap Motion应用程序——Windows下开发环境配置
- python爬虫—hello world!
- Ubuntu 16.04下Intel SGX应用程序程序开发——打印Hello World!
- Ubuntu 16.04下Intel SGX应用程序程序开发——OCALL调用打印Hello World!
- Ubuntu入门——hello world
- Leap Motion Using Unity3D——环岛跑车篇
- leap motion
- Leap Motion
- Leap Motion
- Leap Motion开发第一步环境配置
- Python基础01——Hello World!
- Python 基础01—Hello World
- python基础教程学习笔记 — ‘Hello World’
- 命里有时终须有
- Arduino用esp8266WiFi模块连接到服务器
- Servlet&JSP 第九章 整合数据库
- 欢迎使用CSDN-markdown编辑器
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别
- Leap Motion 开发——Ubuntu 16.04.02 LTS + Python 2.7: Hello World
- java基础知识之多态
- JZ2440插入usbhub无法使用
- make(8)
- notifyDataSetChanged()无效原因
- JavaWeb开发知识总结(一)-(oracle_基础)
- rhel-exam2
- 最大流最小割定理
- 这是一道水题 UESTC