comparison scripts/process.py @ 1065:d4d052a05337

added progress report functionality
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 16 Jul 2018 00:05:17 -0400
parents cbc026dacf0b
children 862b55a87e63
comparison
equal deleted inserted replaced
1064:cbc026dacf0b 1065:d4d052a05337
87 for videoId in args.videoIds: 87 for videoId in args.videoIds:
88 if '-' in videoId: 88 if '-' in videoId:
89 videoSequences.extend([session.query(VideoSequence).get(i) for i in moving.TimeInterval.parse(videoId)]) 89 videoSequences.extend([session.query(VideoSequence).get(i) for i in moving.TimeInterval.parse(videoId)])
90 else: 90 else:
91 videoSequences.append(session.query(VideoSequence).get(int(videoId))) 91 videoSequences.append(session.query(VideoSequence).get(int(videoId)))
92 videoSequences = [vs for vs in videoSequences if vs is not None]
92 sites = set([vs.cameraView.site for vs in videoSequences]) 93 sites = set([vs.cameraView.site for vs in videoSequences])
93 elif args.siteIds is not None: 94 elif args.siteIds is not None:
94 for siteId in args.siteIds: 95 for siteId in args.siteIds:
95 if '-' in siteId: 96 if '-' in siteId:
96 sites.extend([session.query(Site).get(i) for i in moving.TimeInterval.parse(siteId)]) 97 sites.extend([session.query(Site).get(i) for i in moving.TimeInterval.parse(siteId)])
97 else: 98 else:
98 sites.append(session.query(Site).get(int(siteId))) 99 sites.append(session.query(Site).get(int(siteId)))
100 sites = [s for s in sites if s is not None]
99 for site in sites: 101 for site in sites:
100 videoSequences.extend(getSiteVideoSequences(site)) 102 videoSequences.extend(getSiteVideoSequences(site))
101 else: 103 else:
102 print('No video/site to process') 104 print('No video/site to process')
103 sys.exit() 105
104 if args.nProcesses > 1: 106 if args.nProcesses > 1:
105 pool = Pool(args.nProcesses) 107 pool = Pool(args.nProcesses)
106 108
107 ################################# 109 #################################
108 # Report progress in the processing 110 # Report progress in the processing
109 ################################# 111 #################################
110 if args.progress: 112 if args.progress:
111 print('Providing information on data progress') 113 print('Providing information on data progress')
114 headers = ['site', 'vs', 'features', 'objects', 'interactions'] # todo add prototypes and object classification
115 data = []
116 for site in sites:
117 unprocessedVideoSequences = []
118 for vs in getSiteVideoSequences(site):
119 if (parentPath/vs.getDatabaseFilename()).is_file():
120 tableNames = storage.tableNames(str(parentPath.absolute()/vs.getDatabaseFilename()))
121 data.append([site.name, vs.idx, 'positions' in tableNames, 'objects' in tableNames, 'interactions' in tableNames])
122 else:
123 unprocessedVideoSequences.append(vs)
124 data.append([site.name, vs.idx, False, False, False])
125 #if len(unprocessedVideoSequences):
126 # print('Site {} ({}) has {} completely unprocessed video sequences'.format (site.name, site.idx, len(unprocessedVideoSequences)))
127 data = pd.DataFrame(data, columns = headers)
128 print('-'*80)
129 print('\t'+' '.join(headers[2:]))
130 print('-'*80)
131 for name, group in data.groupby(['site']): #.agg({'vs': 'count'}))
132 n = group.vs.count()
133 print('{}: {} % / {} % / {} % ({})'.format(name, 100*group.features.sum()/float(n), 100*group.objects.sum()/float(n), 100*group.interactions.sum()/float(n), n))
134 print('-'*80)
135 print(data)
112 136
113 ################################# 137 #################################
114 # Delete 138 # Delete
115 ################################# 139 #################################
116 if args.delete is not None: 140 if args.delete is not None:
129 # Process 153 # Process
130 ################################# 154 #################################
131 if args.process in ['feature', 'object']: # tracking 155 if args.process in ['feature', 'object']: # tracking
132 if args.nProcesses == 1: 156 if args.nProcesses == 1:
133 for vs in videoSequences: 157 for vs in videoSequences:
134 if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': 158 if not (parentPath/vs.getDatabaseFilename()).is_file() or args.process == 'object':
135 if args.configFilename is None: 159 if args.configFilename is None:
136 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) 160 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename())
137 else: 161 else:
138 configFilename = args.configFilename 162 configFilename = args.configFilename
139 if vs.cameraView.cameraType is None: 163 if vs.cameraView.cameraType is None:
142 cvutils.tracking(configFilename, args.process == 'object', str(parentPath.absolute()/vs.getVideoSequenceFilename()), str(parentPath.absolute()/vs.getDatabaseFilename()), str(parentPath.absolute()/vs.cameraView.getHomographyFilename()), str(parentPath.absolute()/vs.cameraView.getMaskFilename()), True, vs.cameraView.cameraType.intrinsicCameraMatrix, vs.cameraView.cameraType.distortionCoefficients, args.dryRun) 166 cvutils.tracking(configFilename, args.process == 'object', str(parentPath.absolute()/vs.getVideoSequenceFilename()), str(parentPath.absolute()/vs.getDatabaseFilename()), str(parentPath.absolute()/vs.cameraView.getHomographyFilename()), str(parentPath.absolute()/vs.cameraView.getMaskFilename()), True, vs.cameraView.cameraType.intrinsicCameraMatrix, vs.cameraView.cameraType.distortionCoefficients, args.dryRun)
143 else: 167 else:
144 print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename())) 168 print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename()))
145 else: 169 else:
146 for vs in videoSequences: 170 for vs in videoSequences:
147 if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': 171 if not (parentPath/vs.getDatabaseFilename()).is_file() or args.process == 'object':
148 if args.configFilename is None: 172 if args.configFilename is None:
149 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) 173 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename())
150 else: 174 else:
151 configFilename = args.configFilename 175 configFilename = args.configFilename
152 if vs.cameraView.cameraType is None: 176 if vs.cameraView.cameraType is None: