Note that there are some explanatory texts on larger screens.

plurals
  1. POKalman Filter in OpenCV + Python
    primarykey
    data
    text
    <p>I wrote this code to use the Kalman Filter to predict the trajectory in 2D, I am trying to use the Opencv Kalman Filter in python, here is my code:</p> <pre><code>import cv2.cv as cv kalman = cv.CreateKalman(4, 2, 0) i = 0 # I read the point from an .txt file with open('trajectory_0000.txt') as f: array = [] for line in f: # read rest of lines array.append([int(x) for x in line.split()]) vec=array.pop() x=vec[0] y=vec[1] # I obtain the (x,y) points if i== 0: # This happens only one time to initialize the kalman Filter with the first (x,y) point kalman.state_pre[0,0] = x kalman.state_pre[1,0] = y kalman.state_pre[2,0] = 0 kalman.state_pre[3,0] = 0 # set kalman transition matrix kalman.transition_matrix[0,0] = 1 kalman.transition_matrix[1,1] = 1 kalman.transition_matrix[2,2] = 1 kalman.transition_matrix[3,3] = 1 # set Kalman Filter cv.SetIdentity(kalman.measurement_matrix, cv.RealScalar(1)) cv.SetIdentity(kalman.process_noise_cov, cv.RealScalar(1e-5))## 1e-5 cv.SetIdentity(kalman.measurement_noise_cov, cv.RealScalar(1e-1)) cv.SetIdentity(kalman.error_cov_post, cv.RealScalar(0.1)) else: # Kalman prediction with Kalman Correction with the points I have in trajectory_0000.txt kalman_prediction = cv.KalmanPredict(kalman) rightPoints = cv.CreateMat(2, 1, cv.CV_32FC1) rightPoints[0,0]=x rightPoints[1,0]=y kalman.state_pre[0,0] = x kalman.state_pre[1,0] = y kalman.state_pre[2,0] = 0 kalman.state_pre[3,0] = 0 estimated = cv.KalmanCorrect(kalman, rightPoints) i=i+1 print str( x ) + " - " + str( y ) # Here we do not have more points to apply the Kalman Correct, so I need to predict the points for i in range(20): kalman_prediction = cv.KalmanPredict(kalman) x= kalman_prediction[0,0] y= kalman_prediction[1,0] print "Kalman prediction " +str(i) + ": "+str( x ) + ", " + str( y ) </code></pre> <p>Here the <a href="http://img850.imageshack.us/img850/5980/t178.jpg" rel="nofollow">Results of my code</a>, white points are my points, and green points are the Kalman Prediction, the red circle is the last point of my points. As you can see, that code predict points(green points) but they far of my points (red point). I changed the parameters without success, do you have any idea?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload