forked from citrusvanilla/multiplewavetracking_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mwt_tracking.py
102 lines (75 loc) · 2.85 KB
/
mwt_tracking.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
##
## Near-shore Wave Tracking
## mwt_tracking.py
##
## Created by Justin Fung on 9/1/17.
## Copyright 2017 justin fung. All rights reserved.
##
## ====================================================================
"""Functions for using tracking to recognize actual waves.
Method for recognition is:
-1. merge potential waves
-2. track potential waves
-3. declare actual waves conditional on wave dynamics
"""
from __future__ import division
import numpy as np
import mwt_objects
## ====================================================================
def will_be_merged(section, list_of_waves):
"""Boolean evaluating whether or not a section is in an existing
wave's search region.
Args:
section: a wave object
list_of_waves: a list of waves having search regions in which a
wave might fall
Returns:
going_to_be_merged: evaluates to True if the section is in an
existing wave's search region.
"""
# All sections are initially new waves & will not be merged.
going_to_be_merged = False
# Find the section's major axis' projection on the y axis.
delta_y_left = np.round(section.centroid[0]
* np.tan(np.deg2rad(section.axis_angle)))
left_y = int(section.centroid[1] + delta_y_left)
# For each existing wave, see if the section's axis falls in
# another wave's search region.
for wave in list_of_waves:
if left_y >= wave.searchroi_coors[0][1] \
and left_y <= wave.searchroi_coors[3][1]:
going_to_be_merged = True
break
return going_to_be_merged
def track(list_of_waves, frame, frame_number, last_frame):
"""Tracking routine performed by updating the dynamic Wave
attributes.
Args:
list_of_waves: a list of waves to track
frame: a frame from a cv2.video_reader object
frame_number: number of the frame in a sequence
last_frame: final frame number, provided to kill all waves if
necessary
Returns:
NONE: updates wave attributes
"""
for wave in list_of_waves:
# Update search roi for tracking waves and merging waves.
wave.update_searchroi_coors()
# Capture all non-zero points in the new roi.
wave.update_points(frame)
# Check if wave has died.
wave.update_death(frame_number)
# Kill all waves if it is the last frame in the video.
if frame_number == last_frame:
wave.death = frame_number
# Update centroids.
wave.update_centroid()
# Update bounding boxes for display.
wave.update_boundingbox_coors()
# Update displacement vectors.
wave.update_displacement()
# Update wave masses.
wave.update_mass()
# Check masses and dynamics conditionals.
wave.update_recognized()