Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 685:94b291a5f933 dev
several updates for display
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 05 Jun 2015 17:13:28 +0200 |
parents | da1352b89d02 |
children | 35bc5e30a53f |
comparison
equal
deleted
inserted
replaced
684:6d2ece4aed7c | 685:94b291a5f933 |
---|---|
124 return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), identity(3), newCameraMatrix, newImgSize, cv2.CV_32FC1) | 124 return cv2.initUndistortRectifyMap(intrinsicCameraMatrix, array(distortionCoefficients), identity(3), newCameraMatrix, newImgSize, cv2.CV_32FC1) |
125 | 125 |
126 def playVideo(filename, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1): | 126 def playVideo(filename, firstFrameNum = 0, frameRate = -1, interactive = False, printFrames = True, text = None, rescale = 1., step = 1): |
127 '''Plays the video''' | 127 '''Plays the video''' |
128 windowName = 'frame' | 128 windowName = 'frame' |
129 cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) | 129 if rescale == 1.: |
130 cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) | |
130 wait = 5 | 131 wait = 5 |
131 if frameRate > 0: | 132 if frameRate > 0: |
132 wait = int(round(1000./frameRate)) | 133 wait = int(round(1000./frameRate)) |
133 if interactive: | 134 if interactive: |
134 wait = 0 | 135 wait = 0 |
257 xCropMin = int(max(0, .5 * (xmin + xmax - a))) | 258 xCropMin = int(max(0, .5 * (xmin + xmax - a))) |
258 xCropMax = int(min(width - 1, .5 * (xmin + xmax + a))) | 259 xCropMax = int(min(width - 1, .5 * (xmin + xmax + a))) |
259 if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels: | 260 if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > minNPixels: |
260 croppedImg = img[yCropMin : yCropMax, xCropMin : xCropMax] | 261 croppedImg = img[yCropMin : yCropMax, xCropMin : xCropMax] |
261 else: | 262 else: |
262 croppedImg = [] | 263 croppedImg = None |
263 return croppedImg, yCropMin, yCropMax, xCropMin, xCropMax | 264 return croppedImg, yCropMin, yCropMax, xCropMin, xCropMax |
264 | 265 |
265 | 266 |
266 def displayTrajectories(videoFilename, objects, boundingBoxes = {}, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1., nFramesStep = 1, saveAllImages = False, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): | 267 def displayTrajectories(videoFilename, objects, boundingBoxes = {}, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1., nFramesStep = 1, saveAllImages = False, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): |
267 '''Displays the objects overlaid frame by frame over the video ''' | 268 '''Displays the objects overlaid frame by frame over the video ''' |
271 capture = cv2.VideoCapture(videoFilename) | 272 capture = cv2.VideoCapture(videoFilename) |
272 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) | 273 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) |
273 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) | 274 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) |
274 | 275 |
275 windowName = 'frame' | 276 windowName = 'frame' |
276 #cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) | 277 if rescale == 1.: |
278 cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) | |
277 | 279 |
278 if undistort: # setup undistortion | 280 if undistort: # setup undistortion |
279 [map1, map2] = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) | 281 [map1, map2] = computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) |
280 if capture.isOpened(): | 282 if capture.isOpened(): |
281 key = -1 | 283 key = -1 |