android 手势数据库,AndroidStudio:手势识别

一内容:设计一个手写字体识别程序。

二实现

①建立一个存放手写字体的数据库

②activity_main.xml<?xml  version="1.0" encoding="utf-8"?>

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Gesture:"

android:id="@+id/tv"

android:textSize="24dp"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="20dp"

android:text="clear"

android:id="@+id/bt"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gestureStrokeType="multiple"

android:eventsInterceptionEnabled="false"

android:orientation="vertical"

android:id="@+id/gesture">

3.MainActivity.javapackage com.example.myapplication;

import android.gesture.Gesture;

import android.gesture.GestureLibraries;

import android.gesture.GestureLibrary;

import android.gesture.GestureOverlayView;

import android.gesture.Prediction;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements GestureOverlayView.OnGesturePerformedListener {

GestureLibrary mLibrary;  //定义手势库对象

GestureOverlayView gest;  //定义手势视图对象做画板之用

TextView txt;

Button bt;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

gest = (GestureOverlayView)findViewById(R.id.gesture);

gest.addOnGesturePerformedListener(this);  // 注册手势识别的监听器

txt = (TextView)findViewById(R.id.tv);

mLibrary = GestureLibraries.fromRawResource(this,R.raw.gestures);  //加载手势库

bt = (Button)findViewById(R.id.bt);

bt.setOnClickListener(new Click());

if (!mLibrary.load()) {

finish();

}

}

/*根据画的手势识别是否匹配手势库里的手势*/

@Override

public void onGesturePerformed(GestureOverlayView gest, Gesture gesture) {

ArrayList gestList = mLibrary.recognize(gesture);  // 从手势库获取手势数据

if (gestList.size() > 0) {

Prediction pred = (Prediction)gestList.get(0);

if (pred.score > 1.0) {    // 检索到匹配的手势

Toast.makeText(this,pred.name,Toast.LENGTH_SHORT).show();

txt.append(pred.name);

}

}

}

private class Click implements View.OnClickListener {

@Override

public void onClick(View view) {

txt.setText("Gesture:");

}

}

}

三效果

201905091557371622553826.jpg

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值