28
36
OPT_SINGLE_MODE = 251,
29
37
OPT_NO_PRELOAD = 252,
30
38
OPT_MULTIPASS = 253,
35
45
static struct option long_options[] = {
36
{"matlab", no_argument, 0, OPT_MATLAB },
37
{"default-fft", no_argument, 0, OPT_DEFAULT_FFT },
38
{"no-threads", no_argument, 0, OPT_SINGLE_MODE },
39
{"no-preload", no_argument, 0, OPT_NO_PRELOAD },
40
{"multipass", no_argument, 0, OPT_MULTIPASS },
41
{"help", no_argument, 0, OPT_HELP },
46
{"matlab", no_argument, 0, OPT_MATLAB },
47
{"corrsize", required_argument, 0, OPT_CORRSIZE },
48
{"precision", required_argument, 0, OPT_PRECISION },
49
{"default-fft", no_argument, 0, OPT_DEFAULT_FFT },
50
{"no-threads", no_argument, 0, OPT_SINGLE_MODE },
51
{"no-preload", no_argument, 0, OPT_NO_PRELOAD },
52
{"multipass", no_argument, 0, OPT_MULTIPASS },
53
{"help", no_argument, 0, OPT_HELP },
280
320
if (default_fft) flags |= DICT_FLAGS_FIXED_FFT_SIZE;
281
321
if (single_mode) flags |= DICT_FLAGS_SINGLE_THREAD;
283
err = dictSetup(ps, ncp, 15, 1000, flags);
327
ncp_block = dictGetMaxCacheablePoints(corrsize, precision, flags);
328
if (ncp_block >= ncp) multipass = 0;
331
err = dictSetup(ps, multipass?ncp_block:ncp, corrsize, precision, flags);
333
dictDestroyContext(ps);
287
335
printf("Setup is failed, error code %i\n", err);
342
FILE *fx = NULL, *fy = NULL;
344
if ((matlab_mode)||(multipass)) {
295
345
res = (float*) malloc(2 * ncp * (maximg - 1) * sizeof(float));
296
346
step = ncp * (maximg - 1);
349
dictDestroyContext(ps);
351
printf("Can't allocate result memory\n");
298
355
res = (float*) malloc(2 * ncp * sizeof(float));
300
357
dictSetPointsBuffer(ps, res, res + ncp);
303
dictSetTemplatePoints(ps, x, y);
305
name = g_strdup_printf("%s/images/%s", argv[optind], images[0]);
306
if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
308
printf("%s is not a regular file\n", images[0]);
311
err = dictLoadTemplateImageFile(ps, name);
314
printf("failed to load template file %s\n", images[0]);
319
dictSetCurrentPoints(ps, x, y);
321
#ifdef DICT_HW_MEASURE_TIMINGS
322
gettimeofday(&tv2, NULL);
323
time[0] = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
324
#endif /* DICT_HW_MEASURE_TIMINGS */
327
#ifdef DICT_HW_MEASURE_TIMINGS
328
gettimeofday(&tv3, NULL);
329
#endif /* DICT_HW_MEASURE_TIMINGS */
333
359
name = g_strdup_printf("%s/data/validx.dat", argv[optind]);
334
360
fx = fopen(name, "w");
337
363
fy = fopen(name, "w");
366
if ((!res)||(!fx)||(!fy)) {
370
dictDestroyContext(ps);
341
372
printf("Can't create output files...\n");
346
377
#ifdef DICT_HW_MEASURE_TIMINGS
347
gettimeofday(&tv2, NULL);
348
time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
349
#endif /* DICT_HW_MEASURE_TIMINGS */
354
name = g_strdup_printf("%s/images/%s", argv[optind], images[1]);
355
if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
357
printf("%s is not a regular file\n", images[1]);
361
for (i = 1; i < maximg; i++, name = next) {
362
#ifndef DICT_HW_MEASURE_TIMINGS
363
printf("%s\n", images[i]);
364
#endif /* !DICT_HW_MEASURE_TIMINGS */
367
if ((i + 1) < maximg) {
368
next = g_strdup_printf("%s/images/%s", argv[optind], images[i + 1]);
369
if (!g_file_test(next, G_FILE_TEST_IS_REGULAR)) {
372
printf("%s is not a regular file\n", images[i + 1]);
377
dictPreloadImageFile(ps, next);
381
#ifdef DICT_HW_MEASURE_TIMINGS
382
gettimeofday(&tv3, NULL);
383
#endif /* DICT_HW_MEASURE_TIMINGS */
384
err = dictLoadImageFile(ps, name);
385
#ifdef DICT_HW_MEASURE_TIMINGS
386
378
gettimeofday(&tv2, NULL);
387
time[5] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
379
time[0] = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
388
380
#endif /* DICT_HW_MEASURE_TIMINGS */
385
for (icp = 0, ncp = multipass?ncp_block:ncp; icp < real_ncp; icp += ncp, ncp = min2(ncp_block, real_ncp - icp)) {
386
#ifdef DICT_HW_VERBOSE_OUTPUT
387
printf("%i + %i (of %i)\n", icp, ncp, real_ncp);
388
#endif /* DICT_HW_VERBOSE_OUTPUT */
390
dictSetActualNumberOfPoints(ps, ncp);
392
//dictSetup(ps, ncp, corrsize, precision, flags);
396
dictSetTemplatePoints(ps, x + icp, y + icp);
398
name = g_strdup_printf("%s/images/%s", argv[optind], images[0]);
399
if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
401
printf("%s is not a regular file\n", images[0]);
406
err = dictLoadTemplateImageFile(ps, name);
393
printf("failed to load image %s\n", images[0]);
409
printf("failed to load template file %s\n", images[0]);
414
dictSetCurrentPoints(ps, x + icp, y + icp);
419
name = g_strdup_printf("%s/images/%s", argv[optind], images[1]);
420
if (!g_file_test(name, G_FILE_TEST_IS_REGULAR)) {
422
printf("%s is not a regular file\n", images[1]);
427
for (i = 1; i < maximg; i++, name = next) {
428
#ifdef DICT_HW_VERBOSE_OUTPUT
429
# ifndef DICT_HW_MEASURE_TIMINGS
430
printf("%s\n", images[i]);
431
# endif /* !DICT_HW_MEASURE_TIMINGS */
432
#endif /* DICT_HW_VERBOSE_OUTPUT */
434
if ((i + 1) < maximg) {
435
next = g_strdup_printf("%s/images/%s", argv[optind], images[i + 1]);
436
if (!g_file_test(next, G_FILE_TEST_IS_REGULAR)) {
439
printf("%s is not a regular file\n", images[i + 1]);
445
dictPreloadImageFile(ps, next);
399
float *out = res + ncp * (i - 1);
400
dictGetCurrentPoints(ps, out, out + step);
404
449
#ifdef DICT_HW_MEASURE_TIMINGS
405
450
gettimeofday(&tv3, NULL);
406
451
#endif /* DICT_HW_MEASURE_TIMINGS */
408
for (int j = 0; j < ncp; j++) {
409
fprintf(fx, "% 9.7le\t", res[j]);
413
float *out = res + step;
414
for (int j = 0; j < ncp; j++) {
415
fprintf(fy, "% 9.7le\t", out[j]);
452
err = dictLoadImageFile(ps, name);
419
453
#ifdef DICT_HW_MEASURE_TIMINGS
420
454
gettimeofday(&tv2, NULL);
421
time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
422
#endif /* DICT_HW_MEASURE_TIMINGS */
455
time[5] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
456
#endif /* DICT_HW_MEASURE_TIMINGS */
461
printf("failed to load image %s\n", images[0]);
467
if ((matlab_mode)||(multipass)) {
468
float *out = res + real_ncp * (i - 1) + icp;
469
dictGetCurrentPoints(ps, out, out + step);
473
#ifdef DICT_HW_MEASURE_TIMINGS
474
gettimeofday(&tv3, NULL);
475
#endif /* DICT_HW_MEASURE_TIMINGS */
477
for (int j = 0; j < ncp; j++) {
478
fprintf(fx, "% 9.7le\t", res[j]);
482
float *out = res + step;
483
for (int j = 0; j < ncp; j++) {
484
fprintf(fy, "% 9.7le\t", out[j]);
488
#ifdef DICT_HW_MEASURE_TIMINGS
489
gettimeofday(&tv2, NULL);
490
time[1] += (tv2.tv_sec - tv3.tv_sec) * 1000000 + (tv2.tv_usec - tv3.tv_usec);
491
#endif /* DICT_HW_MEASURE_TIMINGS */
426
496
#ifdef DICT_HW_MEASURE_TIMINGS
427
497
gettimeofday(&tv3, NULL);
428
498
#endif /* DICT_HW_MEASURE_TIMINGS */
500
if ((matlab_mode)||(multipass)) {
431
501
name = g_strdup_printf("%s/data/validx.dat", argv[optind]);
432
writefile(name, res, maximg - 1, ncp);
502
writefile(matlab_mode, name, res, maximg - 1, real_ncp);
434
504
name = g_strdup_printf("%s/data/validy.dat", argv[optind]);
435
writefile(name, res+step, maximg - 1, ncp);
505
writefile(matlab_mode, name, res+step, maximg - 1, real_ncp);