-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.py
110 lines (93 loc) · 3.38 KB
/
counter.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# import os
# import pandas
# from pprint import pprint
from collections import OrderedDict
# import logging
## from framechecker we get the frame number and the time period
# import frame_checker
# frame
# frame_num
# frame_time
# dict
# small_car
# big_car
# buses
# three_wheeler
# LCV
# two_wheeler
# trucks
# bycycle
# pedestrian
# mv_data
#
class count():
def __init__(self):
# self.data = {-1:{"frame_path":"",
# "classes":{ "small_car":[],
# "big_car":[],
# "buses":[],
# "three_wheeler":[],
# "LCV":[],
# "two_wheeler":[],
# "trucks":[],
# "bicycle":[],
# "pedestrian":[]
# },
# "target_frame": True
# }
#
# }
self.data = {}
def set(self, imagename):
imageparams = imagename.strip().split("/")[-1].split("_")
frame = imageparams[1].split("time")[0]
time = float(imageparams[-1].split(".jpg")[0])
self.data[int(frame)] = {"frame_path":imagename,
"frame_time":time,
"classes":{ "small_car":[],
"big_car":[],
"buses":[],
"three_wheeler":[],
"LCV":[],
"two_wheeler":[],
"trucks":[],
"bicycle":[],
"pedestrian":[]
},
"target_frame":False
}
def set_target_as_zero(self):
self.data[0]["target_frame"] = True
def sort_dict(self):
# pprint(self.data.items())
self.data = OrderedDict(sorted(self.data.items()))
def find_target_frame(self):
# print(type(self.data))
for keys, vals in self.data.items():
# print(keys, self.data[keys]["frame_path"], self.data[keys]["target_frame"])
if self.data[keys]["target_frame"] == True:
return keys
def set_target_frame(self, k):
if k > len(self.data) or k < 0:
return False, ""
else:
for keys, vals in self.data.items():
self.data[keys]["target_frame"] = False
self.data[k]["target_frame"] = True
return True, self.data[k]["frame_path"]
def add_entity(self, entity):
keyy = self.find_target_frame()
self.data[keyy]["classes"][entity].append(1)
def remove_entity(self, entity):
keyy = self.find_target_frame()
self.data[keyy]["classes"][entity] = self.data[keyy]["classes"][entity][:-1]
def clear_data(self):
# to clear all the values in the dictionary for new video
for value in self.data:
print(value)
def display_all(self):
return self.data
def display(self, k):
return self.data[k]
# def addValue(self, item):
# self.data