Mercurial Hosting > traffic-intelligence
changeset 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 | 584b9405e494 |
files | python/cvutils.py scripts/classify-objects.py scripts/extract-appearance-images.py |
diffstat | 3 files changed, 10 insertions(+), 10 deletions(-) [+] |
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]:
--- a/scripts/classify-objects.py Fri Jul 21 11:25:20 2017 -0400 +++ b/scripts/classify-objects.py Fri Jul 21 11:31:42 2017 -0400 @@ -98,19 +98,19 @@ print('frame number: {}'.format(frameNum)) #if undistort: # img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) - for obj in objects: + for obj in objects[:]: if obj.getFirstInstant() <= frameNum: # if images are skipped obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, classifierParams.maxPedestrianSpeed, classifierParams.maxCyclistSpeed, classifierParams.nFramesIgnoreAtEnds, invHomography, intrinsicCameraMatrix, distortionCoefficients) currentObjects.append(obj) - objects[:] = [obj for obj in objects if obj.getFirstInstant() > frameNum] + objects.remove(obj) - for obj in currentObjects: + for obj in currentObjects[:]: if obj.getLastInstant() <= frameNum: # if images are skipped obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = classifierParams.minSpeedEquiprobable, speedProbabilities = speedProbabilities, maxPercentUnknown = classifierParams.maxPercentUnknown) pastObjects.append(obj) + currentObjects.remove(obj) else: obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels, classifierParams.hogRescaleSize, classifierParams.hogNOrientations, classifierParams.hogNPixelsPerCell, classifierParams.hogNCellsPerBlock, classifierParams.hogBlockNorm) - currentObjects[:] = [obj for obj in objects if obj.getLastInstant() > frameNum] frameNum += 1 for obj in currentObjects:
--- a/scripts/extract-appearance-images.py Fri Jul 21 11:25:20 2017 -0400 +++ b/scripts/extract-appearance-images.py Fri Jul 21 11:31:42 2017 -0400 @@ -68,7 +68,7 @@ if ret: if frameNum%50 == 0: print('frame number: {}'.format(frameNum)) - for obj in objects: + for obj in objects[:]: if obj.existsAtInstant(frameNum): if (10+frameNum-obj.getFirstInstant())%args.nFramesStep == 0: currentImageFeatures = set([f.num for f in obj.getFeatures() if f.existsAtInstant(frameNum)]) @@ -80,9 +80,8 @@ croppedImg = cvutils.imageBox(img, obj, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels) if croppedImg is not None: cv2.imwrite(args.directoryName+os.sep+moving.userTypeNames[obj.getUserType()]+os.sep+args.imagePrefix+'-{}-{}.png'.format(obj.getNum(), frameNum), croppedImg) -# elif obj.getLastInstant() == frameNum: -# objects.remove(obj) - objects[:] = [obj for obj in objects if obj.getLastInstant() != frameNum] + elif obj.getLastInstant() == frameNum: + objects.remove(obj) frameNum += 1 # todo speed info: distributions AND min speed equiprobable