Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 218:b5772df11b37
corrected bugs to load objects and display trajectories over videos
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 21 Jun 2012 18:04:11 -0400 |
parents | 51acf43e421a |
children | c31722fcc9de |
comparison
equal
deleted
inserted
replaced
217:ba71924cadf5 | 218:b5772df11b37 |
---|---|
127 def displayTrajectories(videoFilename, objects, homography = None): | 127 def displayTrajectories(videoFilename, objects, homography = None): |
128 '''Displays the objects overlaid frame by frame over the video ''' | 128 '''Displays the objects overlaid frame by frame over the video ''' |
129 capture = cv2.VideoCapture(videoFilename) | 129 capture = cv2.VideoCapture(videoFilename) |
130 if capture.isOpened(): | 130 if capture.isOpened(): |
131 key = -1 | 131 key = -1 |
132 frameNum = 1 | 132 frameNum = 0 |
133 while key!= 113: # 'q' | 133 while key!= 113: # 'q' |
134 ret, img = capture.read() | 134 ret, img = capture.read() |
135 if ret: | 135 if ret: |
136 print(frameNum) | 136 print(frameNum) |
137 for obj in objects: | 137 for obj in objects: |
138 if obj.existsAtInstant(frameNum): | 138 if obj.existsAtInstant(frameNum): |
139 #obj.getTimeInterval() | 139 if obj.getFirstInstant() == frameNum: |
140 if homography != None and obj.getFirstInstant() == frameNum: | 140 if homography != None: |
141 obj.projectedPositions = obj.positions.project(homography) | 141 obj.projectedPositions = obj.positions.project(homography) |
142 else: | |
143 obj.projectedPositions = obj.positions | |
142 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) | 144 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) |
143 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) | 145 cv2.putText(img, '{0}'.format(obj.num), obj.projectedPositions[frameNum-obj.getFirstInstant()].astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) |
144 cv2.imshow('frame', img) | 146 cv2.imshow('frame', img) |
145 key = cv2.waitKey(50) | 147 key = cv2.waitKey(50) |
146 frameNum += 1 | 148 frameNum += 1 |