diff 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
line wrap: on
line diff
--- a/scripts/process.py	Mon Jul 16 00:05:17 2018 -0400
+++ b/scripts/process.py	Mon Jul 16 01:14:37 2018 -0400
@@ -116,7 +116,7 @@
     for site in sites:
         unprocessedVideoSequences = []
         for vs in getSiteVideoSequences(site):
-            if (parentPath/vs.getDatabaseFilename()).is_file():
+            if (parentPath/vs.getDatabaseFilename()).is_file(): # TODO check time of file?
                 tableNames = storage.tableNames(str(parentPath.absolute()/vs.getDatabaseFilename()))
                 data.append([site.name, vs.idx, 'positions' in tableNames, 'objects' in tableNames, 'interactions' in tableNames])
             else:
@@ -162,7 +162,7 @@
                     configFilename = args.configFilename
                 if vs.cameraView.cameraType is None:
                     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:
+                else: #caution: cameratype can be not none, but without parameters for undistortion
                     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(parentPath/vs.getDatabaseFilename()))
@@ -252,23 +252,15 @@
     headers = ['site', 'date', 'time', 'user_type']
     aggFunctions, tmpheaders = utils.aggregationMethods(args.aggMethods, args.aggCentiles)
     headers.extend(tmpheaders)
-    for vs in videoSequences:
-        d = vs.startTime.date()
-        t1 = vs.startTime.time()
-        minUserDuration = args.minUserDuration*vs.cameraView.cameraType.frameRate
-        print('Extracting speed from '+vs.getDatabaseFilename())
-        objects = storage.loadTrajectoriesFromSqlite(str(parentPath/vs.getDatabaseFilename()), 'object', args.nObjects)
-        for o in objects:
-            if o.length() > minUserDuration:
-                row = [vs.cameraView.site.name, d, utils.framesToTime(o.getFirstInstant(), vs.cameraView.cameraType.frameRate, t1), o.getUserType()]
-                tmp = o.getSpeeds()
-                for method,func in aggFunctions.items():
-                    aggSpeeds = vs.cameraView.cameraType.frameRate*3.6*func(tmp)
-                    if method == 'centile':
-                        row += aggSpeeds.tolist()
-                    else:
-                        row.append(aggSpeeds)
-            data.append(row)
+    if args.nProcesses == 1:
+        for vs in videoSequences:
+            data.extend(processing.extractVideoSequenceSpeeds(str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, aggFunctions))
+    else:
+        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]
+        for job in jobs:
+            data.extend(job.get())
+        pool.close()
+            
     data = pd.DataFrame(data, columns = headers)
     if args.output == 'figure':
         for name in headers[4:]: