mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
camshift.py description
This commit is contained in:
parent
714732e9bb
commit
02788eb32e
@ -1,16 +1,29 @@
|
|||||||
|
'''
|
||||||
|
Camshift tracker
|
||||||
|
================
|
||||||
|
|
||||||
|
This is a demo that shows mean-shift based tracking
|
||||||
|
You select a color objects such as your face and it tracks it.
|
||||||
|
This reads from video camera (0 by default, or the camera number the user enters)
|
||||||
|
|
||||||
|
http://www.robinhewitt.com/research/track/camshift.html
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
------
|
||||||
|
camshift.py [<video source>]
|
||||||
|
|
||||||
|
To initialize tracking, select the object with mouse
|
||||||
|
|
||||||
|
Keys:
|
||||||
|
-----
|
||||||
|
ESC - exit
|
||||||
|
b - toggle back-projected probability visualization
|
||||||
|
'''
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
import video
|
import video
|
||||||
|
|
||||||
help_message = '''USAGE: camshift.py [<video source>]
|
|
||||||
|
|
||||||
Select a bright colored object to track.
|
|
||||||
|
|
||||||
Keys:
|
|
||||||
ESC - exit
|
|
||||||
b - toggle back-projected probability visualization
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
class App(object):
|
class App(object):
|
||||||
def __init__(self, video_src):
|
def __init__(self, video_src):
|
||||||
@ -99,6 +112,6 @@ if __name__ == '__main__':
|
|||||||
import sys
|
import sys
|
||||||
try: video_src = sys.argv[1]
|
try: video_src = sys.argv[1]
|
||||||
except: video_src = 0
|
except: video_src = 0
|
||||||
print help_message
|
print __doc__
|
||||||
App(video_src).run()
|
App(video_src).run()
|
||||||
|
|
||||||
|
@ -124,12 +124,12 @@ class App:
|
|||||||
text.tag_add(tag, start, end)
|
text.tag_add(tag, start, end)
|
||||||
self.match_text(r'http://\S+', add_link)
|
self.match_text(r'http://\S+', add_link)
|
||||||
|
|
||||||
def match_text(self, pattern, tag_proc):
|
def match_text(self, pattern, tag_proc, regexp=True):
|
||||||
text = self.text
|
text = self.text
|
||||||
text.mark_set('matchPos', '1.0')
|
text.mark_set('matchPos', '1.0')
|
||||||
count = tk.IntVar()
|
count = tk.IntVar()
|
||||||
while True:
|
while True:
|
||||||
match_index = text.search(pattern, 'matchPos', count=count, regexp=True, stopindex='end')
|
match_index = text.search(pattern, 'matchPos', count=count, regexp=regexp, stopindex='end')
|
||||||
if not match_index: break
|
if not match_index: break
|
||||||
end_index = text.index( "%s+%sc" % (match_index, count.get()) )
|
end_index = text.index( "%s+%sc" % (match_index, count.get()) )
|
||||||
text.mark_set('matchPos', end_index)
|
text.mark_set('matchPos', end_index)
|
||||||
|
Loading…
Reference in New Issue
Block a user