diff python/cvutils.py @ 1003:75af46516b2b

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 01 Jun 2018 17:19:31 -0400
parents 933670761a57
children 75601be6019f
line wrap: on
line diff
--- a/python/cvutils.py	Fri Jun 01 17:19:24 2018 -0400
+++ b/python/cvutils.py	Fri Jun 01 17:19:31 2018 -0400
@@ -18,7 +18,7 @@
     
 from sys import stdout
 from os import listdir
-from copy import deepcopy
+from subprocess import check_call
 from math import floor, log10, ceil
 
 from numpy import dot, array, append, float32, loadtxt, savetxt, append, zeros, ones, identity, abs as npabs, logical_and, unravel_index, sum as npsum, isnan, mgrid, median, floor as npfloor, ceil as npceil
@@ -27,10 +27,9 @@
 from matplotlib.pyplot import imread, imsave
 
 videoFilenameExtensions = ['mov', 'avi', 'mp4', 'MOV', 'AVI', 'MP4']
-
+trackerExe = 'feature-based-tracking'
 #importaggdraw # agg on top of PIL (antialiased drawing)
 
-
 cvRed = {'default': (0,0,255),
          'colorblind': (0,114,178)}
 cvGreen = {'default': (0,255,0),
@@ -283,6 +282,36 @@
         else:
             return None
 
+    def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None):
+        '''Runs the tracker in a subprocess
+        if grouping is True, it is feature grouping
+        otherwise it is feature tracking'''
+        if grouping:
+            trackingMode = '--gf'
+        else:
+            trackingMode = '--tf'
+        cmd = [trackerExe, configFilename, trackingMode]
+        
+        if videoFilename is not None:
+            cmd += ['--video-filename', videoFilename]
+        if dbFilename is not None:
+            cmd += ['--database-filename', dbFilename]
+        if homographyFilename is not None:
+            cmd += ['--homography-filename', homographyFilename]
+        if maskFilename is not None:
+            cmd += ['--mask-filename', maskFilename]
+        if undistort:
+            cmd += ['--undistort', 'true']
+            if intrinsicCameraMatrix is not None: # we currently have to save a file
+                pass#from time import time
+                #savetxt
+                #cmd += []
+            if distortionCoefficients is not None:
+                cmd += ['--distortion-coefficients', ' '.join([str(x) for x in distortionCoefficients])]
+                
+        #check_call([trackerExe, configFilename, trackingMode]) # , stderr = out, shell = True
+        print(cmd) # , stderr = out, shell = True
+        
     def displayTrajectories(videoFilename, objects, boundingBoxes = {}, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1., nFramesStep = 1, saveAllImages = False, nZerosFilenameArg = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., annotations = [], gtMatches = {}, toMatches = {}, colorBlind = False):
         '''Displays the objects overlaid frame by frame over the video '''
         if colorBlind: