Mercurial Hosting > traffic-intelligence
comparison python/cvutils.py @ 903:81ee5aaf213d
changed workflow of display trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 22 Jun 2017 17:02:03 -0400 |
parents | f5a49b603e8b |
children | 8f60ecfc2f06 |
comparison
equal
deleted
inserted
replaced
902:c69a8defe5c3 | 903:81ee5aaf213d |
---|---|
315 lastFrameNum = lastFrameNumArg | 315 lastFrameNum = lastFrameNumArg |
316 if nZerosFilenameArg is None: | 316 if nZerosFilenameArg is None: |
317 nZerosFilename = int(ceil(log10(lastFrameNum))) | 317 nZerosFilename = int(ceil(log10(lastFrameNum))) |
318 else: | 318 else: |
319 nZerosFilename = nZerosFilenameArg | 319 nZerosFilename = nZerosFilenameArg |
320 objectToDeleteIds = [] | |
321 while ret and not quitKey(key) and frameNum <= lastFrameNum: | 320 while ret and not quitKey(key) and frameNum <= lastFrameNum: |
322 ret, img = capture.read() | 321 ret, img = capture.read() |
323 if ret: | 322 if ret: |
324 if undistort: | 323 if undistort: |
325 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) | 324 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) |
326 if printFrames: | 325 if printFrames: |
327 print('frame {0}'.format(frameNum)) | 326 print('frame {0}'.format(frameNum)) |
328 if len(objectToDeleteIds) > 0: | |
329 objects = [o for o in objects if o.getNum() not in objectToDeleteIds] | |
330 objectToDeleteIds = [] | |
331 # plot objects | 327 # plot objects |
332 for obj in objects: | 328 for obj in objects: |
333 if obj.existsAtInstant(frameNum): | 329 if obj.existsAtInstant(frameNum): |
334 if obj.getLastInstant() == frameNum: | |
335 objectToDeleteIds.append(obj.getNum()) | |
336 if not hasattr(obj, 'projectedPositions'): | 330 if not hasattr(obj, 'projectedPositions'): |
337 if homography is not None: | 331 if homography is not None: |
338 obj.projectedPositions = obj.positions.project(homography) | 332 obj.projectedPositions = obj.positions.project(homography) |
339 else: | 333 else: |
340 obj.projectedPositions = obj.positions | 334 obj.projectedPositions = obj.positions |
347 objDescription += moving.userTypeNames[obj.userType][0].upper() | 341 objDescription += moving.userTypeNames[obj.userType][0].upper() |
348 if len(annotations) > 0: # if we loaded annotations, but there is no match | 342 if len(annotations) > 0: # if we loaded annotations, but there is no match |
349 if frameNum not in toMatches[obj.getNum()]: | 343 if frameNum not in toMatches[obj.getNum()]: |
350 objDescription += " FA" | 344 objDescription += " FA" |
351 cv2.putText(img, objDescription, obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvColors[colorType][obj.getNum()]) | 345 cv2.putText(img, objDescription, obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvColors[colorType][obj.getNum()]) |
346 if obj.getLastInstant() == frameNum: | |
347 objects.remove(obj) | |
352 # plot object bounding boxes | 348 # plot object bounding boxes |
353 if frameNum in boundingBoxes.keys(): | 349 if frameNum in boundingBoxes.keys(): |
354 for rect in boundingBoxes[frameNum]: | 350 for rect in boundingBoxes[frameNum]: |
355 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvColors[colorType][obj.getNum()]) | 351 cv2.rectangle(img, rect[0].asint().astuple(), rect[1].asint().astuple(), cvColors[colorType][obj.getNum()]) |
356 # plot ground truth | 352 # plot ground truth |