-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeanshiftTracker.h
57 lines (42 loc) · 1.5 KB
/
MeanshiftTracker.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
//
// Created by Patrick Werner (boonto) on 25.11.17.
//
#ifndef TRACKING_MEANSHIFTTRACKER_H
#define TRACKING_MEANSHIFTTRACKER_H
#include <opencv2/tracking.hpp>
#include "Tracker.h"
class MeanshiftTracker : public Tracker {
public:
struct Parameters {
int nMaxIterations = 200;
int nBins = 32;
};
explicit MeanshiftTracker(const Parameters ¶meters) :
parameters(parameters),
initialized(false),
targetHist() {
}
void track(const cv::Mat &image, cv::Rect2f &roi) override;
void reset() override {
initialized = false;
}
float evaluate(const cv::Rect2f &roi, const cv::Rect2f &groundTruthRoi) const override;
std::string classname() const override {
return "MeanshiftTracker";
}
private:
Parameters parameters;
bool initialized;
cv::Mat targetHist;
void initialize(const cv::Mat &image, cv::Rect2f &roi);
cv::Mat getHistogram(const cv::Mat &image, int nBins) const;
cv::Mat getBackProject(const cv::Mat &image, const cv::Mat &hist) const;
void roiToBounds(cv::Rect2f &roi, const cv::Size size) const {
// Ensure roi is in image bounds
roi.width = std::min(static_cast<float>(size.width), roi.width);
roi.height = std::min(static_cast<float>(size.height), roi.height);
roi.x = std::min(std::max(0.0f, roi.x), size.width - roi.width);
roi.y = std::min(std::max(0.0f, roi.y), size.height - roi.height);
}
};
#endif //TRACKING_MEANSHIFTTRACKER_H