11
11
def get_args ():
12
12
parser = argparse .ArgumentParser ("Image to ASCII" )
13
13
parser .add_argument ("--input" , type = str , default = "data/input.mp4" , help = "Path to input video" )
14
- parser .add_argument ("--output" , type = str , default = "data/output.avi " , help = "Path to output video" )
14
+ parser .add_argument ("--output" , type = str , default = "data/output.mp4 " , help = "Path to output video" )
15
15
parser .add_argument ("--mode" , type = str , default = "simple" , choices = ["simple" , "complex" ],
16
16
help = "10 or 70 different characters" )
17
17
parser .add_argument ("--background" , type = str , default = "white" , choices = ["black" , "white" ],
18
18
help = "background's color" )
19
19
parser .add_argument ("--num_cols" , type = int , default = 100 , help = "number of character for output's width" )
20
20
parser .add_argument ("--scale" , type = int , default = 1 , help = "upsize output" )
21
21
parser .add_argument ("--fps" , type = int , default = 0 , help = "frame per second" )
22
+ parser .add_argument ("--overlay_ratio" , type = float , default = 0.2 , help = "Overlay width ratio" )
22
23
args = parser .parse_args ()
23
24
return args
24
25
@@ -41,9 +42,9 @@ def main(opt):
41
42
num_chars = len (CHAR_LIST )
42
43
num_cols = opt .num_cols
43
44
while cap .isOpened ():
44
- flag , image = cap .read ()
45
+ flag , frame = cap .read ()
45
46
if flag :
46
- image = cv2 .cvtColor (image , cv2 .COLOR_BGR2GRAY )
47
+ image = cv2 .cvtColor (frame , cv2 .COLOR_BGR2GRAY )
47
48
else :
48
49
break
49
50
height , width = image .shape
@@ -81,6 +82,10 @@ def main(opt):
81
82
out = cv2 .VideoWriter (opt .output , cv2 .VideoWriter_fourcc (* "XVID" ), fps ,
82
83
((out_image .shape [1 ], out_image .shape [0 ])))
83
84
85
+ if opt .overlay_ratio :
86
+ height , width , _ = out_image .shape
87
+ overlay = cv2 .resize (frame , (int (width * opt .overlay_ratio ), int (height * opt .overlay_ratio )))
88
+ out_image [height - int (height * opt .overlay_ratio ):, width - int (width * opt .overlay_ratio ):, :] = overlay
84
89
out .write (out_image )
85
90
cap .release ()
86
91
out .release ()
0 commit comments