Hi, when I am trying to use the opencv Kalman Filter to track a target. My initial setup is as below: deltaTime = 1/30 #time approximately for a single frame state = np.zeros((4, 1), np.float32) measure = np.zeros((2, 1), np.float32)
kalman = cv2.KalmanFilter(4, 2, 0) #control vector = 0, assume linear motion.
kalman.measurementMatrix = np.array([[1,0,0,0], [0,1,0,0]],np.float32)
kalman.transitionMatrix = np.array([[1,0,deltaTime,0], [0,1,0,deltaTime], [0,0,1,0], [0,0,0,1]],np.float32)
kalman.processNoiseCov = np.array([[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]],np.float32) * 0.03 I am able to track the target properly when the measurement/observation of the object is exist.However, when the object is lost in the frame, the kalman filter's prediction stays constant at the last known position of the target. Meaning, the prediction component of the kalman filter is not working in my case. The code for detection and no detection is shown below:
if ini.detection==1: #target detected, this component is working correctly
kalman.correct(ini.measureCentreV2)
state = kalman.predict()
else:
ini.detection==0: #no detection
kalman.statePost = state #pass the last known state to KF as the previous state
noDetectstate = np.zeros((2, 1), np.float32)
noDetectstate[0] = state[0]
noDetectstate[1] = state[1]
kalman.correct(noDetectstate)
state = kalman.predict() # The problem is here, the value of the state did not change after the object is not being detected
Thank you for any help in advance