Ask Your Question
0

How to use MSER in Python

asked Aug 17 '13

Koen Wildemeersch gravatar image

Hi all, I've used MSER from VLfeat toolbox (matlab) and noticed that open cv also has they same method available. From my search on this Q&A I'm sure it's available for C++ but I'm not sure if I can use in in python as well. Could anyone help me on this one? If it's possible, could you provide me with an example as I found nothing in the documentation.

Thank you very much!

Koen

Preview: (hide)

4 answers

Sort by » oldest newest most voted
1

answered Aug 17 '13

Guanta gravatar image
import cv2
img = cv2.imread('foo.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE);
mser = cv2.MSER()
mser_areas = mser.detect()

this returns list of list of points as described in the docu for the operator()http://docs.opencv.org/modules/features2d/doc/feature_detection_and_description.html?highlight=mser#mser.

You can also retrieve real keypoints (with associated size etc.) when you use it as feature detector:

fd = cv2.FeatureDetector_create('MSER')
kpts = fd.detect(img)

which you then can pass to a descriptor, which you can e.g. create via cv2.DescriptorExtractor_create("ORB").

Preview: (hide)

Comments

For: fd = cv2.FeatureDetector_create('MSER') I get: AttributeError: 'module' object has no attribute 'FeatureDetector_create' for opencv version '3.0.0', python 2.7.10

visoft gravatar imagevisoft (Nov 17 '15)edit
1

answered Nov 9 '15

Ayush_Sharma gravatar image
import cv2
img = cv2.imread('bed.jpg', 0);
vis = img.copy()
mser = cv2.MSER_create()
regions = mser.detectRegions(img, None)
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)
cv2.destroyAllWindows()

SOURCE : https://fossies.org/dox/opencv-3.0.0/...

The post above is old. This is how now MSER is used.

Preview: (hide)

Comments

1

old is a relative term, many systems, especially in robotics are still using opencv 2.4, mainly because Ubuntu doesn't integrate opencv3 yet as a package. Your answer is only valid for opencv 3. here is a comparison

Mehdi gravatar imageMehdi (Jun 30 '16)edit
0

answered May 14 '18

import cv2

img = cv2.imread(r'C:\2.png', 0)

vis = img.copy()

mser = cv2.MSER_create()

regions = mser.detectRegions(img)

hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions[0]]

cv2.polylines(vis, hulls, 1, (0, 255, 0))

cv2.imshow('img', vis)

cv2.waitKey(0)

cv2.destroyAllWindows()

Preview: (hide)
0

answered Nov 15 '16

hardfish82 gravatar image

For opencv 2.4:

import cv2
img = cv2.imread('bed.jpg', 0);
vis = img.copy()
mser = cv2.MSER()
regions = mser.detect(img, None)
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)
cv2.destroyAllWindows()
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Aug 17 '13

Seen: 30,109 times

Last updated: May 14 '18