【问题标题】:Advanced use of Tesseract OCRTesseract OCR 的高级使用
【发布时间】:2011-12-27 11:12:19
【问题描述】:

我正在将 Tesseract OCR 用于我正在编写的应用程序。我只是想从我不时得到的图片中识别某些区域的文字。基本调用目前有效

tesseract::TessBaseAPI api;
api.SetPageSegMode(tesseract::PSM_AUTO);        // Segmentation on auto
api.Init("/usr/local/share/","eng");            // path = parent directory of tessdata
pFile = fopen( "home/myname/test.bmp","r" );    // Open picture
PIX* image;                                     // Image format from leptonica
image = pixReadStreamBmp(pFile);              
fclose(pFile);
api.SetImage(image);                            // Run the OCR
char* textOutput = new char[512];
textOutput =api.GetUTF8Text();                  // Get the text

到目前为止,这段代码运行良好。但在某些时候,OCR 并不像我希望的那样准确。我实际上不想为我的目的训练一门新语言,所以我想知道是否有可能提高某些 API 调用的准确性? 也许这里有一些建议! 最好的问候

托比亚斯

【问题讨论】:

    标签: c++ ocr tesseract


    【解决方案1】:

    可能,您应该为图像提供一些增强功能。

    平滑图像去除图像内部的噪声,它会减少错误的结果。

    字母的像素高度在 30 或 40 范围内会更好。

    虽然 tesseract 可以处理灰度图像,但发现二值图像可以提供更好的结果。对于阈值,使用自适应阈值的方法。

    单词之间有足够的空间也很好。

    您可以从tesseract forum.获得更多提示

    【讨论】:

      【解决方案2】:

      对我来说,只是将图像放大到几乎 100% 即可。 Tesseract 还在他们的文档中某处声明,为了获得最佳效果,您需要 300 dpi 或更高。

      所以我补充说:

      ocrimage = pixScale(image,4.167,4.167);
      api.SetImage(ocrimage);
      

      (4.167 ~ dpi 从 72 增加到 300)

      请注意,我还尝试使用 api.SetSourceResolution(..) 来告诉 Tesseract 我的图像的 dpi 较低,但不知何故,这并没有像将图像放大等量那样得到好的结果。

      【讨论】:

        【解决方案3】:

        是的,没错,如果您想要比执行以下代码更准确,OCR 无法正常工作。

        /*
         * word_OCR.cpp
         *
         *  Created on: Jun 23, 2016
         *      Author: pratik
         */
        
        #include <opencv2/opencv.hpp>
        #include <tesseract/baseapi.h>
        #include <leptonica/allheaders.h>
        #include <iostream>
        
        using namespace std;
        using namespace cv;
        
        int main(int argc ,char **argv)
        {
            Pix *image = pixRead(argv[1]);
        
            if (image == 0) {
                cout << "Cannot load input file!\n";
            }
        
            tesseract::TessBaseAPI tess;
        
            if (tess.Init("/usr/share/tesseract/tessdata", "eng")) {
                    fprintf(stderr, "Could not initialize tesseract.\n");
                    exit(1);
                }
        
            tess.SetImage(image);
            tess.Recognize(0);
        
            tesseract::ResultIterator *ri = tess.GetIterator();
            tesseract::PageIteratorLevel level = tesseract::RIL_WORD;
        
            if(ri!=0)
            {
                do {
                    const char *word = ri->GetUTF8Text(level);
                    cout << word << endl;
        
                    delete []word;
        
                } while (ri->Next(level));
        
                delete []ri;
            }
        
        }
        

        这里从图像中逐字提取并给出单词作为输出,准确度约为90-95%

        【讨论】:

        • 如果你想要比这更高的精度,那么你可以在 pixeRead() 中传递 OTSU 阈值图像。我现在在 pixRead() 中传递正常图像。通过 OTSU 阈值图像。我为此开发了算法。 .如果有人想要,请告诉我。
        猜你喜欢
        • 1970-01-01
        • 2021-06-30
        • 2016-06-02
        • 2016-11-14
        • 1970-01-01
        • 2018-02-11
        • 1970-01-01
        • 2018-02-22
        • 2017-04-03
        相关资源
        最近更新 更多