2011-12-27 139 views
1

我正在为我正在编写的应用程序使用Tesseract OCR。我只是想从我时常得到的照片中识别出某些区域的文字。基本调用此刻工作高级使用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调用提高准确度? 也许这里有一些建议! 问候

托比亚斯

回答

2

可能是,你应该提供一些增强图像。

平滑图像消除图像中的噪音,它会减少错误的结果。字母的

像素高度将是在30或40

范围更好尽管灰度图像的tesseract工作,二进制图像中发现,得到更好的结果。对于阈值处理,使用自适应阈值法。

在单词之间留出足够的空间也很好。

您可以从tesseract forum.

0

得到进一步的提示对我来说只是扩大图像精度提高至几乎100%。 Tesseract在他们的文档中还指出,为获得最佳效果,您需要300 dpi或更多。

于是我说:

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

(从72到300 4.167〜dpi的增加),我也试过api.SetSourceResolution(..)来代替,告诉正方体,我的形象是小于dpi,但不知何故,这不会产生与放大图像等效量一样好的结果。

0

是的,这是正确的,如果您想要比执行下面的代码更精确,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%

+0

如果你想要比这更精确,那么你可以在pixeRead()中传递OTSU阈值图像。我正在pixRead()中传递正常图像。通过OTSU阈值图像。我为此开发了算法。 。让我知道是否有人想要。 – 2016-06-24 07:44:43