4 * Copyright (c) 2008 Lenny <leonardo.masoni@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
21 #if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(WIN32)
29 #if !defined(MAXFLOAT)
30 #define MAXFLOAT HUGE_VAL
33 es_ctx *es_init(int nc, int nr) {
35 es_ctx *es = (es_ctx *)malloc(sizeof(es_ctx));
37 es->tc = KLTCreateTrackingContext();
39 es->tc->sequentialMode = TRUE;
40 es->tc->min_eigenvalue = 8;
41 es->tc->verbose = FALSE;
43 KLTChangeTCPyramid(es->tc, 31);
45 KLTUpdateTCBorder(es->tc);
47 es->fr[0] = (KLT_PixelType *)malloc(nc * nr * sizeof(KLT_PixelType));
48 es->fr[1] = (KLT_PixelType *)malloc(nc * nr * sizeof(KLT_PixelType));
50 es->fl = KLTCreateFeatureList(64);
52 es->dv = (vc *)malloc(64 * sizeof(vc));
63 vc es_estimate(es_ctx *es, unsigned char *fr) {
68 t = es->fr[0]; es->fr[0] = es->fr[1]; es->fr[1] = t;
70 for (is = 0, id = 0; id < es->nc * es->nr; is += 3, id ++)
71 es->fr[1][id] = (fr[is + 0] * 30 + fr[is + 1] * 59 + fr[is + 2] * 11) / 100;
73 if (es->ff == FALSE) {
79 vc bv = vc_set(0.0, 0.0);
84 KLTSelectGoodFeatures(
85 es->tc, es->fr[0], es->nc, es->nr, es->fl
88 for (i = 0; i < es->fl->nFeatures; i ++)
89 es->dv[i] = vc_set(es->fl->feature[i]->x, es->fl->feature[i]->y);
92 es->tc, es->fr[0], es->fr[1], es->nc, es->nr, es->fl
97 for (i = 0; i < es->fl->nFeatures; i ++) {
99 if (es->fl->feature[i]->val == KLT_TRACKED) {
101 es->dv[es->nv] = vc_set(
102 es->fl->feature[i]->x - es->dv[i].x,
103 es->fl->feature[i]->y - es->dv[i].y
110 for (i = 0; i < es->nv; i ++) {
114 for (i2 = 0; i2 < es->nv; i2 ++)
115 ce += vc_len(vc_sub(es->dv[i2], es->dv[i]));
130 void es_free(es_ctx *es) {
137 KLTFreeFeatureList(es->fl);
138 KLTFreeTrackingContext(es->tc);