Last active
April 11, 2018 02:27
-
-
Save mjdietzx/f212156cc03b289aaa35500b4f7822b8 to your computer and use it in GitHub Desktop.
Utilize uncertainty for improved person-tracking/face-matching performance in Rekognition video face search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment