-
Notifications
You must be signed in to change notification settings - Fork 1
/
HoG.hpp
executable file
·63 lines (48 loc) · 1.25 KB
/
HoG.hpp
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
#pragma once
#include <cv.h>
#include <opencv2/core/core.hpp>
#include <vector>
using namespace std;
using namespace cv;
class HoG {
public:
HoG();
~HoG() {
cvReleaseMat(&Gauss);
delete ptGauss;
}
void extractOBin(Mat &Iorient, Mat &Imagn, std::vector<Mat> &out);
private:
void calcHoGBin(uchar *ptOrient, uchar *ptMagn, int step, double *desc);
void binning(float v, float w, double *desc, int maxb);
int bins;
float binsize;
int g_w;
CvMat *Gauss;
// Gauss as vector
float *ptGauss;
};
inline void HoG::calcHoGBin(uchar *ptOrient, uchar *ptMagn, int step, double *desc) {
for (int i = 0; i < bins; i++)
desc[i] = 0;
uchar *ptO = &ptOrient[0];
uchar *ptM = &ptMagn[0];
int i = 0;
for (int y = 0; y < g_w; ++y, ptO += step, ptM += step) {
for (int x = 0; x < g_w; ++x, ++i) {
binning((float)ptO[x] / binsize, (float)ptM[x] * ptGauss[i], desc, bins);
}
}
}
inline void HoG::binning(float v, float w, double *desc, int maxb) {
int bin1 = int(v);
int bin2;
float delta = v - bin1 - 0.5f;
if (delta < 0) {
bin2 = bin1 < 1 ? maxb - 1 : bin1 - 1;
delta = -delta;
} else
bin2 = bin1 < maxb - 1 ? bin1 + 1 : 0;
desc[bin1] += (1 - delta) * w;
desc[bin2] += delta * w;
}