-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkalman.py
28 lines (20 loc) · 935 Bytes
/
kalman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import cv2
import numpy as np
class KalmanFilter:
def __init__(self):
self.kalman = cv2.KalmanFilter(4,2)
self.kalman.measurementMatrix = np.array([[1,0,0,0],
[0,1,0,0]],np.float32)
self.kalman.transitionMatrix = np.array([[1,0,1,0],
[0,1,0,1],
[0,0,1,0],
[0,0,0,1]],np.float32)
self.kalman.processNoiseCov = np.array([[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]],np.float32) * 0.01
def updatePosition(self,position):
position = np.array(position, dtype=np.float32)
self.kalman.correct(position)
def predictPosition(self):
return self.kalman.predict()