Ask Your Question
0

How to use MSER in Python

asked 2013-08-17 06:37:36 -0600

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

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
1

answered 2013-08-17 08:36:06 -0600

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").

edit flag offensive delete link more

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 ( 2015-11-17 04:58:23 -0600 )edit
1

answered 2015-11-09 15:12:04 -0600

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.

edit flag offensive delete link more

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 ( 2016-06-30 09:33:51 -0600 )edit
0

answered 2018-05-14 00:07:17 -0600

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()

edit flag offensive delete link more
0

answered 2016-11-14 19:51:19 -0600

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()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-08-17 06:37:36 -0600

Seen: 29,343 times

Last updated: May 14 '18