comparison 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
comparison
equal deleted inserted replaced
1002:6c5ce3ec497e 1003:75af46516b2b
16 print('Scikit-image library could not be loaded (HoG-based classification methods will not be available)') 16 print('Scikit-image library could not be loaded (HoG-based classification methods will not be available)')
17 skimageAvailable = False 17 skimageAvailable = False
18 18
19 from sys import stdout 19 from sys import stdout
20 from os import listdir 20 from os import listdir
21 from copy import deepcopy 21 from subprocess import check_call
22 from math import floor, log10, ceil 22 from math import floor, log10, ceil
23 23
24 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 24 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
25 from numpy.linalg import inv 25 from numpy.linalg import inv
26 from matplotlib.mlab import find 26 from matplotlib.mlab import find
27 from matplotlib.pyplot import imread, imsave 27 from matplotlib.pyplot import imread, imsave
28 28
29 videoFilenameExtensions = ['mov', 'avi', 'mp4', 'MOV', 'AVI', 'MP4'] 29 videoFilenameExtensions = ['mov', 'avi', 'mp4', 'MOV', 'AVI', 'MP4']
30 30 trackerExe = 'feature-based-tracking'
31 #importaggdraw # agg on top of PIL (antialiased drawing) 31 #importaggdraw # agg on top of PIL (antialiased drawing)
32
33 32
34 cvRed = {'default': (0,0,255), 33 cvRed = {'default': (0,0,255),
35 'colorblind': (0,114,178)} 34 'colorblind': (0,114,178)}
36 cvGreen = {'default': (0,255,0), 35 cvGreen = {'default': (0,255,0),
37 'colorblind': (0,158,115)} 36 'colorblind': (0,158,115)}
281 if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels: 280 if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels:
282 return img[yCropMin : yCropMax, xCropMin : xCropMax] 281 return img[yCropMin : yCropMax, xCropMin : xCropMax]
283 else: 282 else:
284 return None 283 return None
285 284
285 def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None):
286 '''Runs the tracker in a subprocess
287 if grouping is True, it is feature grouping
288 otherwise it is feature tracking'''
289 if grouping:
290 trackingMode = '--gf'
291 else:
292 trackingMode = '--tf'
293 cmd = [trackerExe, configFilename, trackingMode]
294
295 if videoFilename is not None:
296 cmd += ['--video-filename', videoFilename]
297 if dbFilename is not None:
298 cmd += ['--database-filename', dbFilename]
299 if homographyFilename is not None:
300 cmd += ['--homography-filename', homographyFilename]
301 if maskFilename is not None:
302 cmd += ['--mask-filename', maskFilename]
303 if undistort:
304 cmd += ['--undistort', 'true']
305 if intrinsicCameraMatrix is not None: # we currently have to save a file
306 pass#from time import time
307 #savetxt
308 #cmd += []
309 if distortionCoefficients is not None:
310 cmd += ['--distortion-coefficients', ' '.join([str(x) for x in distortionCoefficients])]
311
312 #check_call([trackerExe, configFilename, trackingMode]) # , stderr = out, shell = True
313 print(cmd) # , stderr = out, shell = True
314
286 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): 315 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):
287 '''Displays the objects overlaid frame by frame over the video ''' 316 '''Displays the objects overlaid frame by frame over the video '''
288 if colorBlind: 317 if colorBlind:
289 colorType = 'colorblind' 318 colorType = 'colorblind'
290 else: 319 else: