comparison scripts/process.py @ 1066:862b55a87e63

work on extracting information
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 16 Jul 2018 01:14:37 -0400
parents d4d052a05337
children 092bd9c7deaf
comparison
equal deleted inserted replaced
1065:d4d052a05337 1066:862b55a87e63
114 headers = ['site', 'vs', 'features', 'objects', 'interactions'] # todo add prototypes and object classification 114 headers = ['site', 'vs', 'features', 'objects', 'interactions'] # todo add prototypes and object classification
115 data = [] 115 data = []
116 for site in sites: 116 for site in sites:
117 unprocessedVideoSequences = [] 117 unprocessedVideoSequences = []
118 for vs in getSiteVideoSequences(site): 118 for vs in getSiteVideoSequences(site):
119 if (parentPath/vs.getDatabaseFilename()).is_file(): 119 if (parentPath/vs.getDatabaseFilename()).is_file(): # TODO check time of file?
120 tableNames = storage.tableNames(str(parentPath.absolute()/vs.getDatabaseFilename())) 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]) 121 data.append([site.name, vs.idx, 'positions' in tableNames, 'objects' in tableNames, 'interactions' in tableNames])
122 else: 122 else:
123 unprocessedVideoSequences.append(vs) 123 unprocessedVideoSequences.append(vs)
124 data.append([site.name, vs.idx, False, False, False]) 124 data.append([site.name, vs.idx, False, False, False])
160 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) 160 configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename())
161 else: 161 else:
162 configFilename = args.configFilename 162 configFilename = args.configFilename
163 if vs.cameraView.cameraType is None: 163 if vs.cameraView.cameraType is None:
164 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()), False, None, None, args.dryRun) 164 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()), False, None, None, args.dryRun)
165 else: 165 else: #caution: cameratype can be not none, but without parameters for undistortion
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) 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)
167 else: 167 else:
168 print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename())) 168 print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename()))
169 else: 169 else:
170 for vs in videoSequences: 170 for vs in videoSequences:
250 # aggregation per site 250 # aggregation per site
251 data = [] # list of observation per site-user with time 251 data = [] # list of observation per site-user with time
252 headers = ['site', 'date', 'time', 'user_type'] 252 headers = ['site', 'date', 'time', 'user_type']
253 aggFunctions, tmpheaders = utils.aggregationMethods(args.aggMethods, args.aggCentiles) 253 aggFunctions, tmpheaders = utils.aggregationMethods(args.aggMethods, args.aggCentiles)
254 headers.extend(tmpheaders) 254 headers.extend(tmpheaders)
255 for vs in videoSequences: 255 if args.nProcesses == 1:
256 d = vs.startTime.date() 256 for vs in videoSequences:
257 t1 = vs.startTime.time() 257 data.extend(processing.extractVideoSequenceSpeeds(str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, aggFunctions))
258 minUserDuration = args.minUserDuration*vs.cameraView.cameraType.frameRate 258 else:
259 print('Extracting speed from '+vs.getDatabaseFilename()) 259 jobs = [pool.apply_async(processing.extractVideoSequenceSpeeds, args = (str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, aggFunctions)) for vs in videoSequences]
260 objects = storage.loadTrajectoriesFromSqlite(str(parentPath/vs.getDatabaseFilename()), 'object', args.nObjects) 260 for job in jobs:
261 for o in objects: 261 data.extend(job.get())
262 if o.length() > minUserDuration: 262 pool.close()
263 row = [vs.cameraView.site.name, d, utils.framesToTime(o.getFirstInstant(), vs.cameraView.cameraType.frameRate, t1), o.getUserType()] 263
264 tmp = o.getSpeeds()
265 for method,func in aggFunctions.items():
266 aggSpeeds = vs.cameraView.cameraType.frameRate*3.6*func(tmp)
267 if method == 'centile':
268 row += aggSpeeds.tolist()
269 else:
270 row.append(aggSpeeds)
271 data.append(row)
272 data = pd.DataFrame(data, columns = headers) 264 data = pd.DataFrame(data, columns = headers)
273 if args.output == 'figure': 265 if args.output == 'figure':
274 for name in headers[4:]: 266 for name in headers[4:]:
275 plt.ioff() 267 plt.ioff()
276 plt.figure() # siteids does not exist 268 plt.figure() # siteids does not exist