-
Notifications
You must be signed in to change notification settings - Fork 1
/
VideoData.py
82 lines (75 loc) · 3.29 KB
/
VideoData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
rareCategories = ["pushable_pullable",
"debris",
"ambulance",
"police",
"police_officer",
"personal_mobility",
"child"]
class VideoData:
_instance_tokens = set()
_total_people_area = 0.0
_total_vehicle_area = 0.0
video_path = ""
is_interesting = False
density_of_people = -1.0
density_of_vehicles = -1.0
number_of_people = 0
number_of_vehicles = 0
number_of_rare_objects = 0
peak_number_of_people = 0
peak_number_of_vehicles = 0
peak_area_of_people = 0
peak_area_of_vehicles = 0
def __init__(self, scene, video_path):
self.video_path = video_path
if scene is not None:
for sample in scene:
ann_list = sample["annotation_list"]
self.evaluate_anns(ann_list)
self.evaluate_anns_for_extreme_samples(ann_list)
self.density_of_people = \
self._total_people_area / len(scene) / 1600 / 900
self.density_of_vehicles = \
self._total_vehicle_area / len(scene) / 1600 / 900
def _calculate_area(self, corners):
x_dif = corners[2][0] - corners[0][0]
y_dif = corners[2][1] - corners[0][1]
return x_dif * y_dif
def evaluate_anns(self, ann_list):
for ann in ann_list:
if not ann["instance_token"] in self._instance_tokens:
self._instance_tokens.add(ann["instance_token"])
category = ann["category_name"]
corners = ann["corners"]
category = category.split(".")
general_category = category[0]
sub_category = category[-1]
if general_category == "human":
self.number_of_people += 1
if general_category == "vehicle":
self.number_of_vehicles += 1
if sub_category in rareCategories:
self.number_of_rare_objects += 1
def evaluate_anns_for_extreme_samples(self, ann_list):
number_of_people_in_sample = 0
number_of_vehicles_in_sample = 0
area_of_people_in_sample = 0
area_of_vehicles_in_sample = 0
for ann in ann_list:
category = ann["category_name"]
corners = ann["corners"]
category = category.split(".")
general_category = category[0]
sub_category = category[-1]
if general_category == "human":
number_of_people_in_sample += 1
area_of_people_in_sample += self._calculate_area(corners)
self._total_people_area += area_of_people_in_sample
if general_category == "vehicle":
number_of_vehicles_in_sample += 1
area_of_vehicles_in_sample += self._calculate_area(corners)
self._total_vehicle_area += area_of_vehicles_in_sample
self.peak_number_of_people = max(self.peak_number_of_people, number_of_people_in_sample)
self.peak_number_of_vehicles = max(self.peak_number_of_vehicles, number_of_vehicles_in_sample)
self.peak_area_of_people = max(self.peak_area_of_people, area_of_people_in_sample)
self.peak_area_of_vehicles = max(self.peak_area_of_vehicles, area_of_vehicles_in_sample)