研:手势与眼动相结合-手势SDK的整合
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的整合的更多相关文章
- C#开发EyeLink眼动仪的实验程序
[题外话] Eyelink眼动仪是SR Research推出的一款眼动仪,很多高校都在使用其做实验.其官方提供了COM的接口,所以支持COM接口的开发平台都可以开发使用.官方甚至提供了一个C#的样例供 ...
- 与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触控
原文:与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触 ...
- 手势-webview与scrollView重复手势处理
// called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocke ...
- 解决右滑返回手势和UIScrollView中的手势冲突
当在一个viewController中添加了scrollView或者tableView的时候,贴边侧滑返回的时候会首先触发滚动而失效,要解决这个问题,需要通过requireGestureRecogni ...
- iOS手势UIGestureRecognizer的使用及手势冲突的解决办法【转】
转自:iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 关于手势的一篇很好的帖子,转载过来免得丢失.你可能最感兴趣的是手势间的互斥处理,那么就搜索 4.手势间的互斥处 ...
- 乐动ld06激光雷达sdk改bug记录分享
前言: 工作中,有使用过乐动ld06款激光雷达,此款雷达将常规雷达的转动的电机部分内置于自己的保护罩内,减少了雷达本身转动积灰等其他外界影响,探测半径是12m,是一款不错的雷达. 不过今天的主要内容不 ...
- Kinect for Windows SDK v2.0 开发笔记 (十五) 手势帧
(转载请注明出处) 使用SDK: Kinect for Windows SDK v2.0 public preview1409 同前面,由于SDK未完毕,不附上函数/方法/接口的超链接. 这次最 ...
- 手势识别(一)--手势基本概念和ChaLearn Gesture Challenge
以下转自: http://blog.csdn.net/qq1175421841/article/details/50312565 像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的 ...
- RDVECore来自锐动的无UI,高度抽象化API的视频编辑SDK
1 编写目的 预期读者: 有视频编辑开发经验或者无经验的,打算或者正在使用"锐动IOS版RDVECore"的相关工程师. iOS软件工程师. 产品经理. QA 2 名词解释 分辨率 ...
随机推荐
- arcgis python 更新顺序号
i = 0def myFun(): global i i=i +1 return i myFun() ========================== accumulate( ) total = ...
- 用doxygen+graphviz自动化生成代码文档(附详细教程)
一.引子 用这两个工具可以自动的遍历代码,并且产生代码文档,我们先来看看效果,然后放出这两个工具的下载地址. 二.工具的下载地址 doxygen:http://www.stack.nl/~dimitr ...
- IOS之--UI进阶--多控制器管理第一天
01-项目中常见的文件(LaunchScreen) Xcode5 框架是苹果事先已经导入进去的.在项目的结构当中就能够看到导入的框架. Xcode6 会自动导入一些觉见的框架.在项目结构当中,看不到已 ...
- APP国际化
1.app本地内容国际化 ①在项目中新建一个New File ---> iOS Resource -> String File ---> 命名为Localizable(之所以命名为L ...
- (ios)ARC常用设置,部分文件编译设置ARC
1设置 整个项目是否支持ARC 选择No 不支持 YES 支持 2 设置部分文件是否支持ARC. 支持ARC的Flags -fobjc-arc 不支持的Flags -fno-objc-arc
- java工程中的相关路径
一.路径 绝对路径: 指的是文件在系统中的真实路径(物理路径). 相对路径: 指的是文件相对某个目录的相对路径. 对于java application 工程来说,当编写完一个类之后,class文件会编 ...
- spring+mybatis多数据源切换
在实际的公司项目中,很可能会遇到一个问题就是,一个java项目,但是项目中涉及两个数据库,这两个数据库还在不同IP的机子上. 遇到这种情况的时候,我们有两个选择 1.不走spring的aop方式,直接 ...
- oracle缓存池使用解析
oracle有三种类型的缓存池,分别是default,keep和recycle.默认情况下只会使用default缓存池,另外两种需要额外配置. keep缓存池相当于是一直很热的default缓存池,缓 ...
- .NET 分页
.net分页 1.存储过程create procedure 存储过程名( @pageIndex int, //第几页 @pageSize int ...
- 烂泥:U盘安装Centos6.5
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 使用U盘安装Centos6.5,需要以下几个步骤: 1. 制作U盘linux系统 2. 设置服务器BIOS 3. 安装Centos,注意引导分区的安装 ...