Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/python/mser.py
16337 views
1
#!/usr/bin/env python
2
3
'''
4
MSER detector demo
5
==================
6
7
Usage:
8
------
9
mser.py [<video source>]
10
11
Keys:
12
-----
13
ESC - exit
14
15
'''
16
17
import numpy as np
18
import cv2 as cv
19
import video
20
import sys
21
22
if __name__ == '__main__':
23
try:
24
video_src = sys.argv[1]
25
except:
26
video_src = 0
27
28
cam = video.create_capture(video_src)
29
mser = cv.MSER_create()
30
31
while True:
32
ret, img = cam.read()
33
if ret == 0:
34
break
35
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
36
vis = img.copy()
37
38
regions, _ = mser.detectRegions(gray)
39
hulls = [cv.convexHull(p.reshape(-1, 1, 2)) for p in regions]
40
cv.polylines(vis, hulls, 1, (0, 255, 0))
41
42
cv.imshow('img', vis)
43
if cv.waitKey(5) == 27:
44
break
45
cv.destroyAllWindows()
46
47