Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 223:c31722fcc9de
minor modifications for integer drawing in OpenCV
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 26 Jun 2012 03:29:57 -0400 |
parents | b5772df11b37 |
children | 37a434fb848e |
comparison
equal
deleted
inserted
replaced
222:426321b46e44 | 223:c31722fcc9de |
---|---|
88 def draw(img, positions, color, lastCoordinate = None): | 88 def draw(img, positions, color, lastCoordinate = None): |
89 last = lastCoordinate+1 | 89 last = lastCoordinate+1 |
90 if lastCoordinate != None and lastCoordinate >=0: | 90 if lastCoordinate != None and lastCoordinate >=0: |
91 last = min(positions.length()-1, lastCoordinate) | 91 last = min(positions.length()-1, lastCoordinate) |
92 for i in range(0, last-1): | 92 for i in range(0, last-1): |
93 cv2.line(img, positions[i].astuple(), positions[i+1].astuple(), color) | 93 cv2.line(img, positions[i].asint().astuple(), positions[i+1].asint().astuple(), color) |
94 | 94 |
95 def playVideo(filename): | 95 def playVideo(filename): |
96 '''Plays the video''' | 96 '''Plays the video''' |
97 capture = cv2.VideoCapture(filename) | 97 capture = cv2.VideoCapture(filename) |
98 if capture.isOpened(): | 98 if capture.isOpened(): |
140 if homography != None: | 140 if homography != None: |
141 obj.projectedPositions = obj.positions.project(homography) | 141 obj.projectedPositions = obj.positions.project(homography) |
142 else: | 142 else: |
143 obj.projectedPositions = obj.positions | 143 obj.projectedPositions = obj.positions |
144 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) | 144 draw(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) |
145 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()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvRed) |
146 cv2.imshow('frame', img) | 146 cv2.imshow('frame', img) |
147 key = cv2.waitKey(50) | 147 key = cv2.waitKey(50) |
148 frameNum += 1 | 148 frameNum += 1 |
149 | 149 |
150 def printCvMat(cvmat, out = stdout): | 150 def printCvMat(cvmat, out = stdout): |