使用OpenCV OCR锐化图像 [英] Sharpening image using OpenCV OCR

查看:298
本文介绍了使用OpenCV OCR锐化图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试处理图像处理脚本/OCR,这将允许我从下图中的框中提取字母(使用tesseract).

I've been trying to work on an image processing script /OCR that will allow me to extract the letters (using tesseract) from the boxes found in the image below.

经过大量处理,我能够使图片看起来像这样

Following alot of processing, I was able to get the picture to look like this

为了消除噪声,我对图像进行了反转,然后进行泛洪和高斯模糊处理以消除噪声.这是我接下来要讲的.

In order to remove the noise I inverted the image followed by floodfilling and gaussian blurring to remove noise. This is what I ended up with next.

在通过一些阈值和腐蚀去除噪声后(侵蚀是使文本失真的一步),在通过tesseract运行图像之前,我能够使图像看起来像这样

After running it through some threholding and erosion to remove the noise (erosion being the step that distorted the text) I was able to get the image to look like this before running it through tesseract

尽管效果不错,但可以通过tesseract获得相当准确的结果.尽管有时它会失败,因为它会将哈希(#)读为H或W.这使我想到了我的问题!

This, while a pretty good rendering, allows for fairly accurate results through tesseract. Though it sometimes fails because it reads the hash (#) as a H or W. This leads me to my question!

有没有办法使用opencv,skimage,PIL(最好是opencv),我可以锐化此图像,以增加tesseract正确读取我的图像的机会?还是有一种方法可以使我从第三张图像过渡到最终图像而不必使用侵蚀,而侵蚀最终会使图像中的文本变形.

Is there a way using opencv, skimage, PIL (opencv preferably) I can sharpen this image in order to increase my chances of tesseract properly reading my image? OR Is there a way I can get from the third to final image WITHOUT having to use erosion which ultimately distorted the text in the image.

任何帮助将不胜感激!

推荐答案

OpenCV确实具有类似 filter2D 可将任意内核与给定图像进行卷积.特别是,您可以使用用于图像锐化的内核.主要问题是,这是否会改善OCR库的结果.图像已经非常清晰,图像中的噪点不是模糊造成的.我本人从未与teseract一起工作过,但我相当确定它已经完成了所有可能的降噪工作.在这个过程中帮助"他实际上可能产生相反的效果.例如,任何锐化过程都倾向于放大噪声(与通常使图像模糊的降噪过程相反).当提供原始(未处理的)图像时,大多数计算机视觉库都可以提供更好的结果.

OpenCV does has functions like filter2D that convolves arbitrary kernel with given image. In particular you can use kernels that are used for image sharpening. The main question is whether this will improve the results of your OCR library or not. The image is already pretty sharp and the noise in the image is not a result of blur. I never worked with teseract myself, but I am fairly sure that it already does all the noise reduction it could. And 'helping' him in this process may actually have opposite effect. For example any sharpening process tends to amplify noise (as opposite to noise reduction processes that usually are blurring images). Most of computer vision libraries give better results when provided with raw (unprocessed) images.

编辑(问题更新后): 有多种方法可以做到这一点.我要测试的第一个图像是:您的第一个二进制图像非常干净清晰.与其使用降低字母质量的形态学运算,不如改用过滤轮廓.使用 findContours 函数可在图像并存储其层次结构(即哪个轮廓在其中).从所有找到的轮廓中,您实际上只需要第一和第二级轮廓,即每个字母的内轮廓和内轮廓(零级轮廓是最外轮廓).其他轮廓可以丢弃.在属于第一级的轮廓中,您可以丢弃那些边界框太小而不能成为真实字母的轮廓.经过这两个丢弃程序,我希望剩下的大部分轮廓都是字母的一部分.在白色图像上绘制它们并运行OCR. (如果要在黑色背景上使用白色字母,则需要反转轮廓中的顶点顺序.)

Edit (after question update): There multiple ways to do so. The first one that I would test is this: Your first binary image is pretty clean and sharp. Instead of of using morphological operations that reduce quality of letters switch to filtering contours. Use findContours function to find all contours in the image and store their hierarchy (i.e. which contour is inside which). From all the found contours you actually need only the contours on first and second levels, i.e. outer and inner contours of each letter (contours at zero level are the outermost contours). Other contours can be discarded. Among the contours that do belong to first level you can discard those whose bounding box is too small to be a real letter. After those two discarding procedures I would expect that most of the remaining contours are the ones that are parts of the letters. Draw them on white image and run OCR. (If you want white letters on black background you will need to invert the order of vertices in the contours).

这篇关于使用OpenCV OCR锐化图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