Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/cvutils.py @ 1245:371c718e57d7
interface updates
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 08 Feb 2024 16:10:54 -0500 |
| parents | 4cd8ace3552f |
| children | ef68d4ba7dae |
comparison
equal
deleted
inserted
replaced
| 1244:00b71da2baac | 1245:371c718e57d7 |
|---|---|
| 2 '''Image/Video utilities''' | 2 '''Image/Video utilities''' |
| 3 | 3 |
| 4 from sys import stdout | 4 from sys import stdout |
| 5 from os import listdir | 5 from os import listdir |
| 6 from subprocess import run | 6 from subprocess import run |
| 7 from math import floor, log10, ceil | 7 from math import floor, log10, ceil, inf |
| 8 from time import time | 8 from time import time |
| 9 | 9 |
| 10 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, nonzero, dtype | 10 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, nonzero, dtype |
| 11 from numpy.linalg import inv | 11 from numpy.linalg import inv |
| 12 from matplotlib.pyplot import imread, imsave, imshow, figure, subplot | 12 from matplotlib.pyplot import imread, imsave, imshow, figure, subplot |
| 310 if dryRun: | 310 if dryRun: |
| 311 print(cmd) | 311 print(cmd) |
| 312 else: | 312 else: |
| 313 run(cmd) | 313 run(cmd) |
| 314 | 314 |
| 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, **kwargs): | 315 def displayTrajectories(videoFilename, objects, boundingBoxes = {}, homography = None, firstFrameNum = 0, lastFrameNum = None, printFrames = True, rescale = 1., nFramesStep = 1, saveAllImages = False, nZerosFilenameArg = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., annotations = [], gtMatches = {}, toMatches = {}, colorBlind = False, **kwargs): |
| 316 '''Displays the objects overlaid frame by frame over the video ''' | 316 '''Displays the objects overlaid frame by frame over the video ''' |
| 317 if colorBlind: | 317 if colorBlind: |
| 318 colorType = 'colorblind' | 318 colorType = 'colorblind' |
| 319 else: | 319 else: |
| 320 colorType = 'default' | 320 colorType = 'default' |
| 332 if capture.isOpened(): | 332 if capture.isOpened(): |
| 333 key = -1 | 333 key = -1 |
| 334 ret = True | 334 ret = True |
| 335 frameNum = firstFrameNum | 335 frameNum = firstFrameNum |
| 336 capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum) | 336 capture.set(cv2.CAP_PROP_POS_FRAMES, firstFrameNum) |
| 337 if lastFrameNumArg is None: | |
| 338 lastFrameNum = float("inf") | |
| 339 else: | |
| 340 lastFrameNum = lastFrameNumArg | |
| 341 if nZerosFilenameArg is None: | 337 if nZerosFilenameArg is None: |
| 342 if lastFrameNumArg is None: | 338 if lastFrameNum is None or lastFrameNum == inf: |
| 343 nZerosFilename = int(ceil(log10(objects[-1].getLastInstant()))) | 339 nZerosFilename = int(ceil(log10(objects[-1].getLastInstant()))) |
| 344 else: | 340 else: |
| 345 nZerosFilename = int(ceil(log10(lastFrameNum))) | 341 nZerosFilename = int(ceil(log10(lastFrameNum))) |
| 346 else: | 342 else: |
| 347 nZerosFilename = nZerosFilenameArg | 343 nZerosFilename = nZerosFilenameArg |
