-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLucasKanadeTracker.h
72 lines (54 loc) · 1.8 KB
/
LucasKanadeTracker.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by Patrick Werner (boonto) on 25.11.17.
//
#ifndef TRACKING_LUCASKANADETRACKER_H
#define TRACKING_LUCASKANADETRACKER_H
#include <opencv2/tracking.hpp>
#include "Tracker.h"
class LucasKanadeTracker : public Tracker {
public:
struct Parameters {
int nFeatures = 30;
double qualityLevel = 0.15;
double minDistance = 5;
bool bUseGauss = false;
float gaussSigma = 2.0f;
int nMaxIterations = 40;
int windowSize = 21;
float iterationEps = 0.05f;
};
explicit LucasKanadeTracker(const Parameters ¶meters) :
parameters(parameters),
initialized(false),
features(),
prevImage(),
nInitialPoints(0) {
}
void track(const cv::Mat &image, cv::Rect2f &roi) override;
void reset() override {
initialized = false;
}
void display(cv::Mat &display) const {
// Show feature points
for (const auto &corner : features) {
cv::circle(display, corner, 3, cv::Scalar(0, 255, 0), -1);
}
}
float evaluate(const cv::Rect2f &roi, const cv::Rect2f &groundTruthRoi) const override;
std::string classname() const override {
return "LucasKanadeTracker";
}
private:
Parameters parameters;
bool initialized;
std::vector<cv::Point2f> features;
cv::Mat prevImage;
int nInitialPoints;
void initialize(const cv::Mat &image, const cv::Rect2f &roi);
cv::Rect2f updateRoi() const;
cv::Mat prepareImage(const cv::Mat &inputImage) const;
std::tuple<cv::Mat, cv::Mat> computeDerivatives(const cv::Mat &image) const;
cv::Rect2f buildWindow(const cv::Point2f &feature, int w) const;
void filter(cv::Mat &A1, cv::Mat &A2, cv::Mat &b, int i) const;
};
#endif //TRACKING_LUCASKANADETRACKER_H