-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass_2.py
49 lines (37 loc) · 1.4 KB
/
pass_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from vb_lib import *
import cv2
import pickle
import sys
def main(src, sk):
reader = VideoReader(src, read_sk=sk)
best_ball = reader.load_obj('best_ball')
background = reader.read_image('bg')
#for (count, frame, fgmask) in reader.read():
# if count > best_ball.get_last_frame():
# best_ball.mean_shift()
# best_ball.draw(frame)
for (count, frame, fgmask) in reader.read():
mask = best_ball.circle_contour_mask(count, -9)
masked_ball = cv2.bitwise_or(frame, frame, mask=mask)
mask = cv2.bitwise_not(mask)
masked_bg = cv2.bitwise_or(background, background, mask=mask)
background = cv2.bitwise_or(masked_ball, masked_bg)
reader.write_image(background, 'ball_only')
def usage():
print 'Usage: %s file_name ' % (re.sub('^.*/','',sys.argv[0]))
print ' file_name: The name of the video in the res folder without .mp4 extension'
print ' -s: Use the skvideo vreader (default is opencv VideoCapture)'
print ' '
print ' Outputs only the top ball candidate moving on the background'
print ' '
print '\n'
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 's')
if len(args) is not 1:
usage()
sys.exit(1)
main(args[0], ('-s', '') in opts)
except getopt.GetoptError:
usage()
sys.exit(1)