diff scripts/init-tracking.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents scripts/init_tracking.py@2faabcbde2c4
children 16932cefabc1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/init-tracking.py	Sun May 27 23:22:48 2018 -0400
@@ -0,0 +1,56 @@
+#! /usr/bin/env python3
+
+import sys, argparse, os.path, storage, utils
+from shutil import copy
+from cvutils import getImagesFromVideo
+from matplotlib.pyplot import imsave
+
+# could try to guess the video
+# check if there is already a tracking.cfg file
+
+parser = argparse.ArgumentParser(description='The program initilizes the files for tracking: copy tracking.cfg, sets up with the video filename, generates a frame image (frame.png) and prints the next commands')
+
+parser.add_argument('-i', dest = 'videoFilename', help = 'filename of the video sequence', required = True)
+
+args = parser.parse_args()
+
+# assumes tracking.cfg is in the parent directory to the directory of the traffic intelligence python modules
+matchingPaths = [s for s in sys.path if 'traffic-intelligence' in s]
+#if len(matchingPaths) > 1:
+#    print('Too many matching paths for Traffic Intelligence modules: {}'.format(matchingPaths))
+if len(matchingPaths) == 0:
+    print('No environment path to Traffic Intelligence modules.\nExiting')
+    sys.exit()
+else:
+    directoryName = matchingPaths[0]
+    if directoryName.endswith('/'):
+        directoryName = directoryName[:-1]
+    if os.path.exists(directoryName+'/../tracking.cfg') and not os.path.exists('./tracking.cfg'):
+        f = storage.openCheck(directoryName+'/../tracking.cfg')
+        out = storage.openCheck('./tracking.cfg', 'w')
+        for l in f:
+            if 'video-filename' in l:
+                tmp = l.split('=')
+                out.write(tmp[0]+'= '+args.videoFilename+'\n')
+            elif 'database-filename' in l:
+                tmp = l.split('=')
+                out.write(tmp[0]+'= '+utils.removeExtension(args.videoFilename)+'.sqlite\n')                
+            else:
+                out.write(l)
+        f.close()
+        out.close()
+        print('Configuration file tracking.cfg successfully copied to the current directory with video and database filename adapted')
+    if os.path.exists(directoryName+'/../classifier.cfg') and not os.path.exists('./classifier.cfg'):
+        copy(directoryName+'/../classifier.cfg', 'classifier.cfg')
+        print('Configuration file classifier.cfg successfully copied to the current directory')
+        
+# extract image from video
+image = getImagesFromVideo(args.videoFilename, saveImage = True, outputPrefix = 'frame')
+print('first video frame successfully copied to the current directory')
+
+# next commands
+print('--------------------------------------\nHere are a sample of the next command to compute the homography,\ntrack features, group them in objects and display object trajectories\n--------------------------------------')
+print('compute_homography -i [frame.png] -w [world_image] -n [npoints] -u [unit_per_pixel]')
+print('feature-based-tracking tracking.cfg --tf')
+print('feature-based-tracking tracking.cfg --gf')
+print('display-trajectories --cfg tracking.cfg -t object')