Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def sort_raw_rekognition_results(results):
- indices = collections.defaultdict(list) # unique people detected in video to a `list` of their `PersonMatch` objects
- timestamps = collections.defaultdict(list) # `lists` maintain order so we can keep track of people and their indices
- timestamps_indices = collections.defaultdict(list)
- for p in self.results['Persons']:
- index = p['Person'].pop('Index') # pop off indices so we identical `dicts` will equal each other
- timestamp = p['Timestamp']
- if p in timestamps[timestamp]: # a duplicate
- i = timestamps[timestamp].index(p)
- _index = timestamps_indices[timestamp][i]
- indices[_index].remove(p)
- assert timestamps[timestamp][i] == p
- timestamps[timestamp].pop(i)
- timestamps_indices[timestamp].pop(i)
- index = ','.join(sorted([str(index), *str(_index).split(',')])) # comma separated indices are where the uncertainty is
- assert p not in indices[index]
- assert p not in timestamps[timestamp]
- assert index not in timestamps_indices[timestamp]
- indices[index].append(p)
- timestamps[timestamp].append(p)
- timestamps_indices[timestamp].append(index)
- return indices
Add Comment
Please, Sign In to add comment