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
|
IplImage* inverse_warp_rotate(IplImage* before, CvBox2D box) {
float pi = 3.141592653;
float angle = box.angle * pi/180;
IplImage* after = cvCreateImage(cvSize(box.size.height,box.size.width),before->depth, before->nChannels);
double aftercenterx = ((double)after->width)/2;
double aftercentery = ((double)after->height)/2;
for(int a = 0; a < after->width;a++)
{
for(int b = 0; b < after->height;b++)
{
// coordinates in downsampled image corresponding to window center in original image
double dscoordx = box.center.x; //FIXME: don't know what this should be
double dscoordy = box.center.y;
double translatedx = a - aftercenterx;
double translatedy = b - aftercentery;
double rotatedx = translatedx * cos(angle) + translatedy * (sin(angle));
double rotatedy = translatedx * (-sin(angle)) + translatedy * cos(angle);
double transbackx = rotatedx + dscoordx;
double transbacky = rotatedy + dscoordy; // P, Q, R, S coordinates where P, Q, R, S are the nearest neighboring pixels
//std::vectorNx;
//std::vectorNy;
QVector Nx(4);
QVector Ny(4);
}
int Px = floor(transbackx);
Nx.push_back(Px);
int Py = floor(transbacky);
Ny.push_back(Py);
int Qx = floor(transbackx)+1;
Nx.push_back(Qx);
int Qy = floor(transbacky);
Ny.push_back(Qy);
int Rx = floor(transbackx);
Nx.push_back(Rx);
int Ry = floor(transbacky)+1;
Ny.push_back(Ry);
int Sx = floor(transbackx)+1;
Nx.push_back(Sx);
int Sy = floor(transbacky)+1;
Ny.push_back(Sy);
// qDebug("the size of Nx.size()=%d",Nx.size());
// qDebug("the size of Ny.size()=%d",Ny.size());
for(unsigned(o) = 0; o < 4; o++)
{
if(Nx[o] < 0)
{
Nx[o] = 0;
}
else if(Nx[o] >= before->width)
{
Nx[o] = before->width-1;
}
if(Ny[o] < 0)
{
Ny[o] = 0;
}
else if(Ny[o] >= before->height)
{
Ny[o] = before->height-1;
}
}
double alpha = transbackx - Nx[0];
double beta = transbacky - Ny[0];
CvScalar P = cvGet2D(before, Ny[0], Nx[0]);
CvScalar Q = cvGet2D(before, Ny[1], Nx[1]);
CvScalar R = cvGet2D(before, Ny[2], Nx[2]);
CvScalar S = cvGet2D(before, Ny[3], Nx[3]);
CvScalar MOPSpixel = cvGet2D(before, Ny[3], Nx[3]);
MOPSpixel.val[0] = (1-alpha)*(1-beta)*P.val[0] + alpha*(1-beta)*Q.val[0] + (1-alpha)*beta*R.val[0] + alpha*beta*S.val[0];
cvSet2D(after, b, a, MOPSpixel);
}
}
// apply threshold: those pixels that have intensities > 0 will have them set to 1.
for(int a = 0; a < after->height; a++)
{
for(int b = 0; b < after->width; b++)
{
CvScalar Afterpixel = cvGet2D(after, a, b);
Afterpixel.val[0] = (Afterpixel.val[0] > 0 ? 255 : 0);
cvSet2D(after, a, b, Afterpixel);
}
}
return after;
|