def main(argv): # parse input arguments parser = argparse.ArgumentParser() parser.add_argument('-i', '--input', help="the input YAML configuration file") parser.add_argument('-s', '--serial', help="run in serial mode", action="store_true") args = parser.parse_args() batchStart = time.time() Logger.logPrint("Starting batchprocess: "+args.input) Logger.logPrint("Start time:"+timeStr(batchStart)) # load WormVideo to YAML configuration file with open(args.input, 'r') as f: wvs = wtc.loadWormVideos(f) # run analysis on regions if args.serial: for wv in wvs: wv.processRegions() else: wtp.batchProcessVideos(wvs) batchStop = time.time() Logger.logPrint("Start time:"+timeStr(batchStart)) Logger.logPrint("End time :"+timeStr(batchStop)) Logger.logPrint("Total time:"+timeStr(batchStop-batchStart)) return 'Success'
The config file specifies all the parameters for analyzing a video. NOTE: In the config file, edit the hdf5path if hdf5 tools are not on your system path (h5copy is called at the end of parallel analysis) Also, edit the storeFile and videoFile paths at the end The directory for the store file needs to already exist """ configFile = './sample/short_test.yml' # load the WormVideo object using the config module import wormtracker.config as wtc with open(configFile, 'r') as f: wvs = wtc.loadWormVideos(f) # a config file can specify multiple videos, # but here there's only one wv = wvs[0] # run the analysis in serial wv.processRegions() # run postprocessing import h5py import wormtracker.postprocess as wtp with h5py.File(wv.storeFile, 'r+') as f: strains = f['worms'].keys() for strain in strains: worms = f['worms'][strain].keys() for worm in worms:
import os os.chdir('D:\\Stephen\\Documents\\Code\\wormtracker-matlab\\python') import wormtracker as wt import wormtracker.config as wtc import wormtracker.parallel as wtp import cProfile import pstats import glob testDir = 'D:\\wormTest' outDir = 'out' configFile = 'short_test.yml' with open(os.path.join(testDir, configFile), 'r') as f: wvs = wtc.loadWormVideos(f) # take only the first wv = wvs[0] def test(): wv.regions[0].process() if __name__ == "__main__": for f in glob.glob(os.path.join(os.path.join(testDir, outDir), '*.*')): os.remove(f) cProfile.run('test()', 'region') with open(os.path.join(testDir, 'profiling.txt'), 'w+') as f: stats = pstats.Stats('region', stream=f) stats.strip_dirs()