I am working on a video object tracking problem. I am using Kalman filter to predict and correct the object position return by an algorithm such as CamShift. I want to adjust the likelihood probability of the states so as to customize the weight of the states before feeding to the Kalman filter. Currently this the code I have:
#Define kalman filter
kalman = cv2.KalmanFilter(4, 2, 2)
# initial position: (x0,y0)
state = np.array([col+w/2,row+h/2,0,0],dtype='float64')
kalman.transitionMatrix = np.array([[1.,0., .1, 0.],
[0., 1., 0., .1],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
kalman.measurementMatrix = 1. * np.eye(2, 4)
kalman.processNoiseCov = 1e-5 * np.eye(4, 4)
kalman.measurementNoiseCov = 1e-3 * np.eye(2, 2)
kalman.errorCovPost = 1e-1 * np.eye(4, 4)
kalman.statePost = state
Here, 'row' and 'col' are the top-left row and column indices, respectively of the current rectangular box containing the object position, and 'w' and 'h' are the width and height, respectively of the rectangular box containing the object.
Now, suppose (x1,y1) is the position returned by my algorithm (e.g. CamShift,Optical flow etc.).
Now I pass (x1,y1) and the explicitly calculated velocity (v) and acceleration(a) to Kalman filter as:
#Predict using kalman filter
prediction = kalman.predict()
# Update kalman state using optical flow results
pts=np.array([np.float32(x1),np.float32(y1),np.float32(v),np.float32(a)],
dtype=np.float64)
state=pts
measurement = (np.dot(kalman.measurementNoiseCov, np.random.randn(2,
1))).reshape(-1)
measurement = np.dot(kalman.measurementMatrix, state) + measurement
# use optical flow to correct kalman filter
prediction_new=kalman.correct(measurement)
It is all fine till here. But what if I want to give only less than 0.5 probability weightage to the previous state (=[x0,y0,0,0]) compared to the present state (=[x1,y1,v,a]) while computing 'prediction_new'. I have extensively searched the Kalman filter OpenCV library as well as online, but couldn't find an answer. Appreciate help on this. Thanks in advance.