1 /*********************************************************************
2  * klt.h
3  *
4  * Kanade-Lucas-Tomasi tracker
5  *********************************************************************/
6 
7 #ifndef _KLT_H_
8 #define _KLT_H_
9 
10 typedef float KLT_locType;
11 typedef unsigned char KLT_PixelType;
12 
13 #define KLT_BOOL int
14 
15 #ifndef TRUE
16 #define TRUE  1
17 #define FALSE 0
18 #endif
19 
20 #ifndef NULL
21 #define NULL  0
22 #endif
23 
24 #define KLT_TRACKED           0
25 #define KLT_NOT_FOUND        -1
26 #define KLT_SMALL_DET        -2
27 #define KLT_MAX_ITERATIONS   -3
28 #define KLT_OOB              -4
29 #define KLT_LARGE_RESIDUE    -5
30 
31 #include "klt_util.h" /* for affine mapping */
32 
33 /*******************
34  * Structures
35  */
36 
37 typedef struct  {
38   /* Available to user */
39   int mindist;			            /* min distance b/w features */
40   int window_width, window_height;
41   KLT_BOOL sequentialMode;          /* whether to save most recent image to save time */
42                                     /* can set to TRUE manually, but don't set to */
43                                     /* FALSE manually */
44   KLT_BOOL smoothBeforeSelecting;	/* whether to smooth image before */
45                                     /* selecting features */
46 
47   /* Available, but hopefully can ignore */
48   int min_eigenvalue;		/* smallest eigenvalue allowed for selecting */
49   float min_determinant;	/* th for determining lost */
50   float min_displacement;	/* th for stopping tracking when pixel changes little */
51   int max_iterations;		/* th for stopping tracking when too many iterations */
52   float max_residue;		/* th for stopping tracking when residue is large */
53   float grad_sigma;
54   float smooth_sigma_fact;
55   float pyramid_sigma_fact;
56   float step_factor;        /* size of Newton steps; 2.0 comes from equations, 1.0 seems to avoid overshooting */
57   int nSkippedPixels;		/* # of pixels skipped when finding features */
58   int borderx;              /* border in which features will not be found */
59   int bordery;
60   int nPyramidLevels;       /* computed from search_ranges */
61   int subsampling;          /* 		" */
62 
63   /* User must not touch these */
64   void *pyramid_last;
65   void *pyramid_last_gradx;
66   void *pyramid_last_grady;
67 
68   int verbose;
69 
70 }  KLT_TrackingContextRec, *KLT_TrackingContext;
71 
72 typedef struct  {
73   KLT_locType x;
74   KLT_locType y;
75   int val;
76 }  KLT_FeatureRec, *KLT_Feature;
77 
78 typedef struct  {
79   int nFeatures;
80   KLT_Feature *feature;
81 }  KLT_FeatureListRec, *KLT_FeatureList;
82 
83 typedef struct  {
84   int nFrames;
85   KLT_Feature *feature;
86 }  KLT_FeatureHistoryRec, *KLT_FeatureHistory;
87 
88 typedef struct  {
89   int nFrames;
90   int nFeatures;
91   KLT_Feature **feature;
92 }  KLT_FeatureTableRec, *KLT_FeatureTable;
93 
94 /*******************
95  * Functions
96  */
97 
98 /* Create */
99 KLT_TrackingContext KLTCreateTrackingContext();
100 KLT_FeatureList KLTCreateFeatureList(int);
101 
102 /* Free */
103 void KLTFreeTrackingContext(KLT_TrackingContext);
104 void KLTFreeFeatureList(KLT_FeatureList);
105 
106 /* Processing */
107 void KLTSelectGoodFeatures(
108   KLT_TrackingContext tc,
109   KLT_PixelType *img,
110   int ncols,
111   int nrows,
112   KLT_FeatureList fl);
113 void KLTTrackFeatures(
114   KLT_TrackingContext tc,
115   KLT_PixelType *img1,
116   KLT_PixelType *img2,
117   int ncols,
118   int nrows,
119   KLT_FeatureList fl);
120 void KLTReplaceLostFeatures(
121   KLT_TrackingContext tc,
122   KLT_PixelType *img,
123   int ncols,
124   int nrows,
125   KLT_FeatureList fl);
126 
127 /* Utilities */
128 int KLTCountRemainingFeatures(
129   KLT_FeatureList fl);
130 void KLTPrintTrackingContext(
131   KLT_TrackingContext tc);
132 void KLTChangeTCPyramid(
133   KLT_TrackingContext tc,
134   int search_range);
135 void KLTUpdateTCBorder(
136   KLT_TrackingContext tc);
137 void KLTStopSequentialMode(
138   KLT_TrackingContext tc);
139 float _KLTComputeSmoothSigma(
140   KLT_TrackingContext tc);
141 
142 #endif
143 
144