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. Mybatis学习记录(七)----Mybatis查询缓存

    1. 什么是查询缓存 mybatis提供查询缓存,用于减轻数据压力,提高数据库性能. mybaits提供一级缓存,和二级缓存. 一级缓存是SqlSession级别的缓存.在操作数据库时需要构造 sql ...

  2. SAP ST05数据跟踪使用

    有时我们想知道SAP操作,对数据库中的那些表进行的增删查改. 可以使用ST05跟踪SQL语句. ST05功能界面如下: 1---激活跟踪 2---结束跟踪 3---显示跟踪结果. 如果想跟踪SQL语句 ...

  3. Windows环境下利用github快速配置git环境

    在windows环境下利用github客户端我们可以直接拥有可视化的界面来管理工程,当然你也可以选择你喜欢的命令行工具来做.今天我分享一个比较快速的方式来配置git环境. 先去下载github的win ...

  4. 【读书笔记】iOS-编码对象

    Cocoa具备一种机制来将对象自身转换为某种格式并保存到磁盘中.对象可以将它们的实例变量和其他数据编码为数据块,然后保存到磁盘中.以后将这些数据块读回到内存中,并且还能基于保存的数据创建新对象.这个过 ...

  5. iOS 学习 - 7.限制 TextField 输入字符长度

    #pragma mark -- TextField代理 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: ...

  6. C语言的判断语句

    // // main.c // homeWork1222 //// #include <stdio.h> int main(int argc, const char * argv[]) { ...

  7. Android 网络编程基础之简单聊天程序

    前一篇讲了Android的网络编程基础,今天写了一个简单的聊天程序分享一下 首先是服务端代码: package com.jiao.socketdemo; import java.io.Buffered ...

  8. nodejs socket

    server.js var net = require('net'); var clientList = []; var HOST = '127.0.0.1'; var PORT = 6969; va ...

  9. Silverlight项目笔记1:UI控件与布局、MVVM、数据绑定、await/async、Linq查询、WCF RIA Services、序列化、委托与事件

    最近从技术支持转到开发岗,做Silverlight部分的开发,用的Prism+MVVM,框架由同事搭好,目前做的主要是功能实现,用到了一些东西,侧重于如何使用,总结如下 1.UI控件与布局 常用的主要 ...

  10. LeetCode 7 Reverse Integer(反转数字)

    题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...