4

Is it possible to replace a gesture template of template library from a running application? I am building a handwriting recognizer system in which there are templates of letters in gesture library file.So basically after loading the library inside the code i compare user input gesture like:

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 good until user will give the same pattern like i did during building the library template.But i want to give an user that flexibility to replace an template item with his handwritten pattern when there is a mismatch of prediction.

Because below 2 handwritten gesture samples are different in terms of pattern,but not as a letter.Suppose,my system supports the 1st image pattern,i want when user will give 2nd image pattern the system will ask confirmation from user to replace it with the library pattern of A and then replace it after confirm.So next time the system will recognize user pattern much better.

Any help would be greatly appreciated.

enter image description here enter image description here

ridoy
  • 6,274
  • 2
  • 29
  • 60

1 Answers1

5

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

So, when the user inputs a gesture that isn't in the library, your app asks the user to select which gesture they wish to replace? From your question, I will assume that when user draws a lowercase a(and if a isn't in the library), user is presented with a list of all available gestures/letters that your app currently supports. And then, the user selects capital A, and now, capital A must be replaced with lowercase a. In the following code, oldGesture is the Gesture corresponding to A. And newGesture is the Gesture just drawn.

The process for that would be: delete the old gesture, add the new one using old gesture's name. To delete 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 I have suggested: if (wants to replace) is being carried out at the wrong place in 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);
        }
    }
}
Vikram
  • 51,313
  • 11
  • 93
  • 122
  • Thanks for your response,i will inform you later whether it works or not. – ridoy Sep 14 '13 at 10:19
  • Can you plz explain if (user wants to replace) condition? because that else occurs for every n-1 cases.Let me explain, if i have 6 templates and draw only 1 template,then 1st if(prediction.score >1.0) catch that template and then else condition happens true for other 5 templates.How can it be managed? – ridoy Sep 19 '13 at 15:41
  • @ridoy Please give me a few minutes to answer your question. – Vikram Sep 19 '13 at 20:52
  • @ridoy I think my `if (user wants to replace)` check is happening at the wrong place. Please check my edit above. – Vikram Sep 19 '13 at 21:05
  • your solution looks promising so what i awarded you the bounty,but as i still not implemented it,so hope you will help me if i face any problem after ending the bounty period,after solving it i will accept your answer if it will do the trick.Because only points couldn't be a programmer's choice,:) – ridoy Sep 20 '13 at 06:38
  • @ridoy All you have to do is: leave me a comment on this question. I will help you the best I can. And if the answer I have already given works fine, please leave a line here. :) – Vikram Sep 20 '13 at 06:44