-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
samples/python/kalman.py is not constant rotation as documented #20091
Description
The comments and documentation in samples/python/kalman.py do not match the behavior of the program.
This line prints that the speed is constant, but it is clear from running the program that the speed is not constant.
opencv/samples/python/kalman.py
Line 4 in a604d44
| Rotation speed is constant. |
Because of:
opencv/samples/python/kalman.py
Line 41 in a604d44
| kalman.processNoiseCov = 1e-5 * np.eye(2) |
and
opencv/samples/python/kalman.py
Lines 85 to 86 in a604d44
| process_noise = sqrt(kalman.processNoiseCov[0,0]) * np.random.randn(2, 1) | |
| state = np.dot(kalman.transitionMatrix, state) + process_noise |
The state variable holds the angle and speed, which at each step is modified by the process transition matrix plus the process noise. Since the process noise is added onto the state variable for the speed of rotation, the speed is not constant -- it is a random walk.
The random walk in speed (and location) is more visually interesting than tracking a constant rotation, but it isn't required by a Kalman filter and doesn't match the documentation.
Kalman filters can be a confusing topic, and the inconsistent documentation doesn't help.
I suggest either making the process noise zero to match the documentation or replacing the "Rotation speed is constant. " with something like:
Rotation speed is a random walk from N(0,0.1 ), integrating N(0,1e-5) process noise.
If you run the program it is clear that the rotation is not constant.
Another couple issues:
- Why plot the crosses underneath the lines? The thick lines overwrite the points and cover them up.
- Why not use/plot the kalman.statePost? The utility of a Kalman filter is to improve the estimate of the current state based on the recent measurement and to improve the estimate of the next state. This demo doesn't use the corrected measurement.