OpenShot Library | libopenshot 1.1.1
KalmanTracker.h
Go to the documentation of this file.
1// © OpenShot Studios, LLC
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
6// KalmanTracker.h: KalmanTracker Class Declaration
7
8#ifndef KALMAN_H
9#define KALMAN_H 2
10
11#include "opencv2/video/tracking.hpp"
12#include "opencv2/highgui/highgui.hpp"
13
14#include <map>
15#include <vector>
16
17
18#define StateType cv::Rect_<float>
19
21{
22 int classId = 0;
23 float score = 0.0f;
25 ClassScore(int _classId, float _score) : classId(_classId), score(_score) {}
26};
27
30{
31public:
33 {
34 init_kf(StateType());
36 m_hits = 0;
37 m_hit_streak = 0;
38 m_age = 0;
39 m_id = 0;
40 }
41 KalmanTracker(StateType initRect, float confidence, int classId, int objectId, const std::vector<ClassScore>& classScores = {}) : confidence(confidence), classId(classId)
42 {
43 init_kf(initRect);
45 m_hits = 0;
46 m_hit_streak = 0;
47 m_age = 0;
48 m_id = objectId;
50 }
51
53 {
54 m_history.clear();
55 }
56
59 void update(StateType stateMat);
60 void update_class_scores(const std::vector<ClassScore>& classScores, int fallbackClassId, float fallbackConfidence);
61
63 StateType get_rect_xysr(float cx, float cy, float s, float r);
64
66 int m_hits;
68 int m_age;
69 int m_id;
72 std::map<int, double> classScoreHistory;
73
74private:
75 void init_kf(StateType stateMat);
76
77 cv::KalmanFilter kf;
78 cv::Mat measurement;
79
80 std::vector<StateType> m_history;
81};
82
83#endif
#define StateType
Definition: KalmanTracker.h:18
This class represents the internel state of individual tracked objects observed as bounding box.
Definition: KalmanTracker.h:30
void update_class_scores(const std::vector< ClassScore > &classScores, int fallbackClassId, float fallbackConfidence)
StateType predict()
KalmanTracker(StateType initRect, float confidence, int classId, int objectId, const std::vector< ClassScore > &classScores={})
Definition: KalmanTracker.h:41
std::map< int, double > classScoreHistory
Definition: KalmanTracker.h:72
StateType get_state()
void update(StateType stateMat)
int m_time_since_update
Definition: KalmanTracker.h:65
StateType predict2()
StateType get_rect_xysr(float cx, float cy, float s, float r)
ClassScore(int _classId, float _score)
Definition: KalmanTracker.h:25