Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
1003:75af46516b2b | 1004:75601be6019f |
---|---|
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 subprocess import check_call | 21 from subprocess import run |
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 |
280 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: |
281 return img[yCropMin : yCropMax, xCropMin : xCropMax] | 281 return img[yCropMin : yCropMax, xCropMin : xCropMax] |
282 else: | 282 else: |
283 return None | 283 return None |
284 | 284 |
285 def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None): | 285 def tracking(configFilename, grouping, videoFilename = None, dbFilename = None, homographyFilename = None, maskFilename = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, dryRun = False): |
286 '''Runs the tracker in a subprocess | 286 '''Runs the tracker in a subprocess |
287 if grouping is True, it is feature grouping | 287 if grouping is True, it is feature grouping |
288 otherwise it is feature tracking''' | 288 otherwise it is feature tracking''' |
289 if grouping: | 289 if grouping: |
290 trackingMode = '--gf' | 290 trackingMode = '--gf' |
301 if maskFilename is not None: | 301 if maskFilename is not None: |
302 cmd += ['--mask-filename', maskFilename] | 302 cmd += ['--mask-filename', maskFilename] |
303 if undistort: | 303 if undistort: |
304 cmd += ['--undistort', 'true'] | 304 cmd += ['--undistort', 'true'] |
305 if intrinsicCameraMatrix is not None: # we currently have to save a file | 305 if intrinsicCameraMatrix is not None: # we currently have to save a file |
306 pass#from time import time | 306 from time import time |
307 #savetxt | 307 intrinsicCameraFilename = '/tmp/intrinsic-{}.txt'.format(time()) |
308 #cmd += [] | 308 savetxt(intrinsicCameraFilename, intrinsicCameraMatrix) |
309 cmd += ['--intrinsic-camera-filename', intrinsicCameraFilename] | |
309 if distortionCoefficients is not None: | 310 if distortionCoefficients is not None: |
310 cmd += ['--distortion-coefficients', ' '.join([str(x) for x in distortionCoefficients])] | 311 cmd += ['--distortion-coefficients', ' '.join([str(x) for x in distortionCoefficients])] |
311 | 312 if dryRun: |
312 #check_call([trackerExe, configFilename, trackingMode]) # , stderr = out, shell = True | 313 print(cmd) |
313 print(cmd) # , stderr = out, shell = True | 314 else: |
315 run(cmd) | |
314 | 316 |
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): | 317 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): |
316 '''Displays the objects overlaid frame by frame over the video ''' | 318 '''Displays the objects overlaid frame by frame over the video ''' |
317 if colorBlind: | 319 if colorBlind: |
318 colorType = 'colorblind' | 320 colorType = 'colorblind' |