Skip to content

SNefertitiB/2D_kalman_filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

2D_kalman_filter

Kalman filter for object tracking

How it works

Object detection Steps

  1. Parse video into frames1

  2. Detect plates in each frame2

  3. Add bounding box3,4 for each plate

Prediction

  1. Use model to get bounding box for each plate

  2. get centroid from bounding box

  3. compare each detection to know plates

    if detection matches known plate, use it to do the kalman update

    if detection does not match know plate, create new plate

  4. predict location for any know plates that were not detected

Kalman Filter

single object

multi object

Starting State

We are using yolov5 as the object detection model for measurements.

The model returns two coordinates $(x_1, y_1)$ and $(x_2, y_2)$ that describe a rectangular bounding box around around the plate. For the Kalman filter, we will need the centroid of each box. Since the bounding box is a rectangle, we can use the following midpoint formula to find the centroid:

centroid coordinates = $ (\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2})$

Velocity

At each measurement, we update the velocity of the object as well as the predicted location.

average velocity: $\bar_v = $

current time: $t$

displacement between measurements: $\Delta z = z_t - z_{t-1}$

change in time: $\Delta t = t - (t - 1)$

$\bar_v = \frac{\Delta z}{\Delta t}$

2 Dimensional Kalman filter with variable velocity

Step 1: Prediction

  • prior.x = prior.x + velocity_x
  • prior.y = prior.y + velocity_y

Step 2: Update (if the object is detected)

  • z = center of bounding box
  • velocity update
    • velocity_x = z.x - prev.x
    • velocity_y = z.y - prev.y
  • prev update
    • prev = z
  • prior update
    • new_x = (prior.x + z.x) / 2
    • new_y = (self.prior.y + z.y) / 2)
    • prior = (new_x, new_y)

Multi Object Tracking

To track multiple objects you need to:

  1. correctly assign each measurement to a tracker

  2. use the distance formula to figure out which measurement is closest to the pre-update prediction

  3. use that measurement to update the prediction

  4. if distance to the closest prediction is greater than some threshold, don't assign the measurement to any tracker

    note: any trackers that don't receive a measurement for a given frame will skip the update step of the Kalman filter

  5. for any unassigned measurements, initialize a new tracker object

Future updates

  1. get rid of duplicate measurements
  2. use distance formula to find the nearest measurement for known plates

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages