手势保存了就可以开始识别了。
// 从资源文件中将手势库加载进来
if (mGre == null) {
Log.e("", "手势");
mGre = GestureLibraries.fromRawResource(this, R.raw.yl_yl);
// 无此句出错
mGre.load();
}
// 从xml中取出GestureOverlayView控件
mGov = (GestureOverlayView) findViewById(R.id.gesture);
mGov.setGestureColor(Color.BLACK);// 手势颜色
mGov.setGestureStrokeWidth(15);// 手势宽度
// 为GestureOverlayView控件添加监听
mGov.addOnGesturePerformedListener(this);
开始识别:
// 识别手势,返回一个类型为Prediction的列表
ArrayList<Prediction> gestureList = mGre.recognize(gesture);
if (gestureList.size() > 0) {
Prediction pd = gestureList.get(0);
// 如果匹配度大于1,表示可以识别,否则提示无法识别
if (pd.score > 3) {
// 判断名字是否与手势库的名字相同
if (pd.name.equals("勾")) {
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);
startActivity(intent);
Toast.makeText(MainActivity.this, "已识别", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(MainActivity.this, "名字不匹配",
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, "无法识别", Toast.LENGTH_SHORT)
.show();
}
}
最后别忘了解绑监听:
protected void onDestroy() {
mGov.removeOnGesturePerformedListener(this);
super.onDestroy();
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。