Improving the quality of the output

简介: There are a variety of reasons you might not get good quality output from Tesseract. It's important to note that unless you're using a very unusual fo...

There are a variety of reasons you might not get good quality output from Tesseract. It's important to note that unless you're using a very unusual font or a new language retraining Tesseract is unlikely to help.

Image processing

Tesseract does various image processing operations internally (using the Leptonica library) before doing the actual OCR. It generally does a very good job of this, but there will inevitably be cases where it isn't good enough, which can result in a significant reduction in accuracy.

You can see how Tesseract has processed the image by using the configuration variabletessedit_write_images to true when running Tesseract. If the resulting tessinput.tif file looks problematic, try some of these image processing operations before passing the image to Tesseract.

Rescaling

Tesseract works best on images which have a DPI of at least 300 dpi, so it may be beneficial to resize images. For more information see the FAQ.

Binarisation

binarisation.png

This is converting an image to black and white. Tesseract does this internally, but the result can be suboptimal, particularly if the page background is of uneven darkness.

Noise Removal

noise.png

Noise is random variation of brightness or colour in an image, that can make the text of the image more difficult to read. Certain types of noise cannot be removed by Tesseract in the binarisation step, which can cause accuracy rates to drop.

Rotation / Deskewing

skew-linedetection.png

A skewed image is when an page has been scanned when not straight. The quality of Tesseract's line segmentation reduces significantly if a page is too skewed, which severely impacts the quality of the OCR. To address this rotating the page image so that the text lines are horizontal.

Border Removal

borders.png

Scanned pages often have dark borders around them. These can be erroneously picked up as extra characters, especially if they vary in shape and gradation.

Tools / Libraries

Examples

If you need an example how to improve image quality programmatically, have a look at this examples:

Page segmentation method

By default Tesseract expects a page of text when it segments an image. If you're just seeking to OCR a small region try a different segmentation mode, using the -psm argument. Note that adding a white border to text which is too tightly cropped may also help, see issue 398.

To see a complete list of supported page segmentation modes, use tesseract -h. Here's the list as of 3.04:

 0   Orientation and script detection (OSD) only.
 1   Automatic page segmentation with OSD.
 2   Automatic page segmentation, but no OSD, or OCR.
 3   Fully automatic page segmentation, but no OSD. (Default)
 4   Assume a single column of text of variable sizes.
 5   Assume a single uniform block of vertically aligned text.
 6   Assume a single uniform block of text.
 7   Treat the image as a single text line.
 8   Treat the image as a single word.
 9   Treat the image as a single word in a circle.
10   Treat the image as a single character.
AI 代码解读

Dictionaries, word lists, and patterns

By default Tesseract is optimized to recognize sentences of words. If you're trying to recognize something else, like receipts, price lists, or codes, there are a few things you can do to improve the accuracy of your results, as well as double-checking that the appropriate segmentation method is selected.

Disabling the dictionaries Tesseract uses should increase recognition if most of your text isn't dictionary words. They can be disabled by setting the both of the configuration variablesload_system_dawg and load_freq_dawg to false.

It is also possible to add words to the word list Tesseract uses to help recognition, or to add common character patterns, which can further help to improve accuracy if you have a good idea of the sort of input you expect. This is explained in more detail in the Tesseract manual.

If you know you will only encounter a subset of the characters available in the language, such as only digits, you can use the tessedit_char_whitelist configuration variable. See the FAQ for an example.

Still having problems?

If you've tried the above and are still getting low accuracy results, ask on the forum for help, ideally posting an example image.

目录
打赏
0
0
0
0
52
分享
相关文章
ElasticSearch的简单介绍与使用【进阶检索】 实时搜索 | 分布式搜索 | 全文搜索 | 大数据处理 | 搜索过滤 | 搜索排序
这篇文章是Elasticsearch的进阶使用指南,涵盖了Search API的两种检索方式、Query DSL的基本语法和多种查询示例,包括全文检索、短语匹配、多字段匹配、复合查询、结果过滤、聚合操作以及Mapping的概念和操作,还讨论了Elasticsearch 7.x和8.x版本中type概念的变更和数据迁移的方法。
ElasticSearch的简单介绍与使用【进阶检索】 实时搜索 | 分布式搜索 | 全文搜索 | 大数据处理 | 搜索过滤 | 搜索排序
使用关系型数据库事务的例子
【5月更文挑战第12天】本文介绍了设置MySQL事务的三种方式:全局、当前session和下一个事务,并提供了示例代码展示如何开始事务和设置隔离级别。还简述了引擎设置和数据源DSN格式。最后,讨论了SQL优化策略,包括选择合适的存储引擎、优化字段数据类型、建立索引、避免全表扫描等。
364 4
使用关系型数据库事务的例子
容器化技术,特别是Docker,已经成为现代软件开发和部署的重要工具。
容器化技术,特别是Docker,已经成为现代软件开发和部署的重要工具。
准确写汉字的文生图AnyText,魔搭社区最佳实践来啦!
AnyText模型所涉及的文字生成技术为电商海报、Logo设计、创意涂鸦、表情包等新型AIGC应用提供了可能性。
记一个诡异的TCP挥手乱序问题
tcp四次挥手是超经典的网络知识,但是网络中的异常状况千奇百怪,说不定会“偷袭”到标准流程的盲区。最近笔者遇到了一个罕见的挥手乱序问题,经过对内核代码的分析和试验,最后终于找到了原因,角度可谓刁钻。本文从技术视角,将排查过程记录下来,既是对整个过程的小小总结,将事情彻底完结掉,也是对tcp实现的一些细节的学习记录。
137915 11
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问