Skip to content Skip to sidebar Skip to footer

Tesseract Ocr Returns Null String

I am building an OCR app for android and i use tesseract ocr engine. Somehow every time i use the engine on a photo it returns an empty text. This is my code: public String detectT

Solution 1:

You are using the OCR Engine Mode Enum value for setting the page segmentation in your setTessData() method.

setTessData() {
    ...
    tessBaseAPI.setPageSegMode(TessBaseAPI.OEM_TESSERACT_ONLY);
}

Based on the type of image on which you are trying to detect the characters, setting an appropriate Page segmentation mode will help detect the characters.

For example :

tessBaseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO);

The various other Page segmentation values are present in TessBaseApi.java :

/** Page segmentation mode. */publicstaticfinalclassPageSegMode {
    /** Orientation and script detection only. */publicstaticfinalint PSM_OSD_ONLY = 0;

    /** Automatic page segmentation with orientation and script detection. (OSD) */publicstaticfinalint PSM_AUTO_OSD = 1;

    /** Fully automatic page segmentation, but no OSD, or OCR. */publicstaticfinalint PSM_AUTO_ONLY = 2;

    /** Fully automatic page segmentation, but no OSD. */publicstaticfinalint PSM_AUTO = 3;

    /** Assume a single column of text of variable sizes. */publicstaticfinalint PSM_SINGLE_COLUMN = 4;

    /** Assume a single uniform block of vertically aligned text. */publicstaticfinalint PSM_SINGLE_BLOCK_VERT_TEXT = 5;

    /** Assume a single uniform block of text. (Default.) */publicstaticfinalint PSM_SINGLE_BLOCK = 6;

    /** Treat the image as a single text line. */publicstaticfinalint PSM_SINGLE_LINE = 7;

    /** Treat the image as a single word. */publicstaticfinalint PSM_SINGLE_WORD = 8;

    /** Treat the image as a single word in a circle. */publicstaticfinalint PSM_CIRCLE_WORD = 9;

    /** Treat the image as a single character. */publicstaticfinalint PSM_SINGLE_CHAR = 10;

    /** Find as much text as possible in no particular order. */publicstaticfinalint PSM_SPARSE_TEXT = 11;

    /** Sparse text with orientation and script detection. */publicstaticfinalint PSM_SPARSE_TEXT_OSD = 12;

    /** Number of enum entries. */publicstaticfinalint PSM_COUNT = 13;
}

You can experiment with different page segmentation enum values and see which gives the best result.

Post a Comment for "Tesseract Ocr Returns Null String"