【问题标题】:MSER Feature extraction in Python 3.5Python 3.5 中的 MSER 特征提取
【发布时间】:2017-07-22 11:21:25
【问题描述】:

我想从 python3.5 中的图像中提取 MSER 特征,但我找不到任何解决方案。我正在尝试以下代码:

import cv2
import sys

mser = cv2.MSER_create()
img = cv2.imread('signboard.jpg')
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]
cv2.polylines(vis, hulls, 1, (0, 255, 0))

cv2.imshow('img', vis)

if cv2.waitKey(0) == 9:
    cv2.destroyAllWindows()

但在 mser.detectRegions 中出现错误。 任何人都可以分享python3.5中MSER的工作代码吗?

【问题讨论】:

    标签: python mser


    【解决方案1】:

    你可以试试这个:

    import cv2
    import numpy as np
    
    img = cv2.imread('adhr/adhr/front6.jpg')
    mser = cv2.MSER_create()
    
    #Resize the image so that MSER can work better
    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))
    
    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)
    
    text_only = cv2.bitwise_and(img, img, mask=mask)
    print text_only
    
    
    cv2.namedWindow('img', 0)
    cv2.imshow('img', vis)
    while(cv2.waitKey()!=ord('q')):
        continue
    cv2.destroyAllWindows()
    

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 2017-05-28
      • 2017-12-05
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多