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__)
29 es_ctx *es_init(int nc, int nr) {
31 es_ctx *es = (es_ctx *)malloc(sizeof(es_ctx));
33 es->tc = KLTCreateTrackingContext();
35 es->tc->sequentialMode = TRUE;
36 es->tc->min_eigenvalue = 8;
37 es->tc->verbose = FALSE;
39 KLTChangeTCPyramid(es->tc, 31);
41 KLTUpdateTCBorder(es->tc);
43 es->fr[0] = (KLT_PixelType *)malloc(nc * nr * sizeof(KLT_PixelType));
44 es->fr[1] = (KLT_PixelType *)malloc(nc * nr * sizeof(KLT_PixelType));
46 es->fl = KLTCreateFeatureList(64);
48 es->dv = (vc *)malloc(64 * sizeof(vc));
59 vc es_estimate(es_ctx *es, unsigned char *fr) {
64 t = es->fr[0]; es->fr[0] = es->fr[1]; es->fr[1] = t;
66 for (is = 0, id = 0; id < es->nc * es->nr; is += 3, id ++)
67 es->fr[1][id] = (fr[is + 0] * 30 + fr[is + 1] * 59 + fr[is + 2] * 11) / 100;
69 if (es->ff == FALSE) {
75 vc bv = vc_set(0.0, 0.0);
80 KLTSelectGoodFeatures(
81 es->tc, es->fr[0], es->nc, es->nr, es->fl
84 for (i = 0; i < es->fl->nFeatures; i ++)
85 es->dv[i] = vc_set(es->fl->feature[i]->x, es->fl->feature[i]->y);
88 es->tc, es->fr[0], es->fr[1], es->nc, es->nr, es->fl
93 for (i = 0; i < es->fl->nFeatures; i ++) {
95 if (es->fl->feature[i]->val == KLT_TRACKED) {
97 es->dv[es->nv] = vc_set(
98 es->fl->feature[i]->x - es->dv[i].x,
99 es->fl->feature[i]->y - es->dv[i].y
106 for (i = 0; i < es->nv; i ++) {
110 for (i2 = 0; i2 < es->nv; i2 ++)
111 ce += vc_len(vc_sub(es->dv[i2], es->dv[i]));
126 void es_free(es_ctx *es) {
133 KLTFreeFeatureList(es->fl);
134 KLTFreeTrackingContext(es->tc);