python - MSER 文本检测问题

标签 python opencv mser

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

测试图像:
Test image

结果图片:
enter image description here

我究竟做错了什么?

最佳答案

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

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

关于python - MSER 文本检测问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417410/

相关文章:

c++ - 如何使用 OpenCV 计算图像的结构张量

matlab - 控制 MATLAB 中 MSERRegions.plot() 使用的颜色?

python - 如何使用Python和OpenCV实现BRISK检测特征?

python - 如何用 Python 伪造类型

赋值中的Python字典get方法

python - mjpeg @ 0x27ee9e0 缓冲区小于最小大小 : How to create a video file with size less than the minimum buffer size?

matlab - MSER特征的匹配算法?

python - 返回类的初始化值(如果属于同一类)的最佳 python 方法

python - tensorflow 导入错误。不包含/Library/Python/2.7/site-packages

Opencv:cv2.findContours 修改已经绘制的图像?