【问题标题】:Enhance readability of TessBaseAPI.getUTF8Text()增强 TessBaseAPI.getUTF8Text() 的可读性
【发布时间】:2016-02-29 06:13:25
【问题描述】:

我尝试在 Android 中通过 Tess-Two 使用 Tesseract OCR 来识别图像中的文本(使用 Android Studio 开发)。

在 gradle 中,我在依赖项部分添加了以下行:

compile 'com.rmtheis:tess-two:5.4.1'

然后,在主活动的onCreate() 中,我有以下代码来初始化库并加载图像:

    final String lang = "eng";
    TessBaseAPI baseAPI = new TessBaseAPI();
    boolean initResult = baseAPI.init(Environment.getExternalStorageDirectory().getPath(), lang);
    if(initResult) {
        InputStream is = null;
        try {
            is = getAssets().open("test2.jpg");
            final Drawable drw = Drawable.createFromStream(is, null);
            Bitmap bmp = ((BitmapDrawable) drw).getBitmap();

            baseAPI.setDebug(true);
            baseAPI.setImage(bmp);
            ImageView imageView = (ImageView)findViewById(R.id.imageView);
            imageView.setImageBitmap(bmp);

            String recognizedText = baseAPI.getUTF8Text().trim();
            Log.d(TAG, recognizedText);
            TextView textView = (TextView) findViewById(R.id.txt_debug);
            textView.setText(recognizedText);
            baseAPI.end();
        } catch (FileNotFoundException nfe) {
            Log.d(TAG, "File Not Found");
            nfe.printStackTrace();
        } catch (IOException ioe) {
            Log.d(TAG, "Unable to open the file");
            ioe.printStackTrace();
        }
    } else {
        Log.d("OCR", "Unable to init Base API");
    }

最后,我将 JPEG 放入资产文件夹 (app/src/main/assets/)。这是JPEG,基本上是一段文字。

但是,OCR 结果是(相当垃圾):

OWW WW ON
R W WWW WK
KW MK
214
3 W5 HE WM
M WW WWW
LFNWW VW QTY
VM ACNL 19 WE NH
5 332152391
HQ W M W

如何提高扫描的可读性?

我尝试了以下Page Sec Mode,但结果是empty

// Automatic page segmentation with orientation and script detection
baseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
// Treat the image as a single text line
baseAPI.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);

【问题讨论】:

    标签: android ocr tesseract tess-two


    【解决方案1】:

    Tesseract 的识别主要取决于两件事: 字体文件和它的训练数据文件。

    tesseract 通常不能识别手写,但理论上如果你训练它识别类似于手写的字体,那么它可以工作。

    【讨论】:

    • 感谢您的意见。我发现通过使用 Scantailor 或 textcleaner ImageMagick 脚本等工具,OCR 功能的可读性得到了提高。关键是去除噪点并将 DPI 提高到至少 300dpi。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    相关资源
    最近更新 更多