comparison scripts/extract-appearance-images.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 933670761a57
comparison
equal deleted inserted replaced
946:e5970606066f 947:053484e08947
66 ret, img = capture.read() 66 ret, img = capture.read()
67 distorted = True 67 distorted = True
68 if ret: 68 if ret:
69 if frameNum%50 == 0: 69 if frameNum%50 == 0:
70 print('frame number: {}'.format(frameNum)) 70 print('frame number: {}'.format(frameNum))
71 for obj in objects: 71 for obj in objects[:]:
72 if obj.existsAtInstant(frameNum): 72 if obj.existsAtInstant(frameNum):
73 if (10+frameNum-obj.getFirstInstant())%args.nFramesStep == 0: 73 if (10+frameNum-obj.getFirstInstant())%args.nFramesStep == 0:
74 currentImageFeatures = set([f.num for f in obj.getFeatures() if f.existsAtInstant(frameNum)]) 74 currentImageFeatures = set([f.num for f in obj.getFeatures() if f.existsAtInstant(frameNum)])
75 if not hasattr(obj, 'lastImageFeatures') or len(currentImageFeatures.intersection(obj.lastImageFeatures))/len(currentImageFeatures.union(obj.lastImageFeatures)) < args.overlap: 75 if not hasattr(obj, 'lastImageFeatures') or len(currentImageFeatures.intersection(obj.lastImageFeatures))/len(currentImageFeatures.union(obj.lastImageFeatures)) < args.overlap:
76 obj.lastImageFeatures = currentImageFeatures 76 obj.lastImageFeatures = currentImageFeatures
78 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) 78 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
79 distorted = False 79 distorted = False
80 croppedImg = cvutils.imageBox(img, obj, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels) 80 croppedImg = cvutils.imageBox(img, obj, frameNum, invHomography, width, height, classifierParams.percentIncreaseCrop, classifierParams.percentIncreaseCrop, classifierParams.minNPixels)
81 if croppedImg is not None: 81 if croppedImg is not None:
82 cv2.imwrite(args.directoryName+os.sep+moving.userTypeNames[obj.getUserType()]+os.sep+args.imagePrefix+'-{}-{}.png'.format(obj.getNum(), frameNum), croppedImg) 82 cv2.imwrite(args.directoryName+os.sep+moving.userTypeNames[obj.getUserType()]+os.sep+args.imagePrefix+'-{}-{}.png'.format(obj.getNum(), frameNum), croppedImg)
83 # elif obj.getLastInstant() == frameNum: 83 elif obj.getLastInstant() == frameNum:
84 # objects.remove(obj) 84 objects.remove(obj)
85 objects[:] = [obj for obj in objects if obj.getLastInstant() != frameNum]
86 frameNum += 1 85 frameNum += 1
87 86
88 # todo speed info: distributions AND min speed equiprobable 87 # todo speed info: distributions AND min speed equiprobable
89 88