comparison scripts/process.py @ 1014:026f6b3b122c

Moving pull request2
author Wendlasida
date Fri, 01 Jun 2018 17:32:52 -0400
parents 75af46516b2b
children 75601be6019f
comparison
equal deleted inserted replaced
1013:d6f121ded971 1014:026f6b3b122c
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 import sys, argparse 3 import sys, argparse
4 from pathlib2 import Path 4 from pathlib import Path
5 5
6 import matplotlib 6 import matplotlib
7 matplotlib.use('Agg') 7 matplotlib.use('Agg')
8 import matplotlib.pyplot as plt 8 import matplotlib.pyplot as plt
9 from numpy import percentile 9 from numpy import percentile
12 from metadata import * 12 from metadata import *
13 13
14 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.') 14 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.')
15 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True) 15 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True)
16 parser.add_argument('--videos', dest = 'videoIds', help = 'indices of the video sequences', nargs = '*', type = int) 16 parser.add_argument('--videos', dest = 'videoIds', help = 'indices of the video sequences', nargs = '*', type = int)
17 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file')
17 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects/interactions to process', type = int) 18 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects/interactions to process', type = int)
18 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps', 'mp']) 19 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps', 'mp'])
19 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') 20 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true')
21 # override other tracking config, erase sqlite?
20 parser.add_argument('--delete', dest = 'delete', help = 'data to delete', choices = ['feature', 'object', 'classification', 'interaction']) 22 parser.add_argument('--delete', dest = 'delete', help = 'data to delete', choices = ['feature', 'object', 'classification', 'interaction'])
21 parser.add_argument('--process', dest = 'process', help = 'data to process', choices = ['feature', 'object', 'classification', 'interaction']) 23 parser.add_argument('--process', dest = 'process', help = 'data to process', choices = ['feature', 'object', 'classification', 'interaction'])
24 parser.add_argument('--display', dest = 'display', help = 'data to display (replay over video)', choices = ['feature', 'object', 'classification', 'interaction'])
22 parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction']) 25 parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction'])
23 26
24 # need way of selecting sites as similar as possible to sql alchemy syntax 27 # need way of selecting sites as similar as possible to sql alchemy syntax
25 # override tracking.cfg from db 28 # override tracking.cfg from db
26 # manage cfg files, overwrite them (or a subset of parameters) 29 # manage cfg files, overwrite them (or a subset of parameters)
27 # delete sqlite files 30 # delete sqlite files
31
32 # info of metadata
28 33
29 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) 34 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1)
30 35
31 args = parser.parse_args() 36 args = parser.parse_args()
32 # files are relative to metadata location 37 # files are relative to metadata location
39 #parser.add_argument('-t', dest = 'dataType', help = 'type of the data to remove', required = True, choices = ['object','interaction', 'bb', 'pois', 'prototype']) 44 #parser.add_argument('-t', dest = 'dataType', help = 'type of the data to remove', required = True, choices = ['object','interaction', 'bb', 'pois', 'prototype'])
40 for videoId in args.videoIds: 45 for videoId in args.videoIds:
41 vs = session.query(VideoSequence).get(videoId) 46 vs = session.query(VideoSequence).get(videoId)
42 storage.deleteFromSqlite(str(parentDir/vs.getDatabaseFilename()), args.delete) 47 storage.deleteFromSqlite(str(parentDir/vs.getDatabaseFilename()), args.delete)
43 48
44 if args.process == 'interaction': 49 if args.process in ['feature', 'object']: # tracking
50 for videoId in args.videoIds:
51 vs = session.query(VideoSequence).get(videoId)
52 if args.configFilename is None:
53 configFilename = vs.cameraView.getTrackingConfigurationFilename()
54 else:
55 configFilename = args.configFilename
56 #todo cvutils.tracking(configFilename, args.process == 'object', str(parentDir/vs.getVideoSequenceFilename(), str(parentDir/vs.getDatabaseFilename(), configFilename = vs.cameraView.getHomographyFilename())
57
58 elif args.process == 'interaction':
45 # safety analysis TODO make function in safety analysis script 59 # safety analysis TODO make function in safety analysis script
46 if args.predictionMethod == 'cvd': 60 if args.predictionMethod == 'cvd':
47 predictionParameters = prediction.CVDirectPredictionParameters() 61 predictionParameters = prediction.CVDirectPredictionParameters()
48 if args.predictionMethod == 'cve': 62 if args.predictionMethod == 'cve':
49 predictionParameters = prediction.CVExactPredictionParameters() 63 predictionParameters = prediction.CVExactPredictionParameters()