博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leap Motion C++开发笔记(一)下载安装及环境配置
阅读量:2439 次
发布时间:2019-05-10

本文共 7933 字,大约阅读时间需要 26 分钟。

下载安装

下载地址

tip安装的时候记住安装的路径,该安装包无法自定义安装,默认路径为系统盘\Program Files (x86)

点击exe安装完成之后,可以看到右下角状态栏里出现leap motion的小图标,绿色表示连接成功

这里写图片描述

tip如果出现绿色闪烁,可尝试着右键-观察器,查看有无图像生成。

安装完成之后,也可以尝试着打开SDK里的App Home,可以看到多款demo~


环境配置

1.配置系统的环境变量,如下添加

这里写图片描述

tip:这里要注意,尽管你的电脑是64位的,但由于软件的框架是x86的,所以还是要链接到x86的,同时环境变量配置完成后电脑要注销或重启,相关配置才会生效。


2.配置visual studio(2010,2012,2013)

首先建立空项目

右键项目属性,分别如下配置

这里写图片描述

这里写图片描述

至此配置完成


代码测试

官方所给环境测试代码

#include 
#include
#include "Leap.h"using namespace Leap;int main(int argc, char** argv) { std::cout << "Hello Leap motion!!!" << std::endl; // Keep this process running until Enter is pressed std::cout << "Press Enter to quit..." << std::endl; std::cin.get(); return 0;}

若环境配置无误,则如下图所示

这里写图片描述


功能测试代码

