Guest User

Untitled

a guest
Feb 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import collections
  2.  
  3.  
  4. def sort_raw_rekognition_results(results):
  5. indices = collections.defaultdict(list) # unique people detected in video to a `list` of their `PersonMatch` objects
  6.  
  7. timestamps = collections.defaultdict(list) # `lists` maintain order so we can keep track of people and their indices
  8. timestamps_indices = collections.defaultdict(list)
  9.  
  10. for p in self.results['Persons']:
  11. index = p['Person'].pop('Index') # pop off indices so we identical `dicts` will equal each other
  12. timestamp = p['Timestamp']
  13.  
  14. if p in timestamps[timestamp]: # a duplicate
  15. i = timestamps[timestamp].index(p)
  16. _index = timestamps_indices[timestamp][i]
  17.  
  18. indices[_index].remove(p)
  19.  
  20. assert timestamps[timestamp][i] == p
  21. timestamps[timestamp].pop(i)
  22. timestamps_indices[timestamp].pop(i)
  23.  
  24. index = ','.join(sorted([str(index), *str(_index).split(',')])) # comma separated indices are where the uncertainty is
  25.  
  26. assert p not in indices[index]
  27. assert p not in timestamps[timestamp]
  28. assert index not in timestamps_indices[timestamp]
  29. indices[index].append(p)
  30. timestamps[timestamp].append(p)
  31. timestamps_indices[timestamp].append(index)
  32.  
  33. return indices
Add Comment
Please, Sign In to add comment