• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3'''
4MSER detector demo
5==================
6
7Usage:
8------
9    mser.py [<video source>]
10
11Keys:
12-----
13    ESC   - exit
14
15'''
16
17import numpy as np
18import cv2
19import video
20
21if __name__ == '__main__':
22    import sys
23    try:
24        video_src = sys.argv[1]
25    except:
26        video_src = 0
27
28    cam = video.create_capture(video_src)
29    mser = cv2.MSER_create()
30    while True:
31        ret, img = cam.read()
32        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
33        vis = img.copy()
34
35        regions = mser.detectRegions(gray, None)
36        hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]
37        cv2.polylines(vis, hulls, 1, (0, 255, 0))
38
39        cv2.imshow('img', vis)
40        if 0xFF & cv2.waitKey(5) == 27:
41            break
42    cv2.destroyAllWindows()
43