def main(STARTFRAME,ENDFRAME): t0 = time.time() if STARTFRAME <= FRAMEDELTA: # handle case where no prior frames exist to compare STARTFRAME = FRAMEDELTA + 1 cstartframe = STARTFRAME - FRAMEDELTA cendframe = ENDFRAME - FRAMEDELTA FileNames = libutil.get_file_names_for_framerange(STARTFRAME,ENDFRAME,IMGDIR,filter='.jpg') CompareFileNames = libutil.get_file_names_for_framerange(cstartframe,cendframe,IMGDIR,filter='.jpg') RefAndCompareFileNames = zip(FileNames,CompareFileNames) if STEPSIZE >1: RefAndCompareFileNames = RefAndCompareFileNames[::STEPSIZE] ChunksOfRefAndCompareFileNames = libutil.get_data_chunks(RefAndCompareFileNames,NPROCS) p = Pool(NPROCS) x = p.map(do_pixel_change_on_batch,ChunksOfRefAndCompareFileNames) aggregate_output() t1 = time.time() print "Time to run on %i cores: %5.2f" % (NPROCS,t1-t0)
def filter_file_names(): FileNames = libutil.get_file_names_for_framerange(STARTFRAME,ENDFRAME,IMGDIR,filter='.jpg') FilteredFileNames = [] for fn in FileNames: if FILTER in fn: FilteredFileNames.append(fn) FilteredFileNames.sort() return FilteredFileNames
def main(WINDOWSIZE, NIMG, IMGDIR, startindex, endindex): FileNames = libutil.get_file_names_for_framerange(startindex, endindex, IMGDIR, filter='.jpg') totalimages = len(FileNames) lastchunk = totalimages % WINDOWSIZE print FileNames bg_image_windows = [] window_start_index = 0 window_end_index = WINDOWSIZE # non-overlapping pass through frames while window_end_index < totalimages: print window_start_index, window_end_index bg_image_windows.append({ 'windowstart': window_start_index, 'windowend': window_end_index }) window_start_index += WINDOWSIZE window_end_index += WINDOWSIZE # create overlap window_start_index = WINDOWSIZE / 2 window_end_index = window_start_index + WINDOWSIZE while window_end_index < totalimages: bg_image_windows.append({ 'windowstart': window_start_index, 'windowend': window_end_index }) window_start_index += WINDOWSIZE window_end_index += WINDOWSIZE # handle the last few frames that are left when the number of images is not evenly # divisible by WINDOWSIZE if lastchunk != 0: window_start_index = totalimages - lastchunk window_end_index = totalimages - 1 bg_image_windows.append({ 'windowstart': window_start_index, 'windowend': window_end_index }) print bg_image_windows # create the background images for item in bg_image_windows: startindex = item['windowstart'] endindex = item['windowend'] build_startend(FileNames, IMGDIR, startindex, endindex)
def main(WINDOWSIZE,NIMG,IMGDIR,startindex,endindex): FileNames = libutil.get_file_names_for_framerange( startindex,endindex,IMGDIR,filter='.jpg') totalimages = len(FileNames) lastchunk = totalimages % WINDOWSIZE print FileNames bg_image_windows = [] window_start_index = 0 window_end_index = WINDOWSIZE # non-overlapping pass through frames while window_end_index < totalimages: print window_start_index,window_end_index bg_image_windows.append( {'windowstart':window_start_index,'windowend':window_end_index} ) window_start_index += WINDOWSIZE window_end_index += WINDOWSIZE # create overlap window_start_index = WINDOWSIZE/2 window_end_index = window_start_index + WINDOWSIZE while window_end_index < totalimages: bg_image_windows.append( {'windowstart':window_start_index,'windowend':window_end_index} ) window_start_index += WINDOWSIZE window_end_index += WINDOWSIZE # handle the last few frames that are left when the number of images is not evenly # divisible by WINDOWSIZE if lastchunk != 0: window_start_index = totalimages - lastchunk window_end_index = totalimages - 1 bg_image_windows.append( {'windowstart':window_start_index,'windowend':window_end_index} ) print bg_image_windows # create the background images for item in bg_image_windows: startindex = item['windowstart'] endindex = item['windowend'] build_startend(FileNames,IMGDIR,startindex,endindex)