【问题标题】:OCR text recognition wrong text displayingOCR文字识别错误文字显示
【发布时间】:2016-12-29 12:48:57
【问题描述】:

我是 tess-two 库的新手。我可以添加该库并从可绘制对象中获取图像,甚至可以进行转换,但我得到的文本错误如下:

这是我的完整代码:

Bitmap image;
private TessBaseAPI mTess;
String datapath = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //init image
    image = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);

    //initialize Tesseract API
    String language = "eng";
    datapath = getFilesDir()+ "/tesseract/";
    mTess = new TessBaseAPI();

    checkFile(new File(datapath + "tessdata/"));

    mTess.init(datapath, language);
}

private void checkFile(File file) {
    if (!file.exists()&& file.mkdirs()){
        copyFiles();
    }
    if(file.exists()) {
        String datafilepath = datapath+ "/tessdata/eng.traineddata";
        File datafile = new File(datafilepath);

        if (!datafile.exists()) {
            copyFiles();
        }
    }
}


public void processImage(View view){
    String OCRresult = null;
    mTess.setImage(image);     
    OCRresult = mTess.getUTF8Text();
    TextView OCRTextView = (TextView) findViewById(R.id.OCRTextView);
    OCRTextView.setText(OCRresult);
}

private void copyFiles() {
    try {
        String filepath = datapath + "/tessdata/eng.traineddata";
        AssetManager assetManager = getAssets();

        InputStream instream = assetManager.open("tessdata/eng.traineddata");
        OutputStream outstream = new FileOutputStream(filepath);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = instream.read(buffer)) != -1) {
            outstream.write(buffer, 0, read);
        }


        outstream.flush();
        outstream.close();
        instream.close();

        File file = new File(filepath);
        if (!file.exists()) {
            throw new FileNotFoundException();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

我收到如下文字:

mmmm.and,mmm,1111 等

感谢任何帮助。

【问题讨论】:

  • 你想做什么?表示预期输出?
  • 我的图片包含一些文字,例如,
  • 能否请您更新该图像和所有内容
  • 我的图像包含一些文本,例如,Tomorrow,Tomorrow....类似的东西。我应该得到相同的输出,但我得到的输出类似于 mmmm、md、mm 和 3:4就这样……
  • 尝试裁剪图像。

标签: java android ocr tess-two


【解决方案1】:

我遇到了同样的问题。它已在 2 分钟前修复它,您必须将图像调整为更大的尺寸。我使用thumbnailator 库来完成这项工作:

BufferedImage bigger = Thumbnails.of(oldImage).size(700, 500).asBufferedImage();

我希望它对我糟糕的英语有所帮助并道歉。

注意:更多关于调整here的信息

【讨论】:

    【解决方案2】:

    可能的问题:

    1. OCR 文本不正确
    2. 在训练数据中添加关键字 跟着教程Tesseract Tutorial Page

    【讨论】:

    • 我遵循了相同的教程。当我使用该图像时,我能够获得相同的文本,即 abc ....我更改了图像。我得到了错误的文本...那么...这就是问题..
    • 关注我的重播 :D 请尝试在输入图像中使用 Times New Roman 和 Arial 字体。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 2017-05-19
    • 2018-12-11
    • 1970-01-01
    • 2014-04-25
    • 2015-09-17
    相关资源
    最近更新 更多