Search code examples
androideclipseocrtesseracttess-two

Android OCR: AndrOCR source code error


I am a student working on a school project to create a business card scanner to extract the text from image and display it accordingly by name, phone number, etc into respective text boxes.

I have been googling for the past few weeks and found many great examples online. Currently I am trying to implement the source code from this application I found online called "AndrOCR". However, I have encountered some error in the codes in which I do not know how to solve in Ecilpse(juno).

I have already implemented tess-two from rmtheis and able to run some other OCR source codes. However, for "AndrOCR" I am unable to solve.

The codes with the error are shown below:

    public void onDialogSingleChoice(int dialog_id, int item){
    switch(dialog_id){

        case SEGMODE_DIALOG:
            mSegModeID = item;
            // Change the OCR page segmentation mode
            switch (mSegModeID){
            case 0:
                mSegMode = TessBaseAPI.**PSM_AUTO**;                        
                break;
            case 1:         
                mSegMode = TessBaseAPI.**PSM_SINGLE_BLOCK**;                        
                break;
            case 2:
                mSegMode = TessBaseAPI.**PSM_SINGLE_LINE**;                     
                break;
            case 3:
                mSegMode = TessBaseAPI.**PSM_SINGLE_WORD**;                     
                break;
            case 4:
                mSegMode = TessBaseAPI.**PSM_SINGLE_CHAR**;                     
                break;
            case 5:
                mSegMode = TessBaseAPI.**PSM_SINGLE_BLOCK_VERT_TEXT**;                      
                break;                  
            }                   
            // It's not needed to restart the whole library here
            removeDialogFragment("segmode_dialog");
            Toast.makeText(mThis, getString(R.string.selected_text_layout) + " " + mSegModeArray[mSegModeID], Toast.LENGTH_SHORT).show();
            break;

        case LANGUAGE_DIALOG:
            mLangID = item;
            // Change the OCR language recognition
            mLang = mTessLangArray[mLangID];
            removeDialogFragment("language_dialog");
            setTessData();              
            break;
    }
}

The error occurs in the bolded text as shown above. The error message is "PSM_AUTO cannot be resolved or is not a field" for the first error, which also apply to the rest.

The source code is available in this link: https://github.com/TheWall89/AndrOCR

Please do check it out and let me know what the error are and how I can resolve them, as I am still a beginner at android development and require much help, thanks a lot~


Solution

  • Those constants were moved to an inner class called PageSegMode.

    So change your code to

    mSegMode = TessBaseAPI.PageSegMode.PSM_AUTO;
    

    and

    mSegMode = TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK;
    

    etc.