From 2be805ce29b690d80e6ef3beb207a71fe9f8c837 Mon Sep 17 00:00:00 2001 From: Anatoly Orlov Date: Tue, 29 Mar 2016 18:27:35 +0300 Subject: [PATCH] kalman.py was broken totally 1. Following condition is True on each iteration becuase -1 % 0xFF is 255 not -1 code = cv2.waitKey(100) % 0x100 if code != -1: break this were resetting point position on each cycle not on key press as intended 2. Previous small bug were masking serious bug with matrix operation on matrices of incorrect size. As the result on 2nd iteration of internal cycle program has crushed. I have fixed it too, matrix operation was taken from examples/cpp/kalman.cpp where it looks like randn( processNoise, Scalar(0), Scalar::all(sqrt(KF.processNoiseCov.at(0, 0)))); which is something totally different from previous code here. Example behave as it should now, i.e. point moving by circle trajectory as in C++ example. --- samples/python/kalman.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/python/kalman.py b/samples/python/kalman.py index 8e3748b4de..cc11642648 100755 --- a/samples/python/kalman.py +++ b/samples/python/kalman.py @@ -19,7 +19,7 @@ if PY3: long = int import cv2 -from math import cos, sin +from math import cos, sin, sqrt import numpy as np if __name__ == "__main__": @@ -81,12 +81,12 @@ if __name__ == "__main__": kalman.correct(measurement) - process_noise = kalman.processNoiseCov * np.random.randn(2, 1) + process_noise = sqrt(kalman.processNoiseCov[0,0]) * np.random.randn(2, 1) state = np.dot(kalman.transitionMatrix, state) + process_noise cv2.imshow("Kalman", img) - code = cv2.waitKey(100) % 0x100 + code = cv2.waitKey(100) if code != -1: break