菜鸟教程小白 发表于 2022-12-11 19:30:15

ios - Tesseract OCR 无法识别从设备拍摄的图像


                                            <p><p>我正在使用 <a href="https://github.com/gali8/Tesseract-OCR-iOS/" rel="noreferrer noopener nofollow">https://github.com/gali8/Tesseract-OCR-iOS/</a> 制作一个检测名片上的文本的应用。 </p>

<p>我一直坚持让 Tesseract 检测图像中的文本。</p>

<p>如果我通过代码传递图像,Tesseract 能够检测到它。如果我提供从相机拍摄的图像,则 tesseract 无法识别它。 </p>

<pre><code>-(void)startTess:(UIImage *)img{

G8Tesseract *tesseract = [ initWithLanguage:@&#34;eng&#34;];
tesseract.delegate = self;
tesseract.engineMode=G8OCREngineModeTesseractCubeCombined;

// Optional: Limit the character set Tesseract should try to recognize from
tesseract.charWhitelist = @&#34;@.,()-,abcdefghijklmnopqrstuvwxyz0123456789&#34;;

// Specify the image Tesseract should recognize on
tesseract.image = ;

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

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

// Start the recognition
;

// Retrieve the recognized text
NSLog(@&#34;text %@&#34;, );

// You could retrieve more information about recognized text with that methods:
NSArray *characterBoxes = ;
NSArray *paragraphs = ;
NSArray *characterChoices = tesseract.characterChoices;
UIImage *imageWithBlocks = ;

self.imgView.image = imageWithBlocks;

NSString * result = [ componentsJoinedByString:@&#34;\n&#34;];

_txtView.text=result;


}
</code></pre>

<p>从 .xcassets 提供图像时的结果:</p>

<p> <a href="/image/lQXh9.jpg" rel="noreferrer noopener nofollow"><img src="/image/lQXh9.jpg" alt="enter image description here"/></a> </p>

<p>直接从相机拍摄图像时的结果:</p>

<p> <a href="/image/UsO9h.png" rel="noreferrer noopener nofollow"><img src="/image/UsO9h.png" alt="enter image description here"/></a> </p>

<p>在这两种情况下,Tesseract 都可以识别带有一些随机字符的空白空间。我在两张图片中都标记了该区域(图片的左上角)。</p>

<p>我确保从设备相机拍摄的图像具有向上的方向,因为一些报告称 Tesseract 无法识别从相机拍摄的图像,因为它具有 180 度偏移。 </p>

<pre><code>UIImage *chosenImage = info;

// Redraw the image (if necessary) so it has the corrent orientation:
if (chosenImage.imageOrientation != UIImageOrientationUp) {
    UIGraphicsBeginImageContextWithOptions(chosenImage.size, NO, chosenImage.scale);
    ;
    chosenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}
</code></pre>

<p>调试此问题并继续前进的最佳方法是什么?</p>

<p>我在 git 上提交了一个问题:
<a href="https://github.com/gali8/Tesseract-OCR-iOS/issues/358" rel="noreferrer noopener nofollow">https://github.com/gali8/Tesseract-OCR-iOS/issues/358</a> </p>

<p>编辑:</p>

<p>我已将迭代器级别更改为G8PageIteratorLevelTextline,现在设备相机拍摄的图像给出以下输出:</p>

<p> <a href="/image/vK0xV.jpg" rel="noreferrer noopener nofollow"><img src="/image/vK0xV.jpg" alt="enter image description here"/></a> </p>

<p>仍然不准确。如果有人可以指出如何改进这一点,那就太好了。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在 tesseract 的官方 github 源中,提到了各种预处理方法,除了这些措施,我建议使用 .tiff 图像而不是 .jpg 或 .png,因为使用除 tiff 之外的任何其他类型的图像会压缩图像并减少它将质量二值化。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Tesseract OCR 无法识别从设备拍摄的图像,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47946808/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47946808/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Tesseract OCR 无法识别从设备拍摄的图像