Mercurial Hosting > traffic-intelligence
diff python/cvutils.py @ 904:8f60ecfc2f06
work in progress, almost ready
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 22 Jun 2017 18:08:46 -0400 |
parents | 81ee5aaf213d |
children | a71455bd8367 |
line wrap: on
line diff
--- a/python/cvutils.py Thu Jun 22 17:02:03 2017 -0400 +++ b/python/cvutils.py Thu Jun 22 18:08:46 2017 -0400 @@ -258,9 +258,9 @@ else: print('Video capture for {} failed'.format(videoFilename)) return None - - def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, minNPixels = 800): - 'Computes the bounding box of object at frameNum' + + def imageBoxSize(obj, frameNum, homography, width, height, px = 0.2, py = 0.2): + 'Computes the bounding box size of object at frameNum' x = [] y = [] if obj.hasFeatures(): @@ -280,12 +280,15 @@ yCropMax = int(min(height - 1, .5 * (ymin + ymax + a))) xCropMin = int(max(0, .5 * (xmin + xmax - a))) xCropMax = int(min(width - 1, .5 * (xmin + xmax + a))) + return yCropMin, yCropMax, xCropMin, xCropMax + + def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, minNPixels = 800): + 'Computes the bounding box of object at frameNum' + yCropMin, yCropMax, xCropMin, xCropMax = imageBoxSize(obj, frameNum, homography, width, height, px, py) if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels: - croppedImg = img[yCropMin : yCropMax, xCropMin : xCropMax] + return img[yCropMin : yCropMax, xCropMin : xCropMax] else: - croppedImg = None - return croppedImg, yCropMin, yCropMax, xCropMin, xCropMax - + return None 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 ''' @@ -334,7 +337,7 @@ obj.projectedPositions = obj.positions cvPlot(img, obj.projectedPositions, cvColors[colorType][obj.getNum()], frameNum-obj.getFirstInstant()) if frameNum not in boundingBoxes.keys() and obj.hasFeatures(): - imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height) + yCropMin, yCropMax, xCropMin, xCropMax = imageBoxSize(obj, frameNum, homography, width, height) cv2.rectangle(img, (xCropMin, yCropMin), (xCropMax, yCropMax), cvBlue[colorType], 1) objDescription = '{} '.format(obj.num) if moving.userTypeNames[obj.userType] != 'unknown':