iink SDK on Device

Answered

Editor question

We need to identify a lot of data in the for loop 。

Create a new "Editor" for each recognition to get the corresponding order of recognition results 。

Now there are always exceptions in the recognition that cause the application to crash 。

How can I use "Editor" correctly now to avoid these problems ?


Frequent problems :

 Out Of Memory   /  IO_FAILURE    and so on

Failed to edit block "MainBlock"IO_FAILURE: 

    error: AddResource en_US/en_US-ak-cur.res failed

    error: failed to read configuration script

    script exits with 2 errors


Thanks for your help !


The sample is as follows :


 for (int i = 0; i < 10; i++) {

            initEditorCustomize(ArrayList<PointerEvent>);  

 }


    //数字

    public static void initEditorNUMBERs(ArrayList<PointerEvent> events) {

        float dpiX = 150;

        float dpiY = 150;

        Renderer renderer = engine.createRenderer(dpiX, dpiY, null);


        // Create the editor

        final Editor[] editorPrecise = {engine.createEditor(renderer)};

        //修改引擎配置语言:

        //设置中文识别

        Configuration configuration = editorPrecise[0].getConfiguration();

        configuration.setStringArray("configuration-manager.search-path", new String[]{"zip://" + RzjyApplication.getContext().getPackageCodePath() + "!/assets/conf"});

        String tempDir = RzjyApplication.getContext().getFilesDir().getPath() + File.separator + "tmp";

        configuration.setString("content-package.temp-folder", tempDir);

  //数字

        configuration.setString("text.configuration.name", "text-cust-select-num");

        configuration.setString("lang", "zh_CN");

        // The editor requires a font metrics provider and a view size *before* calling setPart()

        DisplayMetrics displayMetrics = RzjyApplication.getContext().getResources().getDisplayMetrics();

        Map<String, Typeface> typefaceMap = new HashMap<>();

        editorPrecise[0].setFontMetricsProvider(new FontMetricsProvider(displayMetrics, typefaceMap));

        editorPrecise[0].setViewSize(1240, 1754);

        // Create a temporary package and part for the editor to work with

        try {

            if (packages == null) {

                packages = engine.createPackage("text.iink");

            }

            ContentPart parts = packages.createPart("Text");

            editorPrecise[0].setPart(parts);


        } catch (IOException e) {

            e.printStackTrace();

        }


        //识别状态监听 代理

        editorPrecise[0].addListener(new IEditorListener() {

            @Override

            public void partChanging(Editor editor, ContentPart oldPart, ContentPart newPart) {

                // no-op

            }


            @Override

            public void partChanged(Editor editor) {

            }

            @Override

            public void contentChanged(final Editor editor, String[] blockIds) {

                final ContentBlock rootBlock = editor.getRootBlock();

                try {

                    String trim = editor.export_(rootBlock, MimeType.TEXT).trim();

                      Log.e("识别editor数字", "contentChanged1: " + trim);

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            @Override

            public void onError(Editor editor, String blockId, String message) {

                Log.e("TAG", "Failed to edit block \"" + blockId + "\"" + message);

            }

        });

        try {

            editorPrecise[0].pointerEvents(events.toArray(new PointerEvent[0]), true);

        } catch (Exception e) {

            Log.e("识别", "Exception: " + e.toString());

        }

    }



Best Answer

Dear 磊 胡,

Thank you for contacting us and your questions.

First, is there a reason you are creating 10 editors in parallel? Indeed, the bottleneck being the device (CPU RAM), you will not get the results faster... instead, I would rather recommend you process each batch of ink one by one, and do not have several editors in parallel.

Also, is there a reason you call the export function (editor.export_(rootBlock, MimeType.TEXT).trim()) in the contentChanged function? Indeed, this is not an approach we recommend, as the content changed is called very often (several time per second, e.g. each time the "content has changed").
Instead, our recommendation is that after calling "editorPrecise[0].pointerEvents(...);", you call waitForIdle(), and then export.

Also, in the editorPrecise[0].pointerEvents, you set the processGestures boolean to true, while we recommend to set it to false for a better result in batch mode: https://developer.myscript.com/docs/interactive-ink/1.4/android/advanced/off-screen-usage/

All this can be found in the batch sample example we provide, which we recommend you follow carefully: https://github.com/MyScript/interactive-ink-additional-examples-android/tree/master/java/samples/batch-mode

Now, regarding your errors:
-Out Of Memory => This error is quite implicit. If applying above recommendations (i.e. reduce the number of ink processed in parallel, ideally process inks one after another), and call export after waitForIdle, it is less likely to occur
-error: AddResource en_US/en_US-ak-cur.res failed => This means that you are trying to load the en_US configuration, and it cannot find the en_US/en_US-ak-cur.res resource. You shall ensure you properly deploy the corresponding en_US language package into your project.

Please note some of these recommendations were already provided in thhe post you created 2 months ago: https://developer-support.myscript.com/support/discussions/topics/16000029933

Best regards,

Olivier

1 Comment

Answer

Dear 磊 胡,

Thank you for contacting us and your questions.

First, is there a reason you are creating 10 editors in parallel? Indeed, the bottleneck being the device (CPU RAM), you will not get the results faster... instead, I would rather recommend you process each batch of ink one by one, and do not have several editors in parallel.

Also, is there a reason you call the export function (editor.export_(rootBlock, MimeType.TEXT).trim()) in the contentChanged function? Indeed, this is not an approach we recommend, as the content changed is called very often (several time per second, e.g. each time the "content has changed").
Instead, our recommendation is that after calling "editorPrecise[0].pointerEvents(...);", you call waitForIdle(), and then export.

Also, in the editorPrecise[0].pointerEvents, you set the processGestures boolean to true, while we recommend to set it to false for a better result in batch mode: https://developer.myscript.com/docs/interactive-ink/1.4/android/advanced/off-screen-usage/

All this can be found in the batch sample example we provide, which we recommend you follow carefully: https://github.com/MyScript/interactive-ink-additional-examples-android/tree/master/java/samples/batch-mode

Now, regarding your errors:
-Out Of Memory => This error is quite implicit. If applying above recommendations (i.e. reduce the number of ink processed in parallel, ideally process inks one after another), and call export after waitForIdle, it is less likely to occur
-error: AddResource en_US/en_US-ak-cur.res failed => This means that you are trying to load the en_US configuration, and it cannot find the en_US/en_US-ak-cur.res resource. You shall ensure you properly deploy the corresponding en_US language package into your project.

Please note some of these recommendations were already provided in thhe post you created 2 months ago: https://developer-support.myscript.com/support/discussions/topics/16000029933

Best regards,

Olivier