#include 
#include
#include "Leap.h" using namespace Leap;class SampleListener : public Listener {public: virtual void onInit(const Controller&); virtual void onConnect(const Controller&); virtual void onDisconnect(const Controller&); virtual void onExit(const Controller&); virtual void onFrame(const Controller&); virtual void onFocusGained(const Controller&); virtual void onFocusLost(const Controller&); virtual void onDeviceChange(const Controller&); virtual void onServiceConnect(const Controller&); virtual void onServiceDisconnect(const Controller&); virtual void onServiceChange(const Controller&); virtual void onDeviceFailure(const Controller&); virtual void onLogMessage(const Controller&, MessageSeverity severity, int64_t timestamp, const char* msg);};const std::string fingerNames[] = { "Thumb", "Index", "Middle", "Ring", "Pinky" };const std::string boneNames[] = { "Metacarpal", "Proximal", "Middle", "Distal" };void SampleListener::onInit(const Controller& controller) { std::cout << "Initialized" << std::endl;}void SampleListener::onConnect(const Controller& controller) { std::cout << "Connected" << std::endl;}void SampleListener::onDisconnect(const Controller& controller) { // Note: not dispatched when running in a debugger. std::cout << "Disconnected" << std::endl;}void SampleListener::onExit(const Controller& controller) { std::cout << "Exited" << std::endl;}void SampleListener::onFrame(const Controller& controller) { // Get the most recent frame and report some basic information const Frame frame = controller.frame(); std::cout << "Frame id: " << frame.id() << ", timestamp: " << frame.timestamp() << ", hands: " << frame.hands().count() << ", extended fingers: " << frame.fingers().extended().count() << std::endl; HandList hands = frame.hands(); for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) { // Get the first hand const Hand hand = *hl; std::string handType = hand.isLeft() ? "Left hand" : "Right hand"; std::cout << std::string(2, ' ') << handType << ", id: " << hand.id() << ", palm position: " << hand.palmPosition() << std::endl; // Get the hand's normal vector and direction const Vector normal = hand.palmNormal(); const Vector direction = hand.direction(); // Calculate the hand's pitch, roll, and yaw angles std::cout << std::string(2, ' ') << "pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, " << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, " << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl; // Get the Arm bone Arm arm = hand.arm(); /* std::cout << std::string(2, ' ') << "Arm direction: " << arm.direction() << " wrist position: " << arm.wristPosition() << " elbow position: " << arm.elbowPosition() << std::endl; */ // Get fingers const FingerList fingers = hand.fingers(); for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { const Finger finger = *fl; /* std::cout << std::string(4, ' ') << fingerNames[finger.type()] << " finger, id: " << finger.id() << ", length: " << finger.length() << "mm, width: " << finger.width() << std::endl; */ // Get finger bones for (int b = 0; b < 4; ++b) { Bone::Type boneType = static_cast
(b); Bone bone = finger.bone(boneType); /* std::cout << std::string(6, ' ') << boneNames[boneType] << " bone, start: " << bone.prevJoint() << ", end: " << bone.nextJoint() << ", direction: " << bone.direction() << std::endl; */ } } } if (!frame.hands().isEmpty()) { std::cout << std::endl; }}void SampleListener::onFocusGained(const Controller& controller) { std::cout << "Focus Gained" << std::endl;}void SampleListener::onFocusLost(const Controller& controller) { std::cout << "Focus Lost" << std::endl;}void SampleListener::onDeviceChange(const Controller& controller) { std::cout << "Device Changed" << std::endl; const DeviceList devices = controller.devices(); for (int i = 0; i < devices.count(); ++i) { std::cout << "id: " << devices[i].toString() << std::endl; std::cout << " isStreaming: " << (devices[i].isStreaming() ? "true" : "false") << std::endl; std::cout << " isSmudged:" << (devices[i].isSmudged() ? "true" : "false") << std::endl; std::cout << " isLightingBad:" << (devices[i].isLightingBad() ? "true" : "false") << std::endl; }}void SampleListener::onServiceConnect(const Controller& controller) { std::cout << "Service Connected" << std::endl;}void SampleListener::onServiceDisconnect(const Controller& controller) { std::cout << "Service Disconnected" << std::endl;}void SampleListener::onServiceChange(const Controller& controller) { std::cout << "Service Changed" << std::endl;}void SampleListener::onDeviceFailure(const Controller& controller) { std::cout << "Device Error" << std::endl; const Leap::FailedDeviceList devices = controller.failedDevices(); for (FailedDeviceList::const_iterator dl = devices.begin(); dl != devices.end(); ++dl) { const FailedDevice device = *dl; std::cout << " PNP ID:" << device.pnpId(); std::cout << " Failure type:" << device.failure(); }}void SampleListener::onLogMessage(const Controller&, MessageSeverity s, int64_t t, const char* msg) { switch (s) { case Leap::MESSAGE_CRITICAL: std::cout << "[Critical]"; break; case Leap::MESSAGE_WARNING: std::cout << "[Warning]"; break; case Leap::MESSAGE_INFORMATION: std::cout << "[Info]"; break; case Leap::MESSAGE_UNKNOWN: std::cout << "[Unknown]"; } std::cout << "[" << t << "] "; std::cout << msg << std::endl;}int main(int argc, char** argv) { // Create a sample listener and controller SampleListener listener; Controller controller; // Have the sample listener receive events from the controller controller.addListener(listener); if (argc > 1 && strcmp(argv[1], "--bg") == 0) controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES); controller.setPolicy(Leap::Controller::POLICY_ALLOW_PAUSE_RESUME); // Keep this process running until Enter is pressed std::cout << "Press Enter to quit, or enter 'p' to pause or unpause the service..." << std::endl; bool paused = false; while (true) { char c = std::cin.get(); if (c == 'p') { paused = !paused; controller.setPaused(paused); std::cin.get(); //skip the newline } else break; } // Remove the sample listener when done controller.removeListener(listener); return 0;}

运行后,在leap motion上伸出手,输出即有相应的反应。


几个常见的错误

1.leap motion程序运行后出现无法解析的外部错误

可能的原因:在配置时选择了x64,改为x86即可

2.leap motion程序运行编译无错,在结果页面出现报错提示

配置完环境变量后未重启或注销,环境变量未生效

你可能感兴趣的文章
双主+haproxy手工切换的一个注意点
查看>>
利用binlog2sql实现闪回
查看>>
mongos分片集群下db数量过多导致服务不可用
查看>>
故障处理--mongos count不准
查看>>
mongo3.0.9库命名的一个S级bug
查看>>
跨版本导入数据导致mysqld崩溃
查看>>
xtrabackup对于flush tables with read lock操作的设置
查看>>
Server has authorization schema version 3,but found a schema version 1 user
查看>>
WebSphere的池设置——线程池、连接池
查看>>
用户态调测工具(二):perror和man
查看>>
机器学习&深度学习入门历程
查看>>
LTP(Linux Test Project)学习(一)——LTP介绍
查看>>
LTP(Linux Test Project)学习(三)——LTP目录介绍
查看>>
DirtyCow CVE-2016-5195分析
查看>>
LTP(Linux Test Project)学习(七)——LTP提交补丁
查看>>
Linux 4.0亮点特性
查看>>
Linux 4.1亮点特性
查看>>
Linux 4.4亮点特性
查看>>
Linux 4.5 亮点特性
查看>>
Makefile开发工具学习小结
查看>>