Mercurial Hosting > traffic-intelligence
diff python/cvutils.py @ 933:8ac7f61c6e4f
major rework of homography calibration, no in ideal points if correcting for distortion
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 14 Jul 2017 02:11:21 -0400 |
parents | 66f382852e61 |
children | 0e63a918a1ca |
line wrap: on
line diff
--- a/python/cvutils.py Fri Jul 14 00:12:03 2017 -0400 +++ b/python/cvutils.py Fri Jul 14 02:11:21 2017 -0400 @@ -124,7 +124,7 @@ def computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients): newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) newCameraMatrix = cv2.getDefaultNewCameraMatrix(intrinsicCameraMatrix, newImgSize, True) - return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), None, newCameraMatrix, newImgSize, cv2.CV_32FC1) + return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), None, newCameraMatrix, newImgSize, cv2.CV_32FC1), newCameraMatrix def playVideo(filenames, windowNames = None, firstFrameNums = None, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1, colorBlind = False): '''Plays the video(s)''' @@ -305,7 +305,7 @@ cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) if undistort: # setup undistortion - [map1, map2] = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) + [map1, map2], newCameraMatrix = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) if capture.isOpened(): key = -1 ret = True @@ -330,10 +330,10 @@ for obj in objects: if obj.existsAtInstant(frameNum): if not hasattr(obj, 'projectedPositions'): - if homography is not None: - obj.projectedPositions = obj.positions.project(homography) - else: - obj.projectedPositions = obj.positions + obj.projectedPositions = obj.getPositions().homographyProject(homography) + if undistort: + obj.projectedPositions = obj.projectedPositions.newCameraProject(newCameraMatrix) + #obj.projectedPositions = obj.positions cvPlot(img, obj.projectedPositions, cvColors[colorType][obj.getNum()], frameNum-obj.getFirstInstant()) if frameNum not in boundingBoxes.keys() and obj.hasFeatures(): yCropMin, yCropMax, xCropMin, xCropMax = imageBoxSize(obj, frameNum, homography, width, height)