Leap提供了SDK。但是整合有很多的问题,写博客记录一下;

写一个类:SampleListener.cpp以及头文件SampleListener.h。

这里主要碰到的问题是找不到以及冲突问题;

这里最关键的是用的不能写using namespace Lead。必须写Lead::这种形式。

代码如下:

#include <iostream>
#include <cstring>
#include "Leap.h"
//using namespace Leap;
class SampleListener : public Leap::Listener {
public:
int civiv;//手机识别的标志
void onInit(const Leap:: Controller&);
void onConnect(const Leap::Controller&);
void onDisconnect(const Leap:: Controller&);
void onExit(const Leap:: Controller&);
void onFrame(const Leap:: Controller&);
void onFocusGained(const Leap:: Controller&);
void onFocusLost(const Leap::Controller&);
void onDeviceChange(const Leap:: Controller&);
void onServiceConnect(const Leap:: Controller&);
void onServiceDisconnect(const Leap:: Controller&);
void onStart(); private:
};

SampleListener.cpp:

#include "stdafx.h"
#include "SampleListener.h"
using namespace Leap; const std::string fingerNames[] = {"Thumb", "Index", "Middle", "Ring", "Pinky"};
const std::string boneNames[] = {"Metacarpal", "Proximal", "Middle", "Distal"};
const std::string stateNames[] = {"STATE_INVALID", "STATE_START", "STATE_UPDATE", "STATE_END"}; void SampleListener::onInit(const Leap::Controller& controller) {
std::cout << "Initialized" << std::endl;
} void SampleListener::onConnect(const Leap:: Controller& controller) {
std::cout << "Connected" << std::endl;
controller.enableGesture(Gesture::TYPE_CIRCLE);
controller.enableGesture(Gesture::TYPE_KEY_TAP);
controller.enableGesture(Gesture::TYPE_SCREEN_TAP);
controller.enableGesture(Gesture::TYPE_SWIPE);
} void SampleListener::onDisconnect(const Leap:: Controller& controller) {
// Note: not dispatched when running in a debugger.
std::cout << "Disconnected" << std::endl;
} void SampleListener::onExit(const Leap::Controller& controller) {
std::cout << "Exited" << std::endl;
} void SampleListener::onFrame(const Leap:: 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()
<< ", tools: " << frame.tools().count()
<< ", gestures: " << frame.gestures().count() << std::endl; Leap::HandList hands = frame.hands();
for ( Leap::HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
// Get the first hand
const Leap:: Hand hand = *hl;
std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
std::cout << std::string(, ' ') << handType << ", id: " << hand.id()
<< ", palm position: " << hand.palmPosition() << std::endl;
// Get the hand's normal vector and direction
const Leap::Vector normal = hand.palmNormal();
const Leap:: Vector direction = hand.direction(); // Calculate the hand's pitch, roll, and yaw angles
std::cout << std::string(, ' ') << "pitch: " << direction.pitch() * Leap::RAD_TO_DEG << " degrees, "
<< "roll: " << normal.roll() * Leap::RAD_TO_DEG << " degrees, "
<< "yaw: " << direction.yaw() * Leap:: RAD_TO_DEG << " degrees" << std::endl; // Get the Arm bone
Leap::Arm arm = hand.arm();
std::cout << std::string(, ' ') << "Arm direction: " << arm.direction()
<< " wrist position: " << arm.wristPosition()
<< " elbow position: " << arm.elbowPosition() << std::endl; // Get fingers
const Leap::FingerList fingers = hand.fingers();
for ( Leap::FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) { civiv=;
const Leap::Finger finger = *fl;
std::cout << std::string(, ' ') << fingerNames[finger.type()]
<< " finger, id: " << finger.id()
<< ", length: " << finger.length()
<< "mm, width: " << finger.width() << std::endl; // Get finger bones
for (int b = ; b < ; ++b) {
Leap::Bone::Type boneType = static_cast< Leap::Bone::Type>(b);
Leap::Bone bone = finger.bone(boneType);
std::cout << std::string(, ' ') << boneNames[boneType]
<< " bone, start: " << bone.prevJoint()
<< ", end: " << bone.nextJoint()
<< ", direction: " << bone.direction() << std::endl;
}
}
} // Get tools
const ToolList tools = frame.tools();
for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) { const Tool tool = *tl;
std::cout << std::string(, ' ') << "Tool, id: " << tool.id()
<< ", position: " << tool.tipPosition()
<< ", direction: " << tool.direction() << std::endl;
} // Get gestures
const GestureList gestures = frame.gestures();
for (int g = ; g < gestures.count(); ++g) {
Gesture gesture = gestures[g]; switch (gesture.type()) {
case Gesture::TYPE_CIRCLE:
{
CircleGesture circle = gesture;
std::string clockwiseness; if (circle.pointable().direction().angleTo(circle.normal()) <= PI/) {
clockwiseness = "clockwise";
} else {
clockwiseness = "counterclockwise";
} // Calculate angle swept since last frame
float sweptAngle = ;
if (circle.state() != Gesture::STATE_START) {
CircleGesture previousUpdate = CircleGesture(controller.frame().gesture(circle.id()));
sweptAngle = (circle.progress() - previousUpdate.progress()) * * PI;
}
/* std::cout << std::string(2, ' ')
<< "Circle id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
<< ", progress: " << circle.progress()
<< ", radius: " << circle.radius()
<< ", angle " << sweptAngle * RAD_TO_DEG
<< ", " << clockwiseness << std::endl;*/
break;
}
case Gesture::TYPE_SWIPE:
{
SwipeGesture swipe = gesture;
std::cout << std::string(, ' ')
<< "Swipe id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
<< ", direction: " << swipe.direction()
<< ", speed: " << swipe.speed() << std::endl;
break;
}
case Gesture::TYPE_KEY_TAP:
{
KeyTapGesture tap = gesture;
std::cout << std::string(, ' ')
<< "Key Tap id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
<< ", position: " << tap.position()
<< ", direction: " << tap.direction()<< std::endl;
break;
}
case Gesture::TYPE_SCREEN_TAP:
{
ScreenTapGesture screentap = gesture;
std::cout << std::string(, ' ')
<< "Screen Tap id: " << gesture.id()
<< ", state: " << stateNames[gesture.state()]
<< ", position: " << screentap.position()
<< ", direction: " << screentap.direction()<< std::endl;
break;
}
default:
std::cout << std::string(, ' ') << "Unknown gesture type." << std::endl;
break;
}
} if (!frame.hands().isEmpty() || !gestures.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 Leap::DeviceList devices = controller.devices(); for (int i = ; i < devices.count(); ++i) {
std::cout << "id: " << devices[i].toString() << std::endl;
std::cout << " isStreaming: " << (devices[i].isStreaming() ? "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::onStart()
{
// civiv=1;
// Create a sample listener and controller
SampleListener listener;
listener.civiv=;
Controller controller;
//controller.Config.SetFloat ("Gesture.Circle.MinRadius", 10.0f); .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
//................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................// controller.Config.SetFloat ("Gesture.Circle.MinArc", .5f);
// controller.config().setFloat("Gesture.Circle.MinRadius", 10.0f);
// controller.config().setFloat("Gesture.Circle.MinRadius", .5f); // 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); // Keep this process running until Enter is pressed // Remove the sample listener when done
controller.removeListener(listener); } /*int main(int argc, char** argv) {
// Create a sample listener and controller
SampleListener listener;
Controller controller;
//controller.Config.SetFloat ("Gesture.Circle.MinRadius", 10.0f);
// controller.Config.SetFloat ("Gesture.Circle.MinArc", .5f);
controller.config().setFloat("Gesture.Circle.MinRadius", 10.0f);
controller.config().setFloat("Gesture.Circle.MinRadius", .5f); // 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); // Keep this process running until Enter is pressed
std::cout << "Press Enter to quit..." << std::endl;
std::cin.get(); // Remove the sample listener when done
controller.removeListener(listener); return 0;
}
*/

嵌入师兄的MFC写的程序中:

注意因为与师兄写的变量冲突,所以这里不能写using namespace Lead。必须写Lead::这种形式。

EyeTrackView.h:

#include "TshirtCode.h"
#include "TshirtDraw.h"
#include "GeneticAlgorithm.cpp"
#include "CvvImage.h"
#include <deque>
#include "shockwaveflash1.h"
#include "pupilDetector.h"
#include "Device.h"
#include "communication.h"
#include "DeviceEyeDataAnalyze.h"
#include "HardWord.h"
#include "SampleListener.h"

EyeTrackView.cpp照常引入EyeTrackView.h。

研:手势与眼动相结合-手势SDK的整合的更多相关文章

  1. C#开发EyeLink眼动仪的实验程序

    [题外话] Eyelink眼动仪是SR Research推出的一款眼动仪,很多高校都在使用其做实验.其官方提供了COM的接口,所以支持COM接口的开发平台都可以开发使用.官方甚至提供了一个C#的样例供 ...

  2. 与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触控

    原文:与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触 ...

  3. 手势-webview与scrollView重复手势处理

    // called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocke ...

  4. 解决右滑返回手势和UIScrollView中的手势冲突

    当在一个viewController中添加了scrollView或者tableView的时候,贴边侧滑返回的时候会首先触发滚动而失效,要解决这个问题,需要通过requireGestureRecogni ...

  5. iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】

    转自:iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 关于手势的一篇很好的帖子,转载过来免得丢失.你可能最感兴趣的是手势间的互斥处理,那么就搜索 4.手势间的互斥处 ...

  6. 乐动ld06激光雷达sdk改bug记录分享

    前言: 工作中,有使用过乐动ld06款激光雷达,此款雷达将常规雷达的转动的电机部分内置于自己的保护罩内,减少了雷达本身转动积灰等其他外界影响,探测半径是12m,是一款不错的雷达. 不过今天的主要内容不 ...

  7. Kinect for Windows SDK v2.0 开发笔记 (十五) 手势帧

     (转载请注明出处) 使用SDK: Kinect for Windows SDK v2.0 public preview1409 同前面,由于SDK未完毕,不附上函数/方法/接口的超链接. 这次最 ...

  8. 手势识别(一)--手势基本概念和ChaLearn Gesture Challenge

    以下转自: http://blog.csdn.net/qq1175421841/article/details/50312565 像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的 ...

  9. RDVECore来自锐动的无UI,高度抽象化API的视频编辑SDK

    1 编写目的 预期读者: 有视频编辑开发经验或者无经验的,打算或者正在使用"锐动IOS版RDVECore"的相关工程师. iOS软件工程师. 产品经理. QA 2 名词解释 分辨率 ...

随机推荐

  1. web api 限制单个IP在一定时间内访问次数

    ps:下面实例是每隔30秒访问次数不超过3次 1.Filter: using Infrastructure.Log; using Infrastructure.Web; using Lemon.Sta ...

  2. SharePoint 2013 App Remote Event Receivers

    当我们在使用App的时候,就会发现一些问题,比如那些网站部署.更新或者卸载了,我们很关心我们的App是否有人用,这就需要远程事件接收器了. 1.在我们的测试App的解决方案上选中鼠标,按F4弹出属性, ...

  3. SPServices.SPDisplayRelatedInfo

    Function $().SPServices.SPDisplayRelatedInfo Certification Functionality SPDisplayRelatedInfo is a f ...

  4. SharePoint部署工具SPSD

    SharePoint Solution Deployer,绝对属于必备的SharePoint工具之一了. 下载,解压这个工具,会有如下的目录(没有Assemblies和DeployGAC.bat)解压 ...

  5. Bonobo Git Server (Simple git server for Windows.) 测试备忘

    Bonobo Git Server是一款Windows上的Git Server,它使用IIS即可,走的是Http协议,只要简单的安装就能使用,但是因为我的项目大小有1.35GB在 push 的时候一直 ...

  6. C语言内存对齐详解

    一.字节对齐基本概念 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这就需要各种类型 ...

  7. Android SDK Manager 在win8.1上的闪退问题

    全新安装的Windows 8.1的系统,Android SDK,JDK都是最新的版本,但是SDK Manager打开是命令行窗口一闪而过,就再没反映了. 通过搜索,确定了一个问题就是SDK目录tool ...

  8. Retrofit源码设计模式解析(下)

    本文将接着<Retrofit源码设计模式解析(上)>,继续分享以下设计模式在Retrofit中的应用: 适配器模式 策略模式 观察者模式 单例模式 原型模式 享元模式 一.适配器模式 在上 ...

  9. IOS开发中返回值为null时的处理

    在IOS开发中,如果得到了null返回值很容易造成程序崩溃,null和nil的判断方法不同. nil的判断方法: if(data==nil) {      NSLog(@"data is n ...

  10. IOS之UI--小实例项目--综合使用

    前言: 本博文是基于前一个小实例项目:IOS之UI--小实例项目--添加商品和商品名 进行继续综合学习积累的. 内容大纲 01-综合使用01-plist的使用 02-综合使用02-模型取代字典的好处分 ...