General questions

Answered

script stops running after editor.waitForIdle() call

Hello There

I have previously successfully Linked the MyScript and all and everything was working perfectly then suddenly everything stops, through logging I can see that the code do not go beyond the editor.waitforidle() call (I am working in batch mode) and there is no error of any sort its as if i just exited the code

I am running it in a service in android studio

I didnt want to post my code cause it's long and all that but i guess i will just do it. 

        Document doc = (Document) intent.getParcelableExtra(DOCUMENT);
        Toast toast = Toast.makeText(this, "STROKE SERVICE...", Toast.LENGTH_LONG);
        toast.show();
        Log.d(TAG,"STROKE SERVICE....>>>>");

        engine = IInkApplication.getEngine();
        // Configure recognition
        Configuration conf = engine.getConfiguration();
        String confDir = "zip://" + getPackageCodePath() + "!/assets/conf";
        Log.d(TAG, "&&&&&&&&&&&PACKAGE CODE PATH!!!" + getPackageCodePath());
        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();
        //DPI Values for Neo A4 Paper
        Renderer renderer = engine.createRenderer(11, 11, 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);

        //Width and Height for Neo Paper
//        editor.setViewSize(92, 118);
        editor.setViewSize(118, 92);

        mDataSource = new DataSource(this);
        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);
        }

        for(int i=0; i<doc.getInputSize(); i++) {
            // Associate editor with the new part
            editor.setPart(contentPart);

            Input current = doc.getInput(i);
            ArrayList<Stroke> strokes = mDataSource.getStrokes(current.mRectF);
            if(strokes.size() < 1){
                continue;
            }
            ArrayList<PointerEvent> arrayListPointerEvents = null;
            arrayListPointerEvents = new ArrayList<PointerEvent>();
            PointerType mPointerType = PEN;
            int id = 1;
            for (int counter = 0; counter < strokes.size(); counter++) {
                Stroke s = strokes.get(counter);
//                If Pointer does not receive an UP, MOVE and DOWN movement it will give errors
//                So for Strokes with less than 3 Dots we create this pointers
                if(s.size() < 3){
                    Log.d(TAG, "<<<<< LESS THAN 3");
                    for(int d = 0; d< 3; d++){
                        PointerEvent pointerEvent = new PointerEvent();
                        pointerEvent.pointerType = mPointerType;
                        pointerEvent.pointerId = id;
                        // We assign either DOWN,UP Or MOVE Pointer Event Types to each pointer depending on the Dots
                        if (d == 0) {
                            pointerEvent.eventType = PointerEventType.DOWN;
                            Log.d(TAG, "PenDown");
                        } else if (d == 2) {
                            pointerEvent.eventType = PointerEventType.UP;
                            Log.d(TAG, "PenUp");
                        } else {
                            pointerEvent.eventType = PointerEventType.MOVE;
                            Log.d(TAG, "PenMove");
                        }
                        if(doc.orientation ==  Document.ORIENTATION_PORTRAIT) {
                            pointerEvent.x = s.get(0).x;;
                            pointerEvent.y = s.get(0).y;

                            pointerEvent.t = s.get(0).timestamp;
                            pointerEvent.f = s.get(0).pressure;

                        }
                        if(doc.orientation ==  Document.ORIENTATION_LANDSCAPE) {
                            pointerEvent.x = 130 - (s.get(0).y);
                            pointerEvent.y = s.get(0).x;

                            pointerEvent.t = s.get(0).timestamp;
                            pointerEvent.f = s.get(0).pressure;

                        }
                        arrayListPointerEvents.add(pointerEvent);
                        ++id;
                    }

                } else {

                    for (int a = 0; a < s.size(); a++) {
                        Log.d(TAG, "New Dot");
                        PointerEvent pointerEvent = new PointerEvent();
                        pointerEvent.pointerType = mPointerType;
                        pointerEvent.pointerId = id;
                        // We assign either DOWN,UP Or MOVE Pointer Event Types to each pointer depending on the Dots
                        if (a == 0) {
                            pointerEvent.eventType = PointerEventType.DOWN;
                            Log.d(TAG, "PenDown");
                        } else if (a == (s.size() - 1)) {
                            pointerEvent.eventType = PointerEventType.UP;
                            Log.d(TAG, "PenUp");
                        } else {
                            pointerEvent.eventType = PointerEventType.MOVE;
                            Log.d(TAG, "PenMove");
                        }
//                    Switch Statement to check Orientation and adjust x and y axis accordingly

                        if(doc.orientation ==  Document.ORIENTATION_PORTRAIT) {
                            pointerEvent.x = s.get(a).x;;
                            pointerEvent.y = s.get(a).y;

                            pointerEvent.t = s.get(a).timestamp;
                            pointerEvent.f = s.get(a).pressure;

                        }
                        if(doc.orientation ==  Document.ORIENTATION_LANDSCAPE) {
                            pointerEvent.x = 130 - (s.get(a).y);
                            pointerEvent.y = s.get(a).x;

                            pointerEvent.t = s.get(a).timestamp;
                            pointerEvent.f = s.get(a).pressure;

                        }

                        arrayListPointerEvents.add(pointerEvent);
                        ++id;
                    }
                }
            }
            PointerEvent[] arrayPointerEvents = arrayListPointerEvents.toArray(new PointerEvent[arrayListPointerEvents.size()]);
            // Feed the editor
            editor.pointerEvents(arrayPointerEvents, false);
            File file = new File(c.getExternalFilesDir(null), File.separator + current.name + mimeType.getFileExtensions());
            Log.d(TAG, "Reached Here 1");
            editor.waitForIdle();
            Log.d(TAG, "Reached Here 2");
            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);
            } catch (Exception e) {
                e.printStackTrace();
                Log.d(TAG, "There Were Some Errors ");
            }

            Scanner myReader = null;
            try {
                myReader = new Scanner(file);
                while (myReader.hasNextLine()) {
                    readFile.append(myReader.nextLine());
                }
                myReader.close();
//            Delete File
                file.delete();

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            editor.clear();
            current.value = readFile.toString();
            Log.d(TAG, "SENDING DOCUMENT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            Log.d(TAG, "Reached Here 1");

            Intent messageIntent = new Intent(STROKE_SERVICE_MESSAGE);
            messageIntent.putExtra(STROKE_DOC_RESPONSE, doc);
            messageIntent.putExtra(STROKE_DOC_COMPLETE_STATUS, PROCESS_NOT_COMPLETE);
            LocalBroadcastManager manager =
                    LocalBroadcastManager.getInstance(getApplicationContext());
            manager.sendBroadcast(messageIntent);
        }
        mDataSource.close();
        Intent messageIntent = new Intent(STROKE_SERVICE_MESSAGE);
        messageIntent.putExtra(STROKE_DOC_RESPONSE, doc);
        messageIntent.putExtra(STROKE_DOC_COMPLETE_STATUS, PROCESS_COMPLETE);
        LocalBroadcastManager manager =
                LocalBroadcastManager.getInstance(getApplicationContext());
        manager.sendBroadcast(messageIntent);
        contentPart.close();
        contentPackage.close();
        try {
            engine.deletePackage(packageName);
        } catch (IOException e) {
            e.printStackTrace();
        }

  Below is the Document Object (I am using the myscript to interpret pen strokes)

 

package com.myscript.iink.demo.models;

import android.graphics.RectF;
import android.os.Parcel;
import android.os.Parcelable;

import com.myscript.iink.demo.MainActivity;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class Document implements Parcelable {
    public static final int ORIENTATION_PORTRAIT = 1;
    public static final int ORIENTATION_LANDSCAPE = 2;
    private int id = 2;
    private ArrayList<Input> inputList;
//    private Input[] inputList;
//    private Input[] inputList = [new Input("dd", "ss", new RectF(38.97f,95.04f,42.75f,122.34f)),];
    private RectF doneRectF= new RectF(38.97f,95.04f,42.75f,122.34f);
    public int orientation = 22;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Input getInputList(int i) {
        return inputList.get(i);
//        return Array.get(inputList, i);//  inputList[];
    }

//    public void setInputList(ArrayList<Input> inputList) {
//        this.inputList = inputList;
//    }

    public String getDone() {
        return doneRectF.toString();
    }

    public void setDone(RectF done) {
        this.doneRectF = done;
    }

    public int getInputSize() {
        return inputList.size();
//        return inputList.length();
    }

    public Input getInput(int i) {
        return inputList.get(i);
//        return (Input) Array.get(inputList, i);
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeList(this.inputList);
        dest.writeParcelable(this.doneRectF, flags);
        dest.writeInt(this.orientation);
    }

    public Document() {
    }

    protected Document(Parcel in) {
        this.id = in.readInt();
        this.inputList = new ArrayList<Input>();
        in.readList(this.inputList, Input.class.getClassLoader());
        this.doneRectF = in.readParcelable(RectF.class.getClassLoader());
        this.orientation = in.readInt();
    }

    public static final Parcelable.Creator<Document> CREATOR = new Parcelable.Creator<Document>() {
        @Override
        public Document createFromParcel(Parcel source) {
            return new Document(source);
        }

        @Override
        public Document[] newArray(int size) {
            return new Document[size];
        }
    };
}

Each Input is like a form coordinate on the paper document.

Thanks for your Expected positive and Helpful response.

 


Best Answer

Dear Oke Refe,


Thank you for your update.


After extracting from your db file the x and y coordinates, we re-constructed the following  ink:

There are two issues with this ink:

1: The handwriting is vertical whereas it should be horizontal.

2: The ink quality is quite poor and this is probably the reason of your recognition problem.


So our recommandation is that you check your ink capture quality to ensure to have correct data, and to send horizontal ink.


Also, what is the content type you are processing (Text or Math)? If it is Text, what is the language of the text?


Best regards,


Gwenaëlle






Dear Oke Refe,


Thank you for your request.


A first remark about your code is that you should call setPart only once, outside your loop, because I assume you want to only use a single part :

            editor.setPart(contentPart);



Also could you, please,  indicate which language you are using? 

Which part type?

Could you also, please, provide us with the strokes you are using for your test?


Best regards,


Gwenaëlle




Noted (on the setpart(content) )

The language is Java in android studio

Below is the data source method that gets the stroke of a particular RectF Property


 

    public ArrayList<Stroke> getStrokes(RectF rectF) {
        ArrayList<Stroke> strokes = new ArrayList<Stroke>();
        Cursor cursor = null;
        cursor = mDatabase.query(StrokesTable.TABLE_STROKES, StrokesTable.ALL_COLUMNS,
                null, null, null, null, null);

        while (cursor.moveToNext()) {
            Stroke s = getStroke(cursor);
            // check if stroke is in this Rectf
            if (s.contains(rectF)) {
                strokes.add(s);
            }
        }

        return strokes;
    }


    private Stroke getStroke(Cursor cursor) {
        Stroke mStroke = new Stroke(cursor.getInt(cursor.getColumnIndex(StrokesTable.SECTION_ID)),
                cursor.getInt(cursor.getColumnIndex(StrokesTable.OWNER_ID)),
                cursor.getInt(cursor.getColumnIndex(StrokesTable.NOTE_ID)),
                cursor.getInt(cursor.getColumnIndex(StrokesTable.PAGE_ID)),
                cursor.getInt(cursor.getColumnIndex(StrokesTable.COLOR)), 0);


        mStroke.thickness = cursor.getInt(cursor.getColumnIndex(StrokesTable.COLOR));
        mStroke.timeStampStart = cursor.getInt(cursor.getColumnIndex(StrokesTable.TIME_START));
        mStroke.timeStampEnd = cursor.getInt(cursor.getColumnIndex(StrokesTable.TIME_END));

        String dots = cursor.getString(cursor.getColumnIndex(StrokesTable.DOTS));

        Gson gson = new Gson();
        Dot[] f = gson.fromJson(dots, Dot[].class);
        for (Dot d : f) {
            mStroke.add(d);
        }
        return mStroke;
    }


This Link is to a copy of the sqlite database file that contains the stroke. 

it can be viewed with any Sqlite Browser

Thanks for the assist

Answer

Dear Oke Refe,


Thank you for your update.


After extracting from your db file the x and y coordinates, we re-constructed the following  ink:

There are two issues with this ink:

1: The handwriting is vertical whereas it should be horizontal.

2: The ink quality is quite poor and this is probably the reason of your recognition problem.


So our recommandation is that you check your ink capture quality to ensure to have correct data, and to send horizontal ink.


Also, what is the content type you are processing (Text or Math)? If it is Text, what is the language of the text?


Best regards,


Gwenaëlle