C++ Tesseract OCR的高级使用

C++ Tesseract OCR的高级使用,c++,ocr,tesseract,C++,Ocr,Tesseract,我正在为我正在编写的应用程序使用Tesseract OCR。我只是想从我不时得到的图片中识别出一些区域的文字。目前基本的呼叫工作正常 tesseract::TessBaseAPI api; api.SetPageSegMode(tesseract::PSM_AUTO); // Segmentation on auto api.Init("/usr/local/share/","eng"); // path = parent directory of tessd

我正在为我正在编写的应用程序使用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调用来提高准确性? 也许这里有一些建议! 致意


托拜厄斯

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

对图像进行平滑处理可以去除图像中的噪声,减少虚假结果

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

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

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


您可以从

中获得更多提示,只需将图像放大,即可提高精度,几乎达到100%。Tesseract还在他们的文档中的某个地方声明,为了获得最佳效果,您需要300 dpi或更多

所以我补充说:

ocrimage = pixScale(image,4.167,4.167);
api.SetImage(ocrimage);
(4.167~dpi从72增加到300)


请注意,我还尝试了api.SetSourceSolution(..),以告诉Tesseract我的图像的dpi较低,但不知何故,这并不能提供与将图像放大等量一样好的结果。

是的,这是正确的,如果您希望比执行以下代码更精确,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;
    }

}
/*
*word_OCR.cpp
*
*创建日期:2016年6月23日
*作者:pratik
*/
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
int main(int argc,字符**argv)
{
Pix*image=pixRead(argv[1]);
如果(图像==0){
cout GetUTF8Text(级别);

如果你想获得更高的精度,那么你可以通过pixRead()中的OTSU阈值图像。我现在正在通过pixRead()中的正常图像。通过OTSU阈值图像。我为此开发了算法。如果有人需要,请告诉我。