-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from tryolabs/custom-filter
- Loading branch information
Showing
4 changed files
with
79 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .drawing import * | ||
from .tracker import Detection, Tracker | ||
from .filter import FilterSetup | ||
from .utils import get_cutout, print_objects_as_table | ||
from .video import Video |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import numpy as np | ||
from filterpy.kalman import KalmanFilter | ||
|
||
|
||
class FilterSetup: | ||
def __init__(self, R: float = 4.0, Q: float = 0.1, P: float = 10.0): | ||
self.R = R | ||
self.Q = Q | ||
self.P = P | ||
|
||
def create_filter(self, initial_detection: np.array): | ||
num_points = initial_detection.shape[0] | ||
dim_z = 2 * num_points | ||
dim_x = 2 * 2 * num_points # We need to accommodate for velocities | ||
|
||
filter = KalmanFilter(dim_x=dim_x, dim_z=dim_z) | ||
|
||
# State transition matrix (models physics): numpy.array() | ||
filter.F = np.eye(dim_x) | ||
dt = 1 # At each step we update pos with v * dt | ||
|
||
filter.F[:dim_z, dim_z:] = dt * np.eye(dim_z) | ||
|
||
# Measurement function: numpy.array(dim_z, dim_x) | ||
filter.H = np.eye(dim_z, dim_x,) | ||
|
||
# Measurement uncertainty (sensor noise): numpy.array(dim_z, dim_z) | ||
filter.R *= self.R | ||
|
||
# Process uncertainty: numpy.array(dim_x, dim_x) | ||
# Don't decrease it too much or trackers pay too little attention to detections | ||
filter.Q[dim_z:, dim_z:] *= self.Q | ||
|
||
# Initial state: numpy.array(dim_x, 1) | ||
filter.x[:dim_z] = np.expand_dims(initial_detection.flatten(), 0).T | ||
|
||
# Estimation uncertainty: numpy.array(dim_x, dim_x) | ||
filter.P[dim_z:, dim_z:] *= self.P | ||
|
||
return filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters