0

我尝试使用 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 无法检测图像上的所有文本。

测试图像: 测试图像

结果图片: 在此处输入图像描述

我究竟做错了什么?

4

1 回答 1

1

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

er1 = cv.text.createERFilterNM1(erc1,6,0.00005f,0.08f,0.2f,true,0.1f)
er2 = cv.text.createERFilterNM2(erc1,0.15)
于 2019-01-29T11:31:21.947 回答