@@ -43,6 +43,8 @@ def get_affine_matrix(center, translate, scale):
43
43
44
44
45
45
class BaseStreamer ():
46
+ """This streamer will return images at 512x512 size.
47
+ """
46
48
def __init__ (self ,
47
49
width = 512 , height = 512 , pad = True ,
48
50
mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
@@ -76,6 +78,8 @@ def __len__(self):
76
78
77
79
78
80
class CaptureStreamer (BaseStreamer ):
81
+ """This streamer takes webcam as input.
82
+ """
79
83
def __init__ (self , id = 0 , width = 512 , height = 512 , pad = True , ** kwargs ):
80
84
super ().__init__ (width , height , pad , ** kwargs )
81
85
self .capture = cv2 .VideoCapture (id )
@@ -94,6 +98,8 @@ def __del__(self):
94
98
95
99
96
100
class VideoListStreamer (BaseStreamer ):
101
+ """This streamer takes a list of video files as input.
102
+ """
97
103
def __init__ (self , files , width = 512 , height = 512 , pad = True , ** kwargs ):
98
104
super ().__init__ (width , height , pad , ** kwargs )
99
105
self .files = files
@@ -115,6 +121,8 @@ def __del__(self):
115
121
116
122
117
123
class ImageListStreamer (BaseStreamer ):
124
+ """This streamer takes a list of image files as input.
125
+ """
118
126
def __init__ (self , files , width = 512 , height = 512 , pad = True , ** kwargs ):
119
127
super ().__init__ (width , height , pad , ** kwargs )
120
128
self .files = files
@@ -129,53 +137,4 @@ def __len__(self):
129
137
return len (self .files )
130
138
131
139
132
- if __name__ == "__main__" :
133
- import tqdm
134
- import argparse
135
-
136
- parser = argparse .ArgumentParser (description = '.' )
137
- parser .add_argument (
138
- '--camera' , action = "store_true" )
139
- parser .add_argument (
140
- '--images' , default = "" , nargs = "*" )
141
- parser .add_argument (
142
- '--videos' , default = "" , nargs = "*" )
143
- parser .add_argument (
144
- '--loop' , action = "store_true" )
145
- args = parser .parse_args ()
146
-
147
- def visulization (data ):
148
- window = data [0 ].numpy ()
149
- window = window .transpose (1 , 2 , 0 )
150
- window = (window * 0.5 + 0.5 ) * 255.0
151
- window = np .uint8 (window )
152
- window = cv2 .cvtColor (window , cv2 .COLOR_BGR2RGB )
153
- window = cv2 .resize (window , (0 , 0 ), fx = 2 , fy = 2 )
154
-
155
- cv2 .imshow ('window' , window )
156
- cv2 .waitKey (1 )
157
-
158
- if args .camera :
159
- data_stream = CaptureStreamer ()
160
- elif len (args .videos ) > 0 :
161
- data_stream = VideoListStreamer (args .videos * (100 if args .loop else 1 ))
162
- elif len (args .images ) > 0 :
163
- data_stream = ImageListStreamer (args .images * (100 if args .loop else 1 ))
164
-
165
- loader = torch .utils .data .DataLoader (
166
- data_stream ,
167
- batch_size = 1 ,
168
- num_workers = 1 ,
169
- pin_memory = False ,
170
- )
171
-
172
- try :
173
- for data in tqdm .tqdm (loader ):
174
- visulization (data )
175
- pass
176
- except Exception as e :
177
- print (e )
178
- del data_stream
179
-
180
-
181
140
0 commit comments