srianant/kalman_filter_multi_object_tracking

Wrong use of prediction when no measurements are available

wartek69 opened this issue · 1 comments

Hi,
Thank you for the clear code & useful repo!
I think there is a small mistake in the usage of the Kalmann filter update step.

        if not flag:  # update using prediction
            self.b = self.lastResult
        else:  # update using detection
            self.b = b
        C = np.dot(self.A, np.dot(self.P, self.A.T)) + self.R
        K = np.dot(self.P, np.dot(self.A.T, np.linalg.inv(C)))


        self.u = np.round(self.u + np.dot(K, (self.b - np.dot(self.A,
                                                              self.u))))

In the snippet above you are using a prediction as a measurement when the flag is set. I suppose this was done to keep predicting the vessel motions when a detection disappears for a short amount of time. I do not think it is correct since the prediction will then be overconfident as it will be using the measurement noise instead of the process noise.

The correct way of handling a situation when no detections are available for some frames is to use the predict step instead of the update step.

Is my understanding correct or am I missing something?
The link to the code above is here:
https://github.com/srianant/kalman_filter_multi_object_tracking/blob/625e6c0965bb777a888ab46ed70978ad9fc93774/kalman_filter.py#L68C1-L103C22

Br
Alex

devnim commented

Hi Alex, could you please how you would do it with code?