-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsizeEstim.py
More file actions
53 lines (37 loc) · 1.34 KB
/
sizeEstim.py
File metadata and controls
53 lines (37 loc) · 1.34 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'''
sizeEstim.py
Bounding box size estimation.
Alternative: could use some totally different method to improve estimate of sides, e.g. ICP
Built to be executed each time instant in casual order. Does not store history.
MiS - Martin Sanfridson, January 2023
'''
import numpy as np
from filterpy.kalman import KalmanFilter
from filterpy.common import Q_discrete_white_noise
class sizeEstim():
#This class is for estimation of the sides of the box
def __init__(self,x_init,samplingPeriod):
#define constant velocity model
self.dt = samplingPeriod
self.kf = KalmanFilter(dim_x=2, dim_z=2)
self.kf.F = np.array([[1,0],[0,1]])
self.kf.R = np.diag([0.1,0.1]) #meas noise
self.kf.P = np.diag([10,10]) #covariance
#self.kf.Q = Q_discrete_white_noise(dim=2,dt=self.dt,var=1.0)
self.kf.Q = np.eye(2)
self.kf.H = np.array([[1,0],[0,1]])
self.kf.x = x_init
def setMeasNoise(self,R):
self.kf.R = R
def setModelNoise(self,Q):
self.kf.Q = Q
def update(self,meas):
self.kf.update(meas)
def predict(self):
self.kf.predict()
def getState(self):
return self.kf.x
def getCovariance(self):
return self.kf.P
def getLengthAndWidth(self):
return self.kf.x[0],self.kf.x[1]