Software Development Kit

Answered

problem about BATCH-MODE in Android

hello,gods of mycript, recently, I need to solve bacth processing in Android

first, I git clone the repository in https://github.com/MyScript/interactive-ink-additional-examples-android.git


and I also apply this project in chinese,for example,I want to recognize this picture:

image

and the batch mode API give the below result

image

ok , So far is very good ,this is a single file, I want use this API to deal with all files in a Folder, like below


image


and I modify the code to below


image


function readfile()


private void readfile(String assetDir, String dir, Renderer renderer) {

        String[] files;

        float total = 0;

        float error = 0;

        try {

            // 获得Assets一共有几多文件

            System.out.println("开始读取文件");

            files = this.getResources().getAssets().list(assetDir);

            System.out.println("读取文件完毕");


            File param3 = getExternalFilesDir(null);

            String param4 = File.separator + "right_file.txt";


            File outFile1 = new File(param3, param4);


            if (outFile1.exists())

                outFile1.delete();


            OutputStream out1 = new FileOutputStream(outFile1);


            for (int i = 0; i < files.length; i++) {


                try {

                    // 获得每个文件的名字

                    String fileName = files[i];

                    // Load the pointerEvents from the right .json file depending of the part type

                    PointerEvent[] pointerEvents = loadPointerEvents(assetDir + "/" + fileName);


                    packageName = i + "package.iink";

                    // Create a new package

                    contentPackage = engine.createPackage(packageName);


                    // Create a new part

                    contentPart = contentPackage.createPart(partType);

                    // Associate editor with the new part

                    editor.setPart(contentPart);


                    // Feed the editor

                    editor.pointerEvents(pointerEvents, false);


                    // Export the result of the recognition into a file

                    export(fileName);


                    out1.write(fileName.getBytes());

                    out1.write("\n".getBytes());

                    out1.flush();

                    System.out.println(total + " done!");

                } catch (Exception e1) {


                    e1.printStackTrace();

// editor.clear();

                    editor.setPart(null);

                    contentPart.close();

                    contentPackage.close();

                    editor.close();

                    error += 1;

                }

                total += 1;

            }

            out1.close();

            File param1 = getExternalFilesDir(null);

            String param2 = File.separator + "error_rate.txt";

            // Exported file is stored in the Virtual SD Card : "Android/data/com.myscript.iink.batchmode/files"

            File outFile2 = new File(param1, param2);


            if (outFile2.exists())

                outFile2.delete();


            OutputStream out = new FileOutputStream(outFile2);

            out.write(new Float(error).toString().getBytes());

            out.write("\n".getBytes());

            out.write(new Float(total).toString().getBytes());

            out.write("\n".getBytes());

            out.write(new Float(error / total).toString().getBytes());

            out.close();

            finish();

        } catch (IOException e1) {

            e1.printStackTrace();

        }

    }


and problem comes,code below:

image

I admit there are some problems with some of my data,and the code will throws a exception:

pointer with same pointerId has a trace already pending

pointer with same pointerId has a trace already pending

and when a exception  thrown,the code go to:

image

I just want to skip the error file and restart,but the red code Get stuck,yes it stuck,and make program stop,so I can't continue my processing.

how should I do?

is there some problem with my code?

please help me! 

I want to make the processing to a really BATCH MODE


Best Answer

Dear Liu Yongjie,

thank you for contacting us.

Currently, the cause of the error can be found thanks to the error message you have: "pointer with same pointerId has a trace already pending"

Indeed, this error is raised when a pointerUp event is missing. For each stroke that is added, you must ensure you have a "pointerDown" and a "pointerUp": https://developer-support.myscript.com/support/discussions/topics/16000024603

Let us know if you have further questions.

Best regards,

Olivier


Answer

Dear Liu Yongjie,

thank you for contacting us.

Currently, the cause of the error can be found thanks to the error message you have: "pointer with same pointerId has a trace already pending"

Indeed, this error is raised when a pointerUp event is missing. For each stroke that is added, you must ensure you have a "pointerDown" and a "pointerUp": https://developer-support.myscript.com/support/discussions/topics/16000024603

Let us know if you have further questions.

Best regards,

Olivier


1 person likes this

ok I have solved my problem, the staff in myscript is very nice, thank you!