如何告诉tesseract不要忽略单词之间的空格?

时间:2018-02-13 16:18:17

标签: ios ocr tesseract

我正在尝试实施名片扫描应用。我正在使用tesseract库。

我阅读了与提高Tesseract性能相关的文章,我在将图像传递给Tesseract之前预先处理了图像。

我发现Tesseract最适合使用灰度/黑白图像。

我在选择正确的网页细分方面遇到了麻烦。

到目前为止,

  

G8PageSegmentationModeSingleBlock (假设单个统一块   文本)

给我最好的名片格式效果。

以下是使用此细分模式的结果:

灰度:

enter image description here

当使用灰度图像时,T​​esseract正在识别单词(看红色矩形),但有时它会识别单词之间的空格。

这是输出:

o
f l ,t!ti,iy,,,tyii,i,,!),i),,m,i,st,,,i,t,)) ',
REAL E:ESrry"irfEf
SOLUTIONS WC, n
TimTsai        ----> (space missing here)
Investor & Consultant
p 780.803.9935
f 888.803.1485
e tim@lnnoventionGroup.ca
w www.lnnoventionGroup.ca

Black&怀特:

enter image description here

这比识别单词之间的空间的灰度中间点要好一些,但是这也将图像的边界识别为字母,并将它们附加到原始/实际文本。 (查看红色矩形如何延长到图像边缘,因为分割模式设置为识别统一的文本块)

这是输出:

o,
f I t,!h,tig/i,i,,ip,,ip,iy (,
REAL ESTATE i,
SOLUTIONS INC. (i,
Tim Tsai i;,      ------> (yay, got the space)
Investor & Consultant ii,
p 780.803.9935 :i,
f 888.803.1485 i:,
e tim@lnnoventionGroup.ca (i,
,
-ee_--e_-----e----------ir-eeeereree-e-re---------------, u p

我也尝试删除边框,这次,它没有读取单词之间的空白区域。

enter image description here

输出:

 o
I I !,,!ih,tle/IiEhp,tt,l,l),!
REAL ESTATE
SOLUTIONS INC.
TimTsai
Investor & Consultant
p 780.803.9935
f 888.803.1485
e tim@lnnoventionGroup.ca

问题:

这种行为的原因是什么(忽略单词之间的空格?)

我可以通过哪种方式改进这一点,以便tesseract不会一直忽略空格?

我还可以看看旋转/偏移,但我不确定在这种情况下可以提高多少性能,因为文本看起来与我大致相同。

代码:

G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:@"eng"];
tesseract.delegate = self;
tesseract.engineMode=G8OCREngineModeTesseractCubeCombined;

// Optional: Limit the character set Tesseract should try to recognize from
tesseract.charWhitelist = @"@.,&():ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";

tesseract.charBlacklist=@"$%^*={};<>\\~`";

// Specify the image Tesseract should recognize on
    tesseract.image = [img g8_blackAndWhite];

tesseract.sourceResolution=kG8MaxCredibleResolution;


// Optional: Limit the area of the image Tesseract should recognize on to a rectangle
CGRect tessRect = CGRectMake(0, 0, tesseract.image.size.width, tesseract.image.size.height);

    tesseract.rect = tessRect;

// Optional: Limit recognition time with a few seconds
tesseract.maximumRecognitionTime = 60.0;

// Start the recognition
[tesseract recognize];

// Retrieve the recognized text
NSLog(@"text %@", [tesseract recognizedText]);

1 个答案:

答案 0 :(得分:0)

preserve_interword_spaces 设置为 true 以保留单词之间的多个空格。

您的代码可能如下所示:

{
    "payload": {}
}

对于命令行界面,请以这种方式使用 tesseract.setVariable("preserve_interword_spaces", "1"); 开关:

-c

(来自有用评论的自愿回答;感谢用户 nguyenq)

相关问题