Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 393:eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 26 Jul 2013 02:12:08 -0400 |
parents | 1917db662aa7 |
children | 167f6ec44ec5 |
comparison
equal
deleted
inserted
replaced
392:dd4970f4221f | 393:eaf7765221d9 |
---|---|
154 cv2.imwrite('image{0:04d}.png'.format(numImg), img) | 154 cv2.imwrite('image{0:04d}.png'.format(numImg), img) |
155 else: | 155 else: |
156 images.append(img) | 156 images.append(img) |
157 return images | 157 return images |
158 | 158 |
159 def displayTrajectories(videoFilename, objects, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1.): | 159 def displayTrajectories(videoFilename, objects, boundingBoxes, homography = None, firstFrameNum = 0, lastFrameNumArg = None, printFrames = True, rescale = 1.): |
160 '''Displays the objects overlaid frame by frame over the video ''' | 160 '''Displays the objects overlaid frame by frame over the video ''' |
161 capture = cv2.VideoCapture(videoFilename) | 161 capture = cv2.VideoCapture(videoFilename) |
162 if capture.isOpened(): | 162 if capture.isOpened(): |
163 key = -1 | 163 key = -1 |
164 ret = True | 164 ret = True |
180 if homography != None: | 180 if homography != None: |
181 obj.projectedPositions = obj.positions.project(homography) | 181 obj.projectedPositions = obj.positions.project(homography) |
182 else: | 182 else: |
183 obj.projectedPositions = obj.positions | 183 obj.projectedPositions = obj.positions |
184 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) | 184 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) |
185 if frameNum in boundingBoxes.keys(): | |
186 for rect in boundingBoxes[frameNum]: | |
187 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) | |
185 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) | 188 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) |
186 cvImshow('frame', img, rescale) | 189 cvImshow('frame', img, rescale) |
187 key = cv2.waitKey() | 190 key = cv2.waitKey() |
188 if saveKey(key): | 191 if saveKey(key): |
189 cv2.imwrite('image.png', img) | 192 cv2.imwrite('image.png', img) |