diff python/cvutils.py @ 947:053484e08947

found a more elegant solution, making a copy of the list to iterate
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Jul 2017 11:31:42 -0400
parents e5970606066f
children c03d2c0a4c04
line wrap: on
line diff
--- a/python/cvutils.py	Fri Jul 21 11:25:20 2017 -0400
+++ b/python/cvutils.py	Fri Jul 21 11:31:42 2017 -0400
@@ -327,7 +327,7 @@
                     if printFrames:
                         print('frame {0}'.format(frameNum))
                     # plot objects
-                    for obj in objects:
+                    for obj in objects[:]:
                         if obj.existsAtInstant(frameNum):
                             if not hasattr(obj, 'projectedPositions'):
                                 obj.projectedPositions = obj.getPositions().homographyProject(homography)
@@ -344,7 +344,8 @@
                                 if frameNum not in toMatches[obj.getNum()]:
                                     objDescription += " FA"
                             cv2.putText(img, objDescription, obj.projectedPositions[frameNum-obj.getFirstInstant()].asint().astuple(), cv2.FONT_HERSHEY_PLAIN, 1, cvColors[colorType][obj.getNum()])
-                    objects[:] = [obj for obj in objects if obj.getLastInstant() != frameNum]
+                        if obj.getLastInstant() == frameNum:
+                            objects.remove(obj)
                     # plot object bounding boxes
                     if frameNum in boundingBoxes.keys():
                         for rect in boundingBoxes[frameNum]: