diff python/cvutils.py @ 1004:75601be6019f

work on process
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 03 Jun 2018 00:21:18 -0400
parents 75af46516b2b
children 666b38437d9a
line wrap: on
line diff
--- a/python/cvutils.py	Fri Jun 01 17:19:31 2018 -0400
+++ b/python/cvutils.py	Sun Jun 03 00:21:18 2018 -0400
@@ -18,7 +18,7 @@
     
 from sys import stdout
 from os import listdir
-from subprocess import check_call
+from subprocess import run
 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
@@ -282,7 +282,7 @@
         else:
             return None
 
-    def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None):
+    def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, dryRun = False):
         '''Runs the tracker in a subprocess
         if grouping is True, it is feature grouping
         otherwise it is feature tracking'''
@@ -303,14 +303,16 @@
         if undistort:
             cmd += ['--undistort', 'true']
             if intrinsicCameraMatrix is not None: # we currently have to save a file
-                pass#from time import time
-                #savetxt
-                #cmd += []
+                from time import time
+                intrinsicCameraFilename = '/tmp/intrinsic-{}.txt'.format(time())
+                savetxt(intrinsicCameraFilename, intrinsicCameraMatrix)
+                cmd += ['--intrinsic-camera-filename', intrinsicCameraFilename]
             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
+        if dryRun:
+            print(cmd)
+        else:
+            run(cmd)
         
     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 '''