研:手势与眼动相结合-手势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 名词解释 分辨率 ...
随机推荐
- MAC中安卓开发环境的下载(转)
今天终于为我的Macbook Pro Retina搭建好了Android开发环境,几经折磨,差点放弃了: 总结如下:1.最好选择ADT Bundle,这里面已经集成好了Eclipse.ADT.Andr ...
- iOS支付宝集成详细流程
实现支付宝支付的准备工作: 1.向支付宝签约,成为支付宝的商户 签约完成后,支付宝会提供一些必要的数据给我们 商户ID:partner 账号ID:seller 即支付宝账号 签约需要营业执照 2.获取 ...
- python 可变数据类型&不可变数据类型
在python中,数据类型分为可变数据类型和不可变数据类型,不可变数据类型包括string,int,float,tuple,可变数据类型包括list,dict. 所谓的可变与不可变,举例如下: > ...
- (转)Block的使用
转:http://my.oschina.net/leejan97/blog/268536 本文翻译自苹果的文档,有删减,也有添加自己的理解部分. 如果有Block语法不懂的,可以参考fuckingbl ...
- Effective Java 09 Always override hashCode when you override equals
Failure to do so will result in a violation of the general contract for Object.hashCode, which will ...
- Nodejs断言测试
var assert = require('assert');/*node中,我们可以使用assert模块来测试代码.equal()和notEqual()分别作相等性和不等性的判断,第一个参数是期望值 ...
- 堆栈 & Stack and Heap
What's the difference between a stack and a heap? The differences between the stack and the heap can ...
- C++ 第一个C++程序
#include <iostream> // C++自带的标准头文件都是没有.h的 // 就相当于C语言的<stdio.h> // 提前使用命名空间std using name ...
- FZU 1608 Huge Mission(线段树)
Problem 1608 Huge Mission Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Oaiei ...
- python类方法和静态方法
C++的静态方法是用static关键字,python j是没用static的. python中实现静态方法和类方法都是依赖于python的修饰器来实现的. class MyClass: def me ...