Mercurial Hosting > traffic-intelligence
changeset 725:35bc5e30a53f
slight reorganization of display-trajectories (more efficient filtering of list of objects for long sequences)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 07 Aug 2015 01:05:01 -0400 |
parents | b75d0c258ca9 |
children | 43ae3a1af290 |
files | python/cvutils.py |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Thu Aug 06 18:00:25 2015 -0400 +++ b/python/cvutils.py Fri Aug 07 01:05:01 2015 -0400 @@ -290,6 +290,7 @@ else: lastFrameNum = lastFrameNumArg nZerosFilename = int(ceil(log10(lastFrameNum))) + objectToDeleteIds = [] while ret and not quitKey(key) and frameNum <= lastFrameNum: ret, img = capture.read() if ret: @@ -297,24 +298,30 @@ img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) if printFrames: print('frame {0}'.format(frameNum)) + if len(objectToDeleteIds) > 0: + objects = [o for o in objects if o.getNum() not in objectToDeleteIds] + objectToDeleteIds = [] for obj in objects: if obj.existsAtInstant(frameNum): + if obj.getLastInstant() == frameNum: + objectToDeleteIds.append(obj.getNum()) if not hasattr(obj, 'projectedPositions'): if homography is not None: obj.projectedPositions = obj.positions.project(homography) else: obj.projectedPositions = obj.positions cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) - if frameNum in boundingBoxes.keys(): - for rect in boundingBoxes[frameNum]: - cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) - elif obj.hasFeatures(): + if frameNum not in boundingBoxes.keys() and obj.hasFeatures(): imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height) cv2.rectangle(img, (xCropMin, yCropMin), (xCropMax, yCropMax), cvBlue, 1) objDescription = '{} '.format(obj.num) if userTypeNames[obj.userType] != 'unknown': objDescription += userTypeNames[obj.userType][0].upper() cv2.putText(img, objDescription, obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.cv.CV_FONT_HERSHEY_PLAIN, 1, cvRed) + # plot object bounding boxes + if frameNum in boundingBoxes.keys(): + for rect in boundingBoxes[frameNum]: + cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) if not saveAllImages: cvImshow(windowName, img, rescale) key = cv2.waitKey()