Mercurial Hosting > traffic-intelligence
diff scripts/process.py @ 1021:16932cefabc1
work on paths in line with new configurations from tracker
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 05 Jun 2018 17:02:28 -0400 |
parents | 0d29b75f74ea |
children | a13f47c8931d |
line wrap: on
line diff
--- a/scripts/process.py Tue Jun 05 14:33:31 2018 -0400 +++ b/scripts/process.py Tue Jun 05 17:02:28 2018 -0400 @@ -40,7 +40,7 @@ # Data preparation ################################# session = connectDatabase(args.metadataFilename) -parentDir = Path(args.metadataFilename).parent # files are relative to metadata location +parentPath = Path(args.metadataFilename).parent # files are relative to metadata location videoSequences = [] if args.videoIds is not None: videoSequences = [session.query(VideoSequence).get(videoId) for videoId in args.videoIds] @@ -61,7 +61,7 @@ elif args.delete in ['object', 'interaction']: #parser.add_argument('-t', dest = 'dataType', help = 'type of the data to remove', required = True, choices = ['object','interaction', 'bb', 'pois', 'prototype']) for vs in videoSequences: - storage.deleteFromSqlite(str(parentDir/vs.getDatabaseFilename()), args.delete) + storage.deleteFromSqlite(str(parentPath/vs.getDatabaseFilename()), args.delete) ################################# # Process @@ -69,31 +69,31 @@ if args.process in ['feature', 'object']: # tracking if args.nProcesses == 1: for vs in videoSequences: - if not (parentDir/vs.getDatabaseFilename()).exists() or args.process == 'object': + if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': if args.configFilename is None: - configFilename = str(parentDir/vs.cameraView.getTrackingConfigurationFilename()) + configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) else: configFilename = args.configFilename if vs.cameraView.cameraType is None: - cvutils.tracking(configFilename, args.process == 'object', str(parentDir.absolute()/vs.getVideoSequenceFilename()), str(parentDir.absolute()/vs.getDatabaseFilename()), str(parentDir.absolute()/vs.cameraView.getHomographyFilename()), str(parentDir.absolute()/vs.cameraView.getMaskFilename()), False, None, None, args.dryRun) + 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) else: - cvutils.tracking(configFilename, args.process == 'object', str(parentDir.absolute()/vs.getVideoSequenceFilename()), str(parentDir.absolute()/vs.getDatabaseFilename()), str(parentDir.absolute()/vs.cameraView.getHomographyFilename()), str(parentDir.absolute()/vs.cameraView.getMaskFilename()), True, vs.cameraView.cameraType.intrinsicCameraMatrix, vs.cameraView.cameraType.distortionCoefficients, args.dryRun) + 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) else: - print('SQLite already exists: {}'.format(parentDir/vs.getDatabaseFilename())) + print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename())) else: pool = Pool(args.nProcesses) for vs in videoSequences: - if not (parentDir/vs.getDatabaseFilename()).exists() or args.process == 'object': + if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': if args.configFilename is None: - configFilename = str(parentDir/vs.cameraView.getTrackingConfigurationFilename()) + configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) else: configFilename = args.configFilename if vs.cameraView.cameraType is None: - pool.apply_async(cvutils.tracking, args = (configFilename, args.process == 'object', str(parentDir.absolute()/vs.getVideoSequenceFilename()), str(parentDir.absolute()/vs.getDatabaseFilename()), str(parentDir.absolute()/vs.cameraView.getHomographyFilename()), str(parentDir.absolute()/vs.cameraView.getMaskFilename()), False, None, None, args.dryRun)) + pool.apply_async(cvutils.tracking, args = (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)) else: - pool.apply_async(cvutils.tracking, args = (configFilename, args.process == 'object', str(parentDir.absolute()/vs.getVideoSequenceFilename()), str(parentDir.absolute()/vs.getDatabaseFilename()), str(parentDir.absolute()/vs.cameraView.getHomographyFilename()), str(parentDir.absolute()/vs.cameraView.getMaskFilename()), True, vs.cameraView.cameraType.intrinsicCameraMatrix, vs.cameraView.cameraType.distortionCoefficients, args.dryRun)) + pool.apply_async(cvutils.tracking, args = (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)) else: - print('SQLite already exists: {}'.format(parentDir/vs.getDatabaseFilename())) + print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename())) pool.close() pool.join() @@ -105,14 +105,14 @@ predictionParameters = prediction.CVExactPredictionParameters() for vs in videoSequences: print('Processing '+vs.getDatabaseFilename()) - objects = storage.loadTrajectoriesFromSqlite(str(parentDir/vs.getDatabaseFilename()), 'object')#, args.nObjects, withFeatures = (params.useFeaturesForPrediction or predictionMethod == 'ps' or predictionMethod == 'mp')) + objects = storage.loadTrajectoriesFromSqlite(str(parentPath/vs.getDatabaseFilename()), 'object')#, args.nObjects, withFeatures = (params.useFeaturesForPrediction or predictionMethod == 'ps' or predictionMethod == 'mp')) interactions = events.createInteractions(objects) #if args.nProcesses == 1: - #print(str(parentDir/vs.cameraView.getTrackingConfigurationFilename())) - params = storage.ProcessParameters(str(parentDir/vs.cameraView.getTrackingConfigurationFilename())) + #print(str(parentPath/vs.cameraView.getTrackingConfigurationFilename())) + params = storage.ProcessParameters(str(parentPath/vs.cameraView.getTrackingConfigurationFilename())) #print(len(interactions), args.computePET, predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) processed = events.computeIndicators(interactions, True, args.computePET, predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, False, None) - storage.saveIndicatorsToSqlite(str(parentDir/vs.getDatabaseFilename()), processed) + storage.saveIndicatorsToSqlite(str(parentPath/vs.getDatabaseFilename()), processed) # else: # pool = Pool(processes = args.nProcesses) # nInteractionPerProcess = int(np.ceil(len(interactions)/float(args.nProcesses))) @@ -134,7 +134,7 @@ medianSpeeds[vs.cameraView.siteIdx] = [] speeds85[vs.cameraView.siteIdx] = [] print('Extracting speed from '+vs.getDatabaseFilename()) - objects = storage.loadTrajectoriesFromSqlite(str(parentDir/vs.getDatabaseFilename()), 'object') + objects = storage.loadTrajectoriesFromSqlite(str(parentPath/vs.getDatabaseFilename()), 'object') for o in objects: if o.length() > minLength: speeds = 30*3.6*percentile(o.getSpeeds(), [50, 85]) @@ -160,7 +160,7 @@ indicators[vs.cameraView.siteIdx] = {} for i in indicatorIds: indicators[vs.cameraView.siteIdx][i] = [] - interactions[vs.cameraView.siteIdx] += storage.loadInteractionsFromSqlite(str(parentDir/vs.getDatabaseFilename())) + interactions[vs.cameraView.siteIdx] += storage.loadInteractionsFromSqlite(str(parentPath/vs.getDatabaseFilename())) print(vs.getDatabaseFilename(), len(interactions[vs.cameraView.siteIdx])) for inter in interactions[vs.cameraView.siteIdx]: for i in indicatorIds: