-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmotion.py
More file actions
31 lines (27 loc) · 1.13 KB
/
motion.py
File metadata and controls
31 lines (27 loc) · 1.13 KB
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
import numpy as np
from person_detection import Infer
class Motion:
def __init__(self, video_path, debug):
self.video_path = video_path
bounding_boxes, self.infer_frame_size = Infer(video_path, debug=debug)
t_area_data = self.calc_area(bounding_boxes)
self.area_data = self.preprocess_data(t_area_data)
self.bboxes = np.array(bounding_boxes)
for i in range(self.bboxes.shape[1]):
self.bboxes[:, i] = self.preprocess_data(self.bboxes[:, i])
def preprocess_data(self, data, kernel_size = 10):
##rectify some data 361-366
# data[361:367] = data[360]
#average smooth
kernel = np.ones(kernel_size) / kernel_size
temp = np.convolve(data, kernel, mode='same')
affected_idx = int(kernel_size/2)
data[affected_idx:-affected_idx] = temp[affected_idx:-affected_idx]
return data
def calc_area(self, bboxes):
area_data = []
for bbox in bboxes:
area = (bbox[2] - bbox[0]) * (bbox[3] - bbox[1])
area_data.append(area)
area_data = np.array(area_data)
return area_data