@@ -125,7 +125,7 @@ def mg_motion_mp(args):
125
125
motion_frame_rgb = motion_frame
126
126
127
127
if save_video :
128
- # if this is not the first process (rendering the start of the video) then don't save the first frame of the output (it'll always be black).
128
+ # if this is not the first process (rendering the start of the video) then drop the first frame of the output (it'll always be black).
129
129
if process_id != 0 and ii > 0 :
130
130
if inverted_motionvideo :
131
131
out .write (cv2 .bitwise_not (
@@ -185,9 +185,7 @@ def mg_motion_mp(args):
185
185
186
186
def run_pool (func , args , numprocesses ):
187
187
pool = multiprocessing .Pool (numprocesses )
188
- # results = pool.map(func, args)
189
188
pool .map (func , args )
190
- # return results
191
189
192
190
193
191
def calc_frame_groups (framecount , num_cores ):
@@ -204,18 +202,6 @@ def calc_frame_groups(framecount, num_cores):
204
202
return groups
205
203
206
204
207
- def testhogfunc (process_id ):
208
- limit = 20
209
- count = 0
210
- while count < limit :
211
- print (process_id , count )
212
- futyi = 0
213
- for i in range (10_000_000 ):
214
- futyi += 1
215
- count += 1
216
- return process_id , count
217
-
218
-
219
205
def bool_from_str (boolstring ):
220
206
return True if boolstring == "True" else False
221
207
@@ -240,6 +226,7 @@ def bool_from_str(boolstring):
240
226
parser .add_argument ('save_data' , metavar = 'save_data' , type = str , help = 'save_data' )
241
227
parser .add_argument ('save_motiongrams' , metavar = 'save_motiongrams' , type = str , help = 'save_motiongrams' )
242
228
parser .add_argument ('save_video' , metavar = 'save_video' , type = str , help = 'save_video' )
229
+ parser .add_argument ('num_processes' , metavar = 'num_processes' , type = str , help = 'num_processes' )
243
230
244
231
args = parser .parse_args ()
245
232
@@ -257,21 +244,19 @@ def bool_from_str(boolstring):
257
244
fps , width , height , length = int (float (args .fps )), int (float (args .width )), int (float (args .height )), int (float (args .length ))
258
245
color , filtertype , thresh , blur , kernel_size = bool_from_str (args .color ), args .filtertype , float (args .thresh ), args .blur , int (float (args .kernel_size ))
259
246
inverted_motionvideo , inverted_motiongram , equalize_motiongram = bool_from_str (args .inverted_motionvideo ), bool_from_str (args .inverted_motiongram ), bool_from_str (args .equalize_motiongram )
260
- save_data , save_motiongrams , save_video = bool_from_str (args .save_data ), bool_from_str (args .save_motiongrams ), bool_from_str (args .save_video )
247
+ save_data , save_motiongrams , save_video = bool_from_str (args .save_data ), bool_from_str (args .save_motiongrams ), bool_from_str (args .save_video )
248
+ num_processes = multiprocessing .cpu_count () if int (float (args .num_processes )) < 1 else min (int (float (args .num_processes )), multiprocessing .cpu_count ())
261
249
262
- numprocessors = multiprocessing .cpu_count ()
263
- frame_groups = calc_frame_groups (length , numprocessors )
250
+ frame_groups = calc_frame_groups (length , num_processes )
264
251
265
252
feed_args = []
266
253
267
- for i in range (numprocessors ):
254
+ for i in range (num_processes ):
268
255
start_frame , num_frames = frame_groups [i ]
269
256
initargs = [target_folder , of , fex , fps , width , height , length , color , filtertype , thresh , blur , kernel_size , inverted_motionvideo , inverted_motiongram , equalize_motiongram , save_data , save_motiongrams , save_video , start_frame , num_frames , i , client ]
270
257
# client.sendall(bytes(str(initargs), 'utf-8'))
271
258
feed_args .append (initargs )
272
259
273
- # results = run_pool(mg_motion_mp, feed_args, numprocessors)
274
- run_pool (mg_motion_mp , feed_args , numprocessors )
260
+ run_pool (mg_motion_mp , feed_args , num_processes )
275
261
276
- client .close ()
277
- # print("Closed socket client.")
262
+ client .close ()
0 commit comments