Experiment Record
Leap Motion 使用
1.环境配置
-
Mac
1)官方网站下载SDK for mac
2)python版本: 2.7(installed by homebrew)
3)更改动态链接路径
4)在lib/包下找到LeapPython.so ,在终端执行下面的命令 查看默认链接路径otool -L LeapPython.so
5)替换动态链接命令
install_name_tool -change old new LeapPython.so
我自己的路径,每个人不一样的,但是最后的文件都是 libpython2.7.dylib,因为LeapPython.so要加载这个链接库,否则会报错。
old :/library/.../..../...
new:/usr/local/Cellar/python@2/2.7.16_1/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
测试代码(或者使用sdk中提供的sample.py也ok)
import os, sys, inspect, thread, time
src_dir = os.path.dirname(inspect.getfile(inspect.currentframe()))
arch_dir = '../lib/x64' if sys.maxsize > 2**32 else '../lib/x86'
sys.path.insert(0, os.path.abspath(os.path.join(src_dir, arch_dir)))
import Leap
class SampleListener(Leap.Listener):
def on_connect(self, controller):
print "Connected"def main():
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()
# Have the sample listener receive events from the controller
controller.add_listener(listener)
# Keep this process running until Enter is pressed
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()
- Windows
1)从官方网站上下载SDK包
2)python版本:2.7
3)将在sample文件夹下的sample.py leap.py leap.pyc 移动到x64文件夹下
4)在命令行执行sample.py
5)成功
2.代码
取得控制器连接、添加监听
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()
# Have the sample listener receive events from the controller
controller.add_listener(listener)
初始化监听
def on_init(self, controller):
print "Initialized"
连接监听
def on_connect(self, controller):
print "Connected"
取得当前帧,获取当前frame手部数据
def on_frame(self, controller):
# Get the most recent frame and report some basic information
frame = controller.frame()
可从frame中获得的数据
frame.id
handType hand.id hand.palm_position
hand.palm_normal//法向量 hand.direction//方向向量
LeapMotion 坐标系
Pitch: direction.pitch * Leap.RAD_TO_DEG //x轴旋转
Roll: normal.roll * Leap.RAD_TO_DEG //z轴旋转
Yaw: direction.yaw * Leap.RAD_TO_DEG//y轴旋转
手臂、手腕、手肘:hand.arm arm.direction arm.elbow_position arm.wrist_position
手指://'Thumb', 'Index', 'Middle', 'Ring', 'Pinky'
hand.finger finger_names[finger.type] finger.id finger.length finger.width
bone://'Metacarpal', 'Proximal', 'Intermediate', 'Distal'
粗 =>细 拇指3个 其他手指4个
finger.bone bone_names[bone.type] bone.prev_joint bone.next_joint bone.direction