srianant / kalman_filter_multi_object_tracking

Multiple object tracking using Kalman Filter and Hungarian Algorithm - OpenCV
MIT License
539 stars 165 forks source link

What motion model is used? #13

Open r7vme opened 5 years ago

r7vme commented 5 years ago

Hello, thanks for nice repo. So far i believe motion model is incorrect.

For state matrix you use [[x], [y]], but state transition matrix is [[1, dt], [0, 1]], which is believe is for state matrix like [x, vx] (one dimentional constant velocity model). You're computing dot product between them here, which seems incorrect.

My suggestion would be to use two dimentional constant velocity model.

State matrix:

[[x],
 [y],
 [vx],
 [vy]]

Transition matrix:

[[1, 0, dt, 0],
 [0, 1, 0, dt],
 [0, 0, 1, 0],
 [0, 0, 0, 1]],
BartvanMarrewijk commented 3 years ago

Also some variables have to be updated, right?: self.u = np.zeros((4, 1)) # previous state vector self.A = np.array([[1, 0,0,0], [0,1,0,0], [0, 0,0,0], [0, 0,0,0]]) self.b = np.array([[0], [0],[0],[0]]) self.P = np.diag((3.0, 3.0,0,0)) # covariance matrix

and in tracker.py from line 161: ` for i in range(len(assignment)): self.tracks[i].KF.predict()

        if(assignment[i] != -1):
            self.tracks[i].skipped_frames = 0
            # self.tracks[i].prediction = self.tracks[i].KF.correct(
            #                             detections[assignment[i]], 1)
            self.tracks[i].prediction = self.tracks[i].KF.correct(
                                        np.array(([detections[assignment[i]][0][0]], [detections[assignment[i]][1][0]],[0],[0])), 1)
        else:
            # self.tracks[i].prediction = self.tracks[i].KF.correct(
            #                             np.array([[0], [0]]), 0)
            self.tracks[i].prediction = self.tracks[i].KF.correct(
                                        np.array([[0], [0],[0],[0]]), 0)

        if(len(self.tracks[i].trace) > self.max_trace_length):
            for j in range(len(self.tracks[i].trace) -
                           self.max_trace_length):
                del self.tracks[i].trace[j]

        # self.tracks[i].trace.append(self.tracks[i].prediction)
        self.tracks[i].trace.append(np.array(([self.tracks[i].prediction[0][0]],[self.tracks[i].prediction[1][0]])))
        self.tracks[i].KF.lastResult = self.tracks[i].prediction`