我正在尝试使用Tesseract OCR获取下面图像上的读数,但在获得与斑点背景一致的结果时遇到了问题。我的PyteSeract上有以下配置
CONFIG = f"—psm 6 -c tessedit_char_whitelist=01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄabcdefghijklmnopqrstuvwxyzåäö.,-"
我也尝试了下面的图像预处理,取得了一些不错的效果,但仍然没有完美的效果
blur = cv2.blur(img,(4,4))
(T, threshInv) = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
我想要的是始终能够识别数字和小数分隔符。什么图像预处理有助于在以下图像上获得一致的结果
这是一个挑战,但我认为我有一个有趣的方法:模式匹配
如果你放大,你会发现背面的图案只有4个可能的点,一个完整的像素,一个完整的双像素和一个中等左右的双像素。所以我所做的就是从17.160.000,00的图片中抓取这4种图案,然后开始工作。保存这些以便再次加载,我只是在飞行中抓住了它们
实际模式匹配
接下来,我们匹配所有模式和阈值以查找所有出现的情况,我使用了0.7,但您可以稍微使用它。这些图案去掉了侧面的一些像素,只匹配左侧的一个单像素,因此我们在前3个图案中填充两次(一个带有额外的一个)以同时命中这两个像素。最后一个是单个像素,因此它不需要它
编辑图像
现在唯一要做的就是从图像中删除所有匹配项。因为我们有一个大部分是白色的后卫,我们只是把他们设置为255来融入
输出
编辑:
请看一看抽象答案,以改进此输出和tesseract微调
您可以使用稍微复杂一点的方法,通过在频域而不是空间域中进行滤波来找到解决方案。阈值可能需要一些调整,具体取决于tesseract对输出图像的执行情况
实施:
输出:
中值模糊实现:
输出:
最终编辑:
因此,使用Eumel的解决方案,并在其底部结合这段代码,可获得100%的成功结果:
输出图像示例:
将tesseract字符列入白名单似乎对防止错误识别也有很大帮助
相关问题 更多 >
编程相关推荐