-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (23 loc) · 995 Bytes
/
main.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
28
29
30
31
32
33
34
#https://pysource.com/2021/10/29/kalman-filter-predict-the-trajectory-of-an-object/
from kalmanfilter import KalmanFilter
import cv2
# Kalman Filter
kf = KalmanFilter()
img = cv2.imread("blue_background.webp")
ball2_positions = [(4, 300), (61, 256), (116, 214), (170, 180), (225, 148), (279, 120), (332, 97),
(383, 80), (434, 66), (484, 55), (535, 49), (586, 49), (634, 50),
(683, 58), (731, 69), (778, 82), (824, 101), (870, 124), (917, 148),
(962, 169), (1006, 212), (1051, 249), (1093, 290)]
for pt in ball2_positions:
cv2.circle(img, pt, 15, (0, 20, 220), -1)
predicted = kf.predict(pt[0], pt[1])
cv2.circle(img, predicted, 15, (20, 220, 0), 4)
for i in range(10):
predicted = kf.predict(predicted[0], predicted[1])
cv2.circle(img, predicted, 15, (20, 220, 0), 4)
print(predicted)
cv2.imshow("Img", img)
while True:
if cv2.waitKey(0) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()