Replace gesture library templates in android

Can I replace the gesture template in the template library from a running application? I am creating a handwriting recognition system that has letter patterns in a gesture file. So basically after loading the library inside the code, I compare the input user's gesture:

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList<Prediction> predictions = gesturelib.recognize(gesture); if (predictions.size() > 1) { for(Prediction prediction: predictions){ //i compare prediction name here and if matches print it in an edittext } 

This should work well until the user gives the same template as when creating the library template. But I want to give the user the opportunity to replace the template element with his handwritten drawing when there is a mismatch in the forecast.

Because below 2 handwritten gestures differ in pattern, but not as a letter. Suppose my system supports the 1st image template, I want, when the user gives the 2nd image template, the system will ask for confirmation from the user to replace this with library template A, and then replace it after confirmation. So next time, the system will recognize the user template much better.

Any help would be greatly appreciated.

enter image description hereenter image description here

+4
source share
2 answers

If I understand correctly, do you want to replace an existing gesture with a new one?

So, when a user enters a gesture that is not in the library, your application asks the user to choose which gesture they want to replace? From your question, I will assume that when the user draws a lowercase a (and if a not in the library), the user is presented with a list of all available gestures / letters that your application currently supports. Then the user selects capital a , and now capital a should be replaced by lowercase a . In the following code, oldGesture is the gesture corresponding to a . And newGesture - A gesture just drawn.

The process for this: delete the old gesture, add a new one using the old gesture name. To remove a gesture, use GestureLibrary.removeGesture (String, Gesture):

 public void onGesturePerformed(GestureOverlayView overlay, final Gesture gesture) { ArrayList<Prediction> predictions = gesturelib.recognize(gesture); if (predictions.size() > 1) { for(Prediction prediction: predictions){ if (prediction.score > ...) { } else { if (user wants to replace) { showListWithAllGestures(gesture); } } } } } public void showListWithAllGestures(Gesture newGesture) { .... .... // User picks a gesture Gesture oldGesture = userPickedItem.gesture; String gestureName = userPickedItem.name; // delete the gesture gesturelib.removeGesture(gestureName, oldGesture); gesturelib.save(); // add gesture gesturelib.addGesture(gestureName, newGesture); gesturelib.save(); } 

To get a list of all available gestures:

 // Wrapper to hold a gesture static class GestureHolder { String name; Gesture gesture; } 

Load gestures using GestureLibrary.load ():

 if (gesturelib.load()) { for (String name : gesturelib.getGestureEntries()) { for (Gesture gesture : gesturelib.getGestures(name)) { final GestureHolder gestureHolder = new GestureHolder(); gestureHolder.gesture = gesture; gestureHolder.name = name; // Add `gestureHolder` to a list } } // Return the list that holds GestureHolder objects } 

Edit:

Sorry, but the check that I suggested: if (wants to replace) is performed in the wrong place in the code.

 if (predictions.size() > 1) { // To check whether a match was found boolean gotAMatch = false; for(int i = 0; i < predictions.size() && !gotAMatch; i++){ if (prediction.score > ... ) { .... .... // Found a match, look no more gotAMatch = true; } } // If a match wasn't found, ask the user s/he wants to add it if (!gotAMatch) { if (user wants to replace) { showListWithAllGestures(gesture); } } } 
+5
source

you can see this link and maybe give me more info

How to send a file from Android to a computer via bluetooth

0
source

Source: https://habr.com/ru/post/1501557/


All Articles