-
Notifications
You must be signed in to change notification settings - Fork 4
/
LaRank.h
117 lines (95 loc) · 2.78 KB
/
LaRank.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Struck: Structured Output Tracking with Kernels
*
* Code to accompany the paper:
* Struck: Structured Output Tracking with Kernels
* Sam Hare, Amir Saffari, Philip H. S. Torr
* International Conference on Computer Vision (ICCV), 2011
*
* Copyright (C) 2011 Sam Hare, Oxford Brookes University, Oxford, UK
*
* This file is part of Struck.
*
* Struck is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Struck is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Struck. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef LARANK_H
#define LARANK_H
#include "Rect.h"
#include "Sample.h"
#include <vector>
#include <Eigen/Core>
#include <opencv/cv.h>
class Config;
class Features;
class Kernel;
class LaRank
{
public:
LaRank(const Config& conf, const Features& features, const Kernel& kernel);
~LaRank();
virtual void Eval(const MultiSample& x, std::vector<double>& results);
virtual void Update(const MultiSample& x, int y);
virtual void Debug();
private:
struct SupportPattern
{
std::vector<Eigen::VectorXd> x;
std::vector<FloatRect> yv;
std::vector<cv::Mat> images;
int y;
int refCount;
};
struct SupportVector
{
SupportPattern* x;
int y;
double b;
double g;
cv::Mat image;
};
const Config& m_config;
const Features& m_features;
const Kernel& m_kernel;
std::vector<SupportPattern*> m_sps;
std::vector<SupportVector*> m_svs;
cv::Mat m_debugImage;
double m_C;
Eigen::MatrixXd m_K;
inline double Loss(const FloatRect& y1, const FloatRect& y2) const
{
// overlap loss
return 1.0-y1.Overlap(y2);
// squared distance loss
//double dx = y1.XMin()-y2.XMin();
//double dy = y1.YMin()-y2.YMin();
//return dx*dx+dy*dy;
}
double ComputeDual() const;
void SMOStep(int ipos, int ineg);
std::pair<int, double> MinGradient(int ind);
void ProcessNew(int ind);
void Reprocess();
void ProcessOld();
void Optimize();
int AddSupportVector(SupportPattern* x, int y, double g);
void RemoveSupportVector(int ind);
void RemoveSupportVectors(int ind1, int ind2);
void SwapSupportVectors(int ind1, int ind2);
void BudgetMaintenance();
void BudgetMaintenanceRemove();
double Evaluate(const Eigen::VectorXd& x, const FloatRect& y) const;
void UpdateDebugImage();
};
#endif