合并 MSER 中的区域以识别 OCR 中的文本行 [英] Merging regions in MSER for identifying text lines in OCR

查看:98
本文介绍了合并 MSER 中的区域以识别 OCR 中的文本行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MSER 来识别 MSER 中的文本区域.我正在使用以下代码提取区域并将它们保存为图像.目前,每个识别的区域都保存为单独的图像.但是,我想合并属于作为单个图像合并的一行文本的区域.

I am using MSER to identify text regions in MSER. I am using the following code to extract the regions and save them as an image. Currently, each identified region is saved as a separate image. But, I want to merge regions belonging to a line of text merged as a single image.

import cv2

img = cv2.imread('newF.png')
mser = cv2.MSER_create()


img = cv2.resize(img, (img.shape[1]*2, img.shape[0]*2))

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
vis = img.copy()

regions = mser.detectRegions(gray)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions[0]]
cv2.polylines(vis, hulls, 1, (0,255,0)) 

如何将属于单行的图像拼接在一起?我得到的逻辑主要是基于一些启发式方法来识别具有附近 y 坐标的区域.

How can I stitch the images that belong to a single line together? I get the logic to do will mostly be based on some heuristic for identifying areas with nearby y-coordinates.

但是如何在 OpenCV 中准确地合并区域.我错过了这一点,因为我是 openCV 的新手.任何帮助将不胜感激.

But how exactly the regions can be merged in OpenCV. I am missing out on this as I am new to openCV. Any help would be appreciated.

附上示例图片

所需的输出如下

另一行

另一行

推荐答案

也许像 dilate-erode 这样原始的东西可以在你的情况下工作?例如,如果我在原始图像上使用 erode 操作,然后是 dilate 操作,并且主要是在水平方向上,例如.:

Maybe even something as primitive as dilate-erode could be made work in your case? For example, if I use erode operation followed by dilate operation on your original image, and mostly in horizontal direction, e. g.:

img = cv2.erode(img, np.ones((1, 20)))
img = cv2.dilate(img, np.ones((1, 22)))

结果类似于:

所以如果我们把它画在原始图像上,它就会变成:

So if we draw that over the original image, it becomes:

我没有像你那样调整原始图像的大小(可能是为了检测那些小的独立点和东西).不理想(我不知道 MSER 是如何工作的),但是通过足够的调整,也许您甚至可以使用简单的连接组件检测?

I didn't resize the original image as you do (probably to detect those small separate dots and stuff). Not ideal (I don't know how MSER works), but with enough tweaking maybe you could even use simple detection of connected components with this?

这篇关于合并 MSER 中的区域以识别 OCR 中的文本行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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