手势控制 Python !Leap Motion Python 开发教程 (一)
标题手势控制 Python !Leap Motion Python 开发教程
最近需要使用 Leap Motion 控制机械灵巧手,所以在 Python 的平台上做了一些 Leap Motion 的开发,现在整理一下发出来喽
有兴趣的同学可以浏览一下 Leap Motion 开发者官网 哦
一,配置环境
Leap Motion 的开发者官方指出目前的开发文件最高只支持 Python 2.7, 所以使用更高版本的小伙伴们需要新添加一个虚拟环境哦。
如果你已经有一个 Python2.7 版本的环境,可以省略步骤 A
A. 配置虚拟Python环境
由于本人是在windows 上用 Anaconda 配置的环境,所有我直接在 Anaconda 的命令行里输入了以下代码创建了一个新的名为 “py27” 的 Python 2.7 虚拟环境
#以下代码创建环境
conda create --name py27 python=2.7
#创建完后切换到新创建的环境
conda activate py27
B. 下载 Leap Motion 的开发库
想要开发一个 Leap Motion 控制器,必须按照以下顺序满足这些条件
所以大家先去 SDK官方下载链接. 下载自己的系统所需的版本,至于v2还是v4,应该无所谓。如果下载不了,评论里和我说,我会把我自己下载的SDK上传过来。
官方最新的SDK里应该包含的lib文件在更新SDK后消失了!但是这里作者自己找到了需要包括的文件,放这里了,直接下载就行!(csdn下载链接)
C. 配置项目目录
请遵循以下步骤
- 在你的 Python 根目录创建一个名为 lib 的文件夹
- 解压打开从本文下载的LeapSDK文件(注意是本文下载的,官方的缺少文件)
- 遵循下面这张图,将你的系统所需要的文件复制进Python 目录下的lib文件夹
64 位系统用x64,32位系统用x86
复制完文件后你的项目下的lib文件夹应该类似以下 (本人使用的windows 64位)
- 在你需要运行的 Python 文件的第一行写入以下代码
import sys
sys.path.insert(0, "lib")
import Leap
- 然后运行,我们就成功地 import 了 Leap 库!赶紧运行以下测试代码试试看吧
D. 测试代码
################################################################################
# Copyright (C) 2012-2016 Leap Motion, Inc. All rights reserved. #
# Leap Motion proprietary and confidential. Not for distribution. #
# Use subject to the terms of the Leap Motion SDK Agreement available at #
# https://developer.leapmotion.com/sdk_agreement, or another agreement #
# between Leap Motion and you, your company or other organization. #
################################################################################import Leap, sys, thread, timeclass SampleListener(Leap.Listener):finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']def on_init(self, controller):print "Initialized"def on_connect(self, controller):print "Connected"def on_disconnect(self, controller):# Note: not dispatched when running in a debugger.print "Disconnected"def on_exit(self, controller):print "Exited"def on_frame(self, controller):# Get the most recent frame and report some basic informationframe = controller.frame()print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d" % (frame.id, frame.timestamp, len(frame.hands), len(frame.fingers))# Get handsfor hand in frame.hands:handType = "Left hand" if hand.is_left else "Right hand"print " %s, id %d, position: %s" % (handType, hand.id, hand.palm_position)# Get the hand's normal vector and directionnormal = hand.palm_normaldirection = hand.direction# Calculate the hand's pitch, roll, and yaw anglesprint " pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % (direction.pitch * Leap.RAD_TO_DEG,normal.roll * Leap.RAD_TO_DEG,direction.yaw * Leap.RAD_TO_DEG)# Get arm bonearm = hand.armprint " Arm direction: %s, wrist position: %s, elbow position: %s" % (arm.direction,arm.wrist_position,arm.elbow_position)# Get fingersfor finger in hand.fingers:print " %s finger, id: %d, length: %fmm, width: %fmm" % (self.finger_names[finger.type],finger.id,finger.length,finger.width)# Get bonesfor b in range(0, 4):bone = finger.bone(b)print " Bone: %s, start: %s, end: %s, direction: %s" % (self.bone_names[bone.type],bone.prev_joint,bone.next_joint,bone.direction)if not frame.hands.is_empty:print ""def main():# Create a sample listener and controllerlistener = SampleListener()controller = Leap.Controller()# Have the sample listener receive events from the controllercontroller.add_listener(listener)# Keep this process running until Enter is pressedprint "Press Enter to quit..."try:sys.stdin.readline()except KeyboardInterrupt:passfinally:# Remove the sample listener when donecontroller.remove_listener(listener)if __name__ == "__main__":main()
如果大家看完之后还有问题或者配置过程中出现问题的话欢迎在下方评论或者联系我哦,接下来还会更新开发Leap Motion过程中总结的一些经验作为第二部分,敬请期待!
手势控制 Python !Leap Motion Python 开发教程 (一)相关推荐
- Win10+Python+Django+Nginx+MySQL开发教程及实例(1)——开发环境搭建
Win10+Python+Django+Nginx+MySQL开发教程及实例 PaulTsao 本教程共有三篇内容: 第一篇:Win10+Python+Django+Nginx+MySQL 开发环境搭 ...
- Win10+Python+Django+Nginx+MySQL开发教程及实例(2)——Python连通操作MySQL
Win10+Python+Django+Nginx+MySQL开发教程及实例 PaulTsao 本系列教程共有四篇内容: 第一篇: 开发环境搭建 第二篇:用Python连通操作MySQL 第三篇:用N ...
- nginx mysql 网页显示_Win10+Python+Django+Nginx+MySQL开发教程及实例(3)——Nginx运行html网页...
Win10+Python+Django+Nginx+MySQL开发教程及实例 PaulTsao 本教程共有三篇内容: 第四篇*:创建个人博客 第五篇*:个人博客网站上云部署并运行 第三篇:Win10+ ...
- python微信公众号开发教程_python微信公众号开发简单流程实现
本文为大家分享了python微信公众号开发的简单过程,供大家参考,具体内容如下 网上有很多微信公众号的开发教程,但是都是好几年前的了,而且很多都是抄袭其他人的,内容几乎一模一样.真的无语了.只好自己总 ...
- 【机器视觉案例】(9) AI视觉,手势控制电脑键盘,附python完整代码
各位同学好,今天和大家分享一下如何使用 opencv+mediapipe 完成远程手势控制电脑键盘.感兴趣的可以看一下我前面一篇手势控制电脑鼠标:https://blog.csdn.net/dgvv4 ...
- 使用Leap Motion Orion开发酷炫的手势识别VR/AR应用
Leap Motion Orien支持Oculus和HTC Vive开发,当然对Unity的支持显然是必须的. 不过前提是: 1.Windows 7 64位或者windows 10 2.Leap Mo ...
- python连接微信接口开发教程_Python调用微信公众平台接口操作示例
本文实例讲述了Python调用微信公众平台接口操作.分享给大家供大家参考,具体如下: 这里使用的是Django,其他类似 # coding=utf-8 from django.http import ...
- python链接微信接口开发教程_Python调用微信公众平台接口操作示例
本文实例讲述了Python调用微信公众平台接口操作.分享给大家供大家参考,具体如下: 这里使用的是Django,其他类似 # coding=utf-8 from django.http import ...
- python编程第一程序_第一个Python程序_Python编程开发教程
第一个Python程序 用notepad++编写程序代码 语言设置为python(高量显示函数和关键字)(注意:行首不能有空格,Python对缩进要求严格) 命令提示符运行 cd \文件名 #打开py ...
最新文章
- [我的1024开源程序]60元写的宠物网页和音乐网页
- ESP8266在Alios-Things上的入门开发指南 (一)开发环境搭建及HelloWorld固件
- 用Python开始机器学习(4:KNN分类算法)
- 基于JAVA+SpringMVC+Mybatis+MYSQL的心理咨询预约系统
- Adobe reader 在打开时如何恢复上一次阅读位置
- Oracle 10g OCP 官方培训
- 护卫神 mysql 升级_护卫神php套件 php版本升级方法
- 将微信数据提取为exel表格(2022年版)免root 保姆级教程
- 固高运动控制器,c#代码,支持gt400/800
- Axure RP 8 最新注册码
- 数据到物联网服务器作用,物联网数据分析是什么?物联网数据分析如何操作?...
- HTML姓名转为拼音,EXCEL如何自动将姓名转换为拼音?
- 手机投屏到电视的5种方法 看完才知道原来这么简单!
- Java环境配置 win10教程
- Python读取CSV文件,并进行数据可视化绘图
- 外星文明 未来计算机,科学家有望未来在地球“设计打印”外星生命
- c++ 向量化_一种新的FIR滤波器系数量化方法
- CCNA学习笔记#01
- Android开发快速入门及导出apk
- android手机自带软件,为什么安卓手机的预装软件这么多