mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
791 B
43 lines
791 B
12 years ago
|
#!/usr/bin/env python
|
||
12 years ago
|
|
||
12 years ago
|
'''
|
||
|
MSER detector demo
|
||
|
==================
|
||
|
|
||
|
Usage:
|
||
|
------
|
||
|
mser.py [<video source>]
|
||
|
|
||
|
Keys:
|
||
|
-----
|
||
|
ESC - exit
|
||
|
|
||
|
'''
|
||
|
|
||
|
import numpy as np
|
||
|
import cv2
|
||
|
import video
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
import sys
|
||
12 years ago
|
try:
|
||
|
video_src = sys.argv[1]
|
||
|
except:
|
||
|
video_src = 0
|
||
12 years ago
|
|
||
|
cam = video.create_capture(video_src)
|
||
10 years ago
|
mser = cv2.MSER_create()
|
||
12 years ago
|
while True:
|
||
|
ret, img = cam.read()
|
||
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||
|
vis = img.copy()
|
||
|
|
||
10 years ago
|
regions = mser.detectRegions(gray, None)
|
||
12 years ago
|
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 0xFF & cv2.waitKey(5) == 27:
|
||
|
break
|
||
|
cv2.destroyAllWindows()
|