首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么要在检测文本之前重塑MSER轮廓?

为什么要在检测文本之前重塑MSER轮廓?
EN

Stack Overflow用户
提问于 2019-08-27 11:40:37
回答 1查看 340关注 0票数 1

我使用来自opencv的MSER来使用这个stackoverflow question的代码来检测文本。有人能帮我理解为什么在计算物体的凸壳之前,轮廓p被重塑为(-1,1,2)吗?

守则如下:

代码语言:javascript
复制
import cv2
import numpy as np

#Create MSER object
mser = cv2.MSER_create()

#Your image path i-e receipt path
img = cv2.imread('/home/rafiullah/PycharmProjects/python-ocr-master/receipts/73.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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-27 17:01:58

--不管你是否重塑了。--

重塑是没有必要的。cv2.convexHull()可以采用任何一种输入格式。以下图像表明,无论contours中的regions是否被重塑,结果都是相同的。

代码语言:javascript
复制
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
hulls1 = [cv2.convexHull(p) for p in regions]

这就是p轮廓在重塑时的变化方式:

代码语言:javascript
复制
>>> p
array([[305, 382],
       [306, 382],
       [308, 380],
       [309, 380]...


>>> p.reshape(-1, 1, 2)
array([[[305, 382]],    
       [[306, 382]],    
       [[308, 380]],    
       [[309, 380]]...
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57673903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档