Mercurial > hg > nsaunier > traffic-intelligence
comparison python/cvutils.py @ 661:dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 18 May 2015 13:53:25 +0200 |
| parents | 6668f541b915 |
| children | 15e244d2a1b5 |
comparison
equal
deleted
inserted
replaced
| 660:994dd644f6ab | 661:dc70d9e711f5 |
|---|---|
| 236 | 236 |
| 237 def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800): | 237 def imageBox(img, obj, frameNum, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800): |
| 238 'Computes the bounding box of object at frameNum' | 238 'Computes the bounding box of object at frameNum' |
| 239 x = [] | 239 x = [] |
| 240 y = [] | 240 y = [] |
| 241 for f in obj.features: | 241 if obj.hasFeatures(): |
| 242 if f.existsAtInstant(frameNum): | 242 for f in obj.getFeatures(): |
| 243 projectedPosition = f.getPositionAtInstant(frameNum).project(homography) | 243 if f.existsAtInstant(frameNum): |
| 244 x.append(projectedPosition.x) | 244 projectedPosition = f.getPositionAtInstant(frameNum).project(homography) |
| 245 y.append(projectedPosition.y) | 245 x.append(projectedPosition.x) |
| 246 y.append(projectedPosition.y) | |
| 246 xmin = min(x) | 247 xmin = min(x) |
| 247 xmax = max(x) | 248 xmax = max(x) |
| 248 ymin = min(y) | 249 ymin = min(y) |
| 249 ymax = max(y) | 250 ymax = max(y) |
| 250 xMm = px * (xmax - xmin) | 251 xMm = px * (xmax - xmin) |
| 302 obj.projectedPositions = obj.positions | 303 obj.projectedPositions = obj.positions |
| 303 cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) | 304 cvPlot(img, obj.projectedPositions, cvRed, frameNum-obj.getFirstInstant()) |
| 304 if frameNum in boundingBoxes.keys(): | 305 if frameNum in boundingBoxes.keys(): |
| 305 for rect in boundingBoxes[frameNum]: | 306 for rect in boundingBoxes[frameNum]: |
| 306 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) | 307 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvRed) |
| 307 elif len(obj.features) != 0: | 308 elif obj.hasFeatures(): |
| 308 imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height) | 309 imgcrop, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, obj, frameNum, homography, width, height) |
| 309 cv2.rectangle(img, (xCropMin, yCropMin), (xCropMax, yCropMax), cvBlue, 1) | 310 cv2.rectangle(img, (xCropMin, yCropMin), (xCropMax, yCropMax), cvBlue, 1) |
| 310 objDescription = '{} '.format(obj.num) | 311 objDescription = '{} '.format(obj.num) |
| 311 if userTypeNames[obj.userType] != 'unknown': | 312 if userTypeNames[obj.userType] != 'unknown': |
| 312 objDescription += userTypeNames[obj.userType][0].upper() | 313 objDescription += userTypeNames[obj.userType][0].upper() |
