General questions

Answered

Inconsistent Interpretation With MyScript SDK

Please I am trying to Integrate the MyScript SDK with a smart Pen (Neo Smart Pen to be precise) the smart Pen Send Stroke Representation of what has been written and I convert those strokes to pointers and send to the Editor but my problem is that unlike the way MyScript works with the Official NeoNotes Pen, The Interpretation for my own app is inconsistent, sometimes it interprets correctly while most of the times it just gives me: *...  as the Interpretation no errors showing I have gone through my codes below many times please I need assist Below is the code:

   

                    engine = IInkApplication.getEngine();
                    // Configure recognition
                    Configuration conf = engine.getConfiguration();
                    String confDir = "zip://" + getPackageCodePath() + "!/assets/conf";

                    conf.setStringArray("configuration-manager.search-path", new String[]{confDir});
                    conf.setString("content-package.temp-folder", getFilesDir().getPath() + File.separator + "tmp");
                    conf.setString("lang", language);
                    // Configure the engine to disable guides (recommended)
                    conf.setBoolean("text.guides.enable", false);

                    // Create a renderer with a null render target
                    displayMetrics = getResources().getDisplayMetrics();
                    Renderer renderer = engine.createRenderer(displayMetrics.xdpi, displayMetrics.ydpi, null);

                    // Create the editor
                    editor = engine.createEditor(renderer);

                    // The editor requires a font metrics provider and a view size *before* calling setPart()
                    editor.setFontMetricsProvider(null);
                    editor.setViewSize(displayMetrics.widthPixels, displayMetrics.heightPixels);

                    try {
                        // Create a new package
                        contentPackage = engine.createPackage(packageName);

                        // Create a new part
                        contentPart = contentPackage.createPart(partType);
                    } catch (IOException e) {
                        Log.e(TAG, "Failed to open package \"" + packageName + "\"", e);
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, "Failed to open package \"" + packageName + "\"", e);
                    }
                    // Associate editor with the new part
                    editor.setPart(contentPart);



                    EditText mEdit = findViewById(R.id.display);
                    String text = mDataSource.getValue(editor,c);
                    if(!text.equals("")){
                        mEdit.setText(text);
                    } else{
                        mEdit.setText("Value Not found");
                    }
                    mEdit = null;
                    editor.setPart(null);
                    contentPart.close();
                    contentPackage.close();
                    try {
                        engine.deletePackage(packageName);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    engine = null;

  Below is the Get value method of the DataSource Object that get the strokes from the database


 

    public String getValue(Editor editor,Context c) {
//        Define Cursor and get all Strokes From Database
        Cursor cursor = null;
        cursor = mDatabase.query(StrokesTable.TABLE_STROKES, StrokesTable.ALL_COLUMNS,
                null, null, null, null, null);

//        The Engine Editor Accepts PointerArray so we will frist create an Arraylist then after Looping Extensively
//        Through The Database, we will convert the ArrayList to an Array and feed the Editor
        ArrayList<PointerEvent> arrayListPointerEvents = new ArrayList<PointerEvent>();
        PointerType mPointerType = PEN;
        int id =1;
        while (cursor.moveToNext()) {
            Stroke s = getStroke(cursor);//Get Stroke methods decode the Stroke from the database to the way its supposed to be
                for (int i = 0; i < s.size(); i++) {
                    Log.d(TAG,"New Dot");
                    PointerEvent pointerEvent = new PointerEvent();
                    pointerEvent.pointerType = mPointerType;
//                    pointerEvent.pointerId = 1;// We set all pointerId to 1
                    pointerEvent.pointerId = id;// We set all pointerId to 1

                    // We assign either DOWN,UP Or MOVE Pointer Event Types to each pointer depending on the Dots
                    if (i == 0) {
                        pointerEvent.eventType = PointerEventType.DOWN;
                        Log.d(TAG,"PenDown");
                    } else if (i == s.size() - 1) {
                        pointerEvent.eventType = PointerEventType.UP;
                        Log.d(TAG,"PenUp");
                    } else {
                        pointerEvent.eventType = PointerEventType.MOVE;
                        Log.d(TAG,"PenMove");
                    }
                    pointerEvent.x = s.get(i).x;
                    pointerEvent.y = s.get(i).y;

                    pointerEvent.t = s.get(i).timestamp;
                    pointerEvent.f = s.get(i).pressure;
                    arrayListPointerEvents.add(pointerEvent);
                    pointerEvent=null;
                }
                id++;
                Log.d(TAG,"End Of Stroke");

//                We Assume The Stoke wont be used again after being worked on so we delete it from the database to avoid over population of it
                int strokeId = cursor.getInt(cursor.getColumnIndex(StrokesTable._ID));
//                mDatabase.delete(StrokesTable.TABLE_STROKES, StrokesTable._ID + "=" + strokeId, null);

            s=null;
        }
        PointerEvent[] arrayPointerEvents = arrayListPointerEvents.toArray(new PointerEvent[arrayListPointerEvents.size()]);
        // Feed the editor
        editor.pointerEvents(arrayPointerEvents, false);
        File file = new File(c.getExternalFilesDir(null), File.separator + "interpreted_txt" + mimeType.getFileExtensions());
        editor.waitForIdle();
        StringBuilder readFile = new StringBuilder();
        readFile.append("");
        try {
//            Export File and Read The Contents Of the File then Delete the File
            editor.export_(null, file.getAbsolutePath(), mimeType, null);
            Scanner myReader = new Scanner(file);
            while (myReader.hasNextLine()) {
                readFile.append(myReader.nextLine());
            }
            myReader.close();
//            file.delete();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return readFile.toString();
    }

 Above Is My Code and yet the Interpretation is not consistent if it interprets ones the next 5 times it just gives me *...

Thanks For Your Expected Assist.

 




Best Answer

Dear Oke Refe,


Thank you for your request.


I recommand you checking the common pitfalls listed on that section: https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/off-screen-usage/#common-pitfalls


More particularly I would like to draw your attention to the dpi values: they should correspond to the “resolution” of  your input surface, be it a digital screen or a sheet of paper (they possibly are not the same ones as the device values on which you are running your app).


Best regards,


Gwenaëlle


Dear Oke Refe,

To remove the emojis, you can use the no-emojis subset knowledge available at the following link: https://myscript.filecamp.com/s/KFtxeiU2BgGHaqY1/fo

You shall then add it on the assets of your projects, e.g. in the en_US directory of the assets.

You shall then add it in the en_US.conf file, as below:

# Configuration item #1
Name: text
Type: Text
Configuration-Script:
AddResource en_US/en_US-ak-cur.res
AddResource en_US/en_US-lk-text.res
AddResource en_US/no-emojis.res
SetTextListSize 1
SetWordListSize 5
SetCharListSize 1


Let us know if this helps.

Best regards,

Olivier


Answer

Dear Oke Refe,


Thank you for your request.


I recommand you checking the common pitfalls listed on that section: https://developer.myscript.com/docs/interactive-ink/1.3/android/advanced/off-screen-usage/#common-pitfalls


More particularly I would like to draw your attention to the dpi values: they should correspond to the “resolution” of  your input surface, be it a digital screen or a sheet of paper (they possibly are not the same ones as the device values on which you are running your app).


Best regards,


Gwenaëlle

Thanks Very Much Gwenaëlle. That was my Exact Problem I have resolved it (thanks to you) and it is interpreting fine now.

With Appreciation

Oke Refe

Thanks for your answer and sorry for my late reply

I am Implementing this now and will check for the results in the long tern

Regards

Okerefe

Please Another Question:

Is it possible to set the Editor or and Engine to only interpret for a specific type of characters say I want only A-Z and not special emojis like:  or  and the rest of them or say only numbers so symbols like 1 wont be taken as !

Thanks