-
Notifications
You must be signed in to change notification settings - Fork 6
/
gt.c
140 lines (131 loc) · 3.95 KB
/
gt.c
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdio.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/highgui/highgui_c.h>
#include "prop.h"
#define XY_TO_X(x) ((x)&((1<<16)-1))
#define XY_TO_Y(y) ((y)>>16)
static void xy2img(IplImage *xy, IplImage *img, IplImage *recon)
{
int w = xy->width, h = xy->height, i, j;
int xystride = xy->widthStep/sizeof(int32_t);
int rstride = recon->widthStep;
int stride = img->widthStep;
int32_t *xydata = (int32_t*)xy->imageData;
uint8_t *rdata = (uint8_t*)recon->imageData;
uint8_t *data = (uint8_t*)img->imageData;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
int v = xydata[i*xystride + j];
int x = XY_TO_X(v), y = XY_TO_Y(v);
int rd = i*rstride + j*3, dd = y*stride + x*3;
*(rdata + rd + 0) = *(data + dd + 0);
*(rdata + rd + 1) = *(data + dd + 1);
*(rdata + rd + 2) = *(data + dd + 2);
}
}
}
#undef XY_TO_X
#undef XY_TO_Y
static IplImage *alignedImage(CvSize dim, int depth, int chan, int align)
{
int w = dim.width, h = dim.height;
int dx = align - (w % align);
w += (dx != align) * dx;
CvSize s = {w, h};
return cvCreateImage(s, depth, chan);
}
static IplImage *alignedImageFrom(char *file, int align)
{
IplImage *pre = cvLoadImage(file, CV_LOAD_IMAGE_COLOR);
IplImage *img = alignedImage(cvGetSize(pre), pre->depth, pre->nChannels, align);
char *pre_data = pre->imageData;
char *img_data = img->imageData;
int i;
for (i = 0; i < pre->height; i++) {
memcpy(img_data, pre_data, pre->widthStep);
img_data += img->widthStep;
pre_data += pre->widthStep;
}
cvReleaseImage(&pre);
return img;
}
static int64_t sumimg(IplImage *img, int kern)
{
int64_t sum = 0;
int i, j;
uint8_t *data;
for (i = 0; i < img->height; i++) {
data = (uint8_t*)img->imageData + i*img->widthStep;
for (j = 0; j < img->width - kern + 1; j++) {
sum += *data++;
sum += *data++;
sum += *data++;
}
}
return sum;
}
#include <sys/time.h>
static inline double get_time()
{
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec + t.tv_usec * 1e-6;
}
int main(int argc, char **argv)
{
double start, end;
#define SAMEAS(q) cvCreateImage(cvGetSize((q)), (q)->depth, (q)->nChannels)
char *s, *d, *g;
if (argc < 4) {
s = "lena.png";
d = "eva.jpg";
g = "eva-gt.png";
} else {
s = argv[1];
d = argv[2];
g = argv[3];
}
printf("gt: \"%s\" \"%s\" \"%s\"\n", s, d, g);
IplImage *src = alignedImageFrom(s, 8);
IplImage *dst = alignedImageFrom(d, 8);
IplImage *gt = alignedImageFrom(g, 8);
IplImage *diff = SAMEAS(dst);
IplImage *gtdiff = SAMEAS(dst);
IplImage *diff2 = SAMEAS(dst);
IplImage *diff3 = SAMEAS(dst);
IplImage *match = SAMEAS(dst);
start = get_time();
IplImage *xy = prop_match(src, dst);
xy2img(xy, src, match);
end = get_time();
cvAbsDiff(match, gt, diff);
cvAbsDiff(gt, dst, gtdiff);
cvAbsDiff(match, dst, diff2);
cvAbsDiff(gtdiff, diff2, diff3);
/*cvNamedWindow("match-gt", CV_WINDOW_NORMAL);
cvNamedWindow("gt", CV_WINDOW_NORMAL);
cvNamedWindow("match", CV_WINDOW_NORMAL);
cvResizeWindow("match-gt", 960, 400);
cvResizeWindow("gt", 960, 400);
cvResizeWindow("match", 960, 400);*/
//cvShowImage("gt", gt);
//cvShowImage("match-dst", diff2);
//cvShowImage("match-gt", diff);
//cvShowImage("gt-dst" , gtdiff);
//cvShowImage("match", match);
//cvShowImage("gtdiff - matchdiff", diff3);
printf("elapsed %f\n", (end-start)*1000);
printf("match-gt %lld\n", sumimg(diff, 8));
//cvWaitKey(0);
cvReleaseImage(&src);
cvReleaseImage(&dst);
cvReleaseImage(&diff);
cvReleaseImage(&diff2);
cvReleaseImage(>diff);
cvReleaseImage(&match);
cvReleaseImage(>);
cvReleaseImage(&xy);
return 0;
return 0;
return 0;
}