MSER 文本检测问题

MSER text detection issue

我尝试使用MSER算法进行文本检测。我使用此代码:

import cv2
import numpy as np

#Create MSER object
mser = cv2.MSER_create()

#Your image path i-e receipt path
img = cv2.imread('test.jpg')

#Convert to gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

vis = img.copy()

#detect regions in gray scale image
regions, _ = mser.detectRegions(gray)

hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]

cv2.polylines(vis, hulls, 1, (0, 255, 0))

cv2.imshow('img', vis)

cv2.waitKey(0)

mask = np.zeros((img.shape[0], img.shape[1], 1), dtype=np.uint8)

for contour in hulls:

    cv2.drawContours(mask, [contour], -1, (255, 255, 255), -1)

#this is used to find only text regions, remaining are ignored
text_only = cv2.bitwise_and(img, img, mask=mask)

cv2.imshow("text only", text_only)

cv2.waitKey(0)

但我得到了非常有趣的结果。 MSER 无法检测图像上的所有文本。

测试图片:

结果图片:

我做错了什么?

OpenCV 文本模块包含几种文本检测方法。对于您的示例,最简单的方法是 ERFilterNM - python example。 png 屏幕检测结果见: 参数:

er1 = cv.text.createERFilterNM1(erc1,6,0.00005f,0.08f,0.2f,true,0.1f)
er2 = cv.text.createERFilterNM2(erc1,0.15)