cocos2d-x引擎实现$1Unistroke Recognizer手势识别

$1 Unistroke(单笔画) Recognizer官网

http://depts.washington.edu/aimgroup/proj/dollar/

(在官网还有多笔画的识别库)

代码下载

http://depts.washington.edu/aimgroup/proj/dollar/others/cpp.bw.zip

下载代码包括:

GeometricRecognizer.h

GeometricRecognizer.cpp

GemetricRecognizerTypes.h

GestureTemplate.h

PathWriter.h

SamplesGestures.h

使用示例:

1.你的Layer需要实现以下两个方法

virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);

2.初始化GeometricRecognizer来加载你的手势模板

private:

GeometricRecognizer* g_rGemertricRecognizer;

//加载模板

rGemertricRecognizer=new GeometricRecognizer;
rGemertricRecognizer->loadTemplates();

3.记录触摸操作(玩家在手机上所做手势的路径)

//声明一个坐标集合

private:

Path2D p_2dPath;

//Layer的ccTouchesMoved方法中记录坐标

CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);

CCPoint location = touch->locationInView(touch->view()));
Point2D p_Point2DTemp;
Point2DTemp.x=location.x;
Point2DTemp.y=location.y;

//记录
p_2dPath.push_back(Point2DTemp);

4.通过GeometricRecognizer校准

//Layer的ccTouchesEnded方法中, 下面屏蔽玩家单击操作

if (p_2dPath.size() < 1){
  return ;
}

RecognitionResult result = GemertricRecognizer->recognize(path2d);

//RecognitionResult 结果

class RecognitionResult
{
public:
string name;
double score;
RecognitionResult(string name, double score)
{
this->name = name;
this->score = score;
}
};

//这个类会保存你的自定义的模板名称(name未找到会回返回Unknown)和相似度(score 0.0-1.0)

原文地址:https://www.cnblogs.com/yssgyw/p/3456125.html