我正在为我正在编写的应用程序使用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调用的准确性?也许这里有一些建议!诚挚的问候
托比亚斯
发布于 2012-01-27 22:24:22
也许,你应该为图像提供一些增强。
对图像进行平滑可以消除图像内部的噪声,从而减少错误结果。
字母表的像素高度在30或40范围内会更好。
虽然tesseract在灰度图像上工作,但发现二进制图像可以提供更好的结果。对于阈值,使用自适应阈值方法。
单词之间有足够的空格也是很好的。
你可以从tesseract forum.获得更多的技巧
发布于 2014-03-11 21:42:04
对我来说,仅仅是放大图像就可以将准确率提高到几乎100%。Tesseract还在他们的文档中指出,为了获得最佳效果,您需要300 dpi或更多。
所以我补充道:
ocrimage = pixScale(image,4.167,4.167);
api.SetImage(ocrimage);
(4.167 ~ dpi从72增加到300)
注意,我还尝试了api.SetSourceResolution(..)相反,告诉Tesseract我的图像的dpi较少,但不知何故,这并不能提供与放大图像等量一样好的结果。
发布于 2016-06-23 21:22:10
是的,这是正确的,如果你想要比执行下面的代码更准确,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%左右。
https://stackoverflow.com/questions/8644008
复制相似问题