-
Notifications
You must be signed in to change notification settings - Fork 1
/
GEIMDef.cpp
99 lines (92 loc) · 1.97 KB
/
GEIMDef.cpp
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
#include "GEIMDef.h"
#include <cfloat>
/** \brief Calculates the squared Euclidian distance between two feature descriptors.
*
* \param f1 ST_FEATURE* first feature
* \param f2 ST_FEATURE* second feature
* \return double Returns the squared Euclidian distance between the descriptors of
* \a f1 and \a f2.
*
*/
double feat_dist_sq( ST_FEATURE *f1, ST_FEATURE *f2 )
{
static double WEIGHT[FEATURE_MAX_D] = {0.2, 0.2, 0.1, 0.15, 0.05, 0.1, 0.2};
double diff, dsq = 0;
double* descr1, * descr2;
int i, n;
n = f1->n;
if( f2->n != n )
return DBL_MAX;
descr1 = f1->descr;
descr2 = f2->descr;
for( i = 0; i < n; i++ )
{
diff = descr1[i] - descr2[i];
dsq += WEIGHT[i]*diff*diff;
}
return dsq;
}
bool img_draw_line(wxImage &img, const wxRect &rc, const ST_RGB &clr)
{
int iW = 0, iH = 0;
ST_RGB *pImg = nullptr;
double slope = 0.0;
if (!img.IsOk() || (rc.width == 0 && rc.height == 0))
return false;
iW = img.GetWidth();
iH = img.GetHeight();
pImg = (ST_RGB *)img.GetData();
if (abs(rc.width) >= abs(rc.height)) // width priority
{
int x = rc.x;
int y = 0;
slope = rc.height/(double)rc.width;
if (rc.width < 0) // --
{
for (int tx = 0; tx > rc.width; --tx)
{
y = (int)(tx*slope + rc.y);
if (x >= 0 && x < iW && y >= 0 && y < iH)
pImg[y*iW+x] = clr;
--x;
}
}
else // ++
{
for (int tx = 0; tx < rc.width; ++tx)
{
y = (int)(tx*slope + rc.y);
if (x >= 0 && x < iW && y >= 0 && y < iH)
pImg[y*iW+x] = clr;
++x;
}
}
}
else // height priority
{
int x = 0;
int y = rc.y;
slope = rc.width/(double)rc.height;
if (rc.height < 0) // --
{
for (int ty = 0; ty > rc.height; --ty)
{
x = (int)(ty*slope + rc.x);
if (x >= 0 && x < iW && y >= 0 && y < iH)
pImg[y*iW+x] = clr;
--y;
}
}
else // ++
{
for (int ty = 0; ty < rc.height; ++ty)
{
x = (int)(ty*slope + rc.x);
if (x >= 0 && x < iW && y >= 0 && y < iH)
pImg[y*iW+x] = clr;
++y;
}
}
}
return true;
}