I have a list with the following sample key value pairs:
results : {'ROI_0':[{'obj_id':1,'obj_name':'truck', 'obj_confi':93.55, 'bb_box': ['x','y','w','h']},
{'obj_id':2,'obj_name':'truck', 'obj_confi':91.35, 'bb_box': ['x','y','w','h']},
{'obj_id':3,'obj_name':'truck', 'obj_confi':92.65, 'bb_box': ['x','y','w','h']},
{'obj_id':4,'obj_name':'car', 'obj_confi':90.31, 'bb_box': ['x','y','w','h']},
{'obj_id':5,'obj_name':'car', 'obj_confi':90.31, 'bb_box': ['x','y','w','h']}
]}
I need to obtain another list which looks like the one below:
aggreg_results : {'ROI_0':[{'obj_occurances': 3, 'obj_name': 'truck', 'obj_ids':[1,2,3]},
{'obj_occurances': 2, 'obj_name': 'car', 'obj_ids':[4,5]}
]}
Unable to figure out the logic to this.
My answer is a bit long, but I think its easier to understand. First of all I will create a dict that have obj_name as unique key, then count all occurences and store the obj_ids
Now I have a dict like this in
unique_items:Then I just convert it into a dict as whatever format you want
Finally I get the the
aggreg_resultsas you expectedI hope it helps!