/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/src/dict_hw_test.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2010-04-22 13:42:41 UTC
  • Revision ID: csa@dside.dyndns.org-20100422134241-fv5m2ufk8n2tc9h5
Implementation of image and fragment modes, support for non-cacheable grids

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
int matlab_mode = 0;
25
25
 
26
26
typedef enum {
 
27
    OPT_DEFAULT_FFT = 250,
27
28
    OPT_MATLAB = 'm',
28
29
    OPT_HELP = 'h'
29
30
} Options;
30
31
 
31
32
static struct option long_options[] = {
32
33
    {"matlab",                  no_argument, 0, OPT_MATLAB },
 
34
    {"default-fft",             no_argument, 0, OPT_DEFAULT_FFT },
33
35
    {"help",                    no_argument, 0, OPT_HELP },
34
36
    { 0, 0, 0, 0 }
35
37
};
39
41
" %s [options] [mode] <directory> [maximages]\n"
40
42
"  Modes:\n"
41
43
"       --matlab        - Matlab mode (transposed data ordering)\n"
 
44
"       --default-fft   - Do not optimize FFT size\n"
42
45
"       --help          - Help message\n"
43
46
"\n\n", argv[0]);
44
47
}
126
129
int main(int argc, char *argv[]) {
127
130
    int i;
128
131
    int err;
 
132
    int flags;
129
133
    
130
134
    int maximg, allocimg;
131
135
    
144
148
    gettimeofday(&tv1, NULL);
145
149
#endif /* DICT_HW_MEASURE_TIMINGS */
146
150
 
 
151
    int default_fft = 0;
147
152
    
148
153
    int option_index = 0;
149
154
    unsigned char c;
154
159
            case OPT_MATLAB:
155
160
                matlab_mode = 1;
156
161
            break;
 
162
            case OPT_DEFAULT_FFT:
 
163
                default_fft = 1;
 
164
            break;
157
165
            case OPT_HELP:
158
166
                Usage(argc, argv);
159
167
                exit(0);                
182
190
        printf("Amount of X and Y coordinates of control points does not match\n");
183
191
        exit(-1);
184
192
    }
 
193
    
 
194
    //xsize = ysize = 1024;
185
195
 
186
196
    if (optind < (argc - 1)) maximg = atoi(argv[optind+1]);
187
197
    else maximg = 0;
199
209
    
200
210
    g_free(name);
201
211
 
 
212
    GRegex *regex = g_regex_new("(tiff?|bmp|jpe?g|png)", G_REGEX_CASELESS, (GRegexMatchFlags)0, NULL);
 
213
    if (!regex) {
 
214
        printf("Internal error. Failed to compiler regular expression\n");
 
215
        exit(-1);
 
216
    }
 
217
    
 
218
    
202
219
    const gchar *file = g_dir_read_name(dir);
203
220
    for (i = 0;file;file = g_dir_read_name(dir)) {
 
221
        if (!g_regex_match(regex, file, (GRegexMatchFlags)0, NULL)) continue;
 
222
        
204
223
        if (i == size) {
205
224
            size *= 2;
206
225
            images = (char**)realloc(images, size);
212
231
        }*/
213
232
    }    
214
233
    g_dir_close(dir);
 
234
    g_regex_unref(regex);
215
235
 
216
236
    allocimg = i;
217
237
    if ((!maximg)||(maximg > i)) maximg = i;
226
246
    int ncp = xsize;
227
247
    
228
248
    DICTContext ps = dictCreateContext();
229
 
    if (matlab_mode) {
230
 
        err = dictSetup(ps, ncp, 15, 1000, DICT_FLAGS_MATLAB_MODE);
231
 
    } else {
232
 
        err = dictSetup(ps, ncp, 15, 1000, DICT_FLAGS_DEFAULT);
233
 
    }
 
249
 
 
250
    flags = DICT_FLAGS_DEFAULT;
 
251
    if (matlab_mode) flags |= DICT_FLAGS_MATLAB_MODE;
 
252
    if (default_fft) flags |= DICT_FLAGS_FIXED_FFT_SIZE;
 
253
 
 
254
    err = dictSetup(ps, ncp, 15, 1000, flags);
 
255
    
 
256
    
234
257
    if (err) {
235
258
        printf("Setup is failed, error code %i\n", err);
236
259
        exit(-1);
251
274
    dictSetTemplatePoints(ps, x, y);
252
275
 
253
276
    name = g_strdup_printf("%s/images/%s", argv[optind], images[0]);
254
 
    dictLoadTemplateImageFile(ps, name);
 
277
    if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
 
278
        g_free(name);
 
279
        printf("%s is not a regular file\n", images[0]);
 
280
        exit(-1);
 
281
    }
 
282
    err = dictLoadTemplateImageFile(ps, name);
255
283
    g_free(name);
 
284
    if (err) {
 
285
        printf("failed to load template file %s\n", images[0]);
 
286
        exit(-1);
 
287
    }
 
288
    
256
289
 
257
290
    dictSetCurrentPoints(ps, x, y);
258
291
 
293
326
#endif /* !DICT_HW_MEASURE_TIMINGS */
294
327
        
295
328
        name = g_strdup_printf("%s/images/%s", argv[optind], images[i]);
 
329
        if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
 
330
            g_free(name);
 
331
            printf("%s is not a regular file\n", images[0]);
 
332
            exit(-1);
 
333
        }
 
334
 
296
335
#ifdef DICT_HW_MEASURE_TIMINGS
297
336
        gettimeofday(&tv3, NULL);
298
337
#endif /* DICT_HW_MEASURE_TIMINGS */
299
 
        dictLoadImageFile(ps, name);
 
338
        err = dictLoadImageFile(ps, name);
300
339
#ifdef DICT_HW_MEASURE_TIMINGS
301
340
        gettimeofday(&tv2, NULL);
302
341
        time[5] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
303
342
#endif /* DICT_HW_MEASURE_TIMINGS */
304
 
 
305
343
        g_free(name);
 
344
 
 
345
        if (err) {
 
346
            printf("failed to load template file %s\n", images[0]);
 
347
            exit(-1);
 
348
        }
 
349
 
306
350
        if (matlab_mode) {
307
351
            float *out = res + ncp * (i - 1);
308
352
            dictGetCurrentPoints(ps, out, out + step);