• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41 
42 #ifndef _CVTYPES_H_
43 #define _CVTYPES_H_
44 
45 #ifndef SKIP_INCLUDES
46   #include <assert.h>
47   #include <stdlib.h>
48 #endif
49 
50 /* spatial and central moments */
51 typedef struct CvMoments
52 {
53     double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */
54     double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */
55     double  inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */
56 }
57 CvMoments;
58 
59 /* Hu invariants */
60 typedef struct CvHuMoments
61 {
62     double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
63 }
64 CvHuMoments;
65 
66 /**************************** Connected Component  **************************************/
67 
68 typedef struct CvConnectedComp
69 {
70     double area;    /* area of the connected component  */
71     CvScalar value; /* average color of the connected component */
72     CvRect rect;    /* ROI of the component  */
73     CvSeq* contour; /* optional component boundary
74                       (the contour might have child contours corresponding to the holes)*/
75 }
76 CvConnectedComp;
77 
78 /*
79 Internal structure that is used for sequental retrieving contours from the image.
80 It supports both hierarchical and plane variants of Suzuki algorithm.
81 */
82 typedef struct _CvContourScanner* CvContourScanner;
83 
84 /* contour retrieval mode */
85 #define CV_RETR_EXTERNAL 0
86 #define CV_RETR_LIST     1
87 #define CV_RETR_CCOMP    2
88 #define CV_RETR_TREE     3
89 
90 /* contour approximation method */
91 #define CV_CHAIN_CODE               0
92 #define CV_CHAIN_APPROX_NONE        1
93 #define CV_CHAIN_APPROX_SIMPLE      2
94 #define CV_CHAIN_APPROX_TC89_L1     3
95 #define CV_CHAIN_APPROX_TC89_KCOS   4
96 #define CV_LINK_RUNS                5
97 
98 /* Freeman chain reader state */
99 typedef struct CvChainPtReader
100 {
101     CV_SEQ_READER_FIELDS()
102     char      code;
103     CvPoint   pt;
104     schar     deltas[8][2];
105 }
106 CvChainPtReader;
107 
108 /* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
109 #define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \
110     ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \
111      (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \
112      (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \
113      (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))
114 
115 /* Contour tree header */
116 typedef struct CvContourTree
117 {
118     CV_SEQUENCE_FIELDS()
119     CvPoint p1;            /* the first point of the binary tree root segment */
120     CvPoint p2;            /* the last point of the binary tree root segment */
121 }
122 CvContourTree;
123 
124 /* Finds a sequence of convexity defects of given contour */
125 typedef struct CvConvexityDefect
126 {
127     CvPoint* start; /* point of the contour where the defect begins */
128     CvPoint* end; /* point of the contour where the defect ends */
129     CvPoint* depth_point; /* the farthest from the convex hull point within the defect */
130     float depth; /* distance between the farthest point and the convex hull */
131 }
132 CvConvexityDefect;
133 
134 /************ Data structures and related enumerations for Planar Subdivisions ************/
135 
136 typedef size_t CvSubdiv2DEdge;
137 
138 #define CV_QUADEDGE2D_FIELDS()     \
139     int flags;                     \
140     struct CvSubdiv2DPoint* pt[4]; \
141     CvSubdiv2DEdge  next[4];
142 
143 #define CV_SUBDIV2D_POINT_FIELDS()\
144     int            flags;      \
145     CvSubdiv2DEdge first;      \
146     CvPoint2D32f   pt;
147 
148 #define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30)
149 
150 typedef struct CvQuadEdge2D
151 {
152     CV_QUADEDGE2D_FIELDS()
153 }
154 CvQuadEdge2D;
155 
156 typedef struct CvSubdiv2DPoint
157 {
158     CV_SUBDIV2D_POINT_FIELDS()
159 }
160 CvSubdiv2DPoint;
161 
162 #define CV_SUBDIV2D_FIELDS()    \
163     CV_GRAPH_FIELDS()           \
164     int  quad_edges;            \
165     int  is_geometry_valid;     \
166     CvSubdiv2DEdge recent_edge; \
167     CvPoint2D32f  topleft;      \
168     CvPoint2D32f  bottomright;
169 
170 typedef struct CvSubdiv2D
171 {
172     CV_SUBDIV2D_FIELDS()
173 }
174 CvSubdiv2D;
175 
176 
177 typedef enum CvSubdiv2DPointLocation
178 {
179     CV_PTLOC_ERROR = -2,
180     CV_PTLOC_OUTSIDE_RECT = -1,
181     CV_PTLOC_INSIDE = 0,
182     CV_PTLOC_VERTEX = 1,
183     CV_PTLOC_ON_EDGE = 2
184 }
185 CvSubdiv2DPointLocation;
186 
187 typedef enum CvNextEdgeType
188 {
189     CV_NEXT_AROUND_ORG   = 0x00,
190     CV_NEXT_AROUND_DST   = 0x22,
191     CV_PREV_AROUND_ORG   = 0x11,
192     CV_PREV_AROUND_DST   = 0x33,
193     CV_NEXT_AROUND_LEFT  = 0x13,
194     CV_NEXT_AROUND_RIGHT = 0x31,
195     CV_PREV_AROUND_LEFT  = 0x20,
196     CV_PREV_AROUND_RIGHT = 0x02
197 }
198 CvNextEdgeType;
199 
200 /* get the next edge with the same origin point (counterwise) */
201 #define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])
202 
203 
204 /* Defines for Distance Transform */
205 #define CV_DIST_USER    -1  /* User defined distance */
206 #define CV_DIST_L1      1   /* distance = |x1-x2| + |y1-y2| */
207 #define CV_DIST_L2      2   /* the simple euclidean distance */
208 #define CV_DIST_C       3   /* distance = max(|x1-x2|,|y1-y2|) */
209 #define CV_DIST_L12     4   /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
210 #define CV_DIST_FAIR    5   /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
211 #define CV_DIST_WELSCH  6   /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
212 #define CV_DIST_HUBER   7   /* distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */
213 
214 
215 /* Filters used in pyramid decomposition */
216 typedef enum CvFilter
217 {
218     CV_GAUSSIAN_5x5 = 7
219 }
220 CvFilter;
221 
222 /****************************************************************************************/
223 /*                                    Older definitions                                 */
224 /****************************************************************************************/
225 
226 typedef float*   CvVect32f;
227 typedef float*   CvMatr32f;
228 typedef double*  CvVect64d;
229 typedef double*  CvMatr64d;
230 
231 typedef struct CvMatrix3
232 {
233     float m[3][3];
234 }
235 CvMatrix3;
236 
237 
238 #ifdef __cplusplus
239 extern "C" {
240 #endif
241 
242 typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 typedef struct CvConDensation
249 {
250     int MP;
251     int DP;
252     float* DynamMatr;       /* Matrix of the linear Dynamics system  */
253     float* State;           /* Vector of State                       */
254     int SamplesNum;         /* Number of the Samples                 */
255     float** flSamples;      /* arr of the Sample Vectors             */
256     float** flNewSamples;   /* temporary array of the Sample Vectors */
257     float* flConfidence;    /* Confidence for each Sample            */
258     float* flCumulative;    /* Cumulative confidence                 */
259     float* Temp;            /* Temporary vector                      */
260     float* RandomSample;    /* RandomVector to update sample set     */
261     struct CvRandState* RandS; /* Array of structures to generate random vectors */
262 }
263 CvConDensation;
264 
265 /*
266 standard Kalman filter (in G. Welch' and G. Bishop's notation):
267 
268   x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
269   z(k)=H*x(k)+v(k),   p(v)~N(0,R)
270 */
271 typedef struct CvKalman
272 {
273     int MP;                     /* number of measurement vector dimensions */
274     int DP;                     /* number of state vector dimensions */
275     int CP;                     /* number of control vector dimensions */
276 
277     /* backward compatibility fields */
278 #if 1
279     float* PosterState;         /* =state_pre->data.fl */
280     float* PriorState;          /* =state_post->data.fl */
281     float* DynamMatr;           /* =transition_matrix->data.fl */
282     float* MeasurementMatr;     /* =measurement_matrix->data.fl */
283     float* MNCovariance;        /* =measurement_noise_cov->data.fl */
284     float* PNCovariance;        /* =process_noise_cov->data.fl */
285     float* KalmGainMatr;        /* =gain->data.fl */
286     float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
287     float* PosterErrorCovariance;/* =error_cov_post->data.fl */
288     float* Temp1;               /* temp1->data.fl */
289     float* Temp2;               /* temp2->data.fl */
290 #endif
291 
292     CvMat* state_pre;           /* predicted state (x'(k)):
293                                     x(k)=A*x(k-1)+B*u(k) */
294     CvMat* state_post;          /* corrected state (x(k)):
295                                     x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
296     CvMat* transition_matrix;   /* state transition matrix (A) */
297     CvMat* control_matrix;      /* control matrix (B)
298                                    (it is not used if there is no control)*/
299     CvMat* measurement_matrix;  /* measurement matrix (H) */
300     CvMat* process_noise_cov;   /* process noise covariance matrix (Q) */
301     CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
302     CvMat* error_cov_pre;       /* priori error estimate covariance matrix (P'(k)):
303                                     P'(k)=A*P(k-1)*At + Q)*/
304     CvMat* gain;                /* Kalman gain matrix (K(k)):
305                                     K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
306     CvMat* error_cov_post;      /* posteriori error estimate covariance matrix (P(k)):
307                                     P(k)=(I-K(k)*H)*P'(k) */
308     CvMat* temp1;               /* temporary matrices */
309     CvMat* temp2;
310     CvMat* temp3;
311     CvMat* temp4;
312     CvMat* temp5;
313 }
314 CvKalman;
315 
316 
317 /*********************** Haar-like Object Detection structures **************************/
318 #define CV_HAAR_MAGIC_VAL    0x42500000
319 #define CV_TYPE_NAME_HAAR    "opencv-haar-classifier"
320 
321 #define CV_IS_HAAR_CLASSIFIER( haar )                                                    \
322     ((haar) != NULL &&                                                                   \
323     (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
324 
325 #define CV_HAAR_FEATURE_MAX  3
326 
327 typedef struct CvHaarFeature
328 {
329     int  tilted;
330     struct
331     {
332         CvRect r;
333         float weight;
334     } rect[CV_HAAR_FEATURE_MAX];
335 }
336 CvHaarFeature;
337 
338 typedef struct CvHaarClassifier
339 {
340     int count;
341     CvHaarFeature* haar_feature;
342     float* threshold;
343     int* left;
344     int* right;
345     float* alpha;
346 }
347 CvHaarClassifier;
348 
349 typedef struct CvHaarStageClassifier
350 {
351     int  count;
352     float threshold;
353     CvHaarClassifier* classifier;
354 
355     int next;
356     int child;
357     int parent;
358 }
359 CvHaarStageClassifier;
360 
361 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
362 
363 typedef struct CvHaarClassifierCascade
364 {
365     int  flags;
366     int  count;
367     CvSize orig_window_size;
368     CvSize real_window_size;
369     double scale;
370     CvHaarStageClassifier* stage_classifier;
371     CvHidHaarClassifierCascade* hid_cascade;
372 }
373 CvHaarClassifierCascade;
374 
375 typedef struct CvAvgComp
376 {
377     CvRect rect;
378     int neighbors;
379 }
380 CvAvgComp;
381 
382 struct CvFeatureTree;
383 
384 #endif /*_CVTYPES_H_*/
385 
386 /* End of file. */
387