2017-07-22 13 views
1

python3.5でイメージからMSERフィーチャーを抽出したいが、解決策が見つかりません。私は次のコードを試しています:Python 3.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の作業コードを共有できますか?

答えて

0

あなたはこれを試すことができます。

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() 
関連する問題