Cinder

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/OpenCV/cvtypes.h

Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                        Intel License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000, Intel Corporation, all rights reserved.
00014 // Third party copyrights are property of their respective owners.
00015 //
00016 // Redistribution and use in source and binary forms, with or without modification,
00017 // are permitted provided that the following conditions are met:
00018 //
00019 //   * Redistribution's of source code must retain the above copyright notice,
00020 //     this list of conditions and the following disclaimer.
00021 //
00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
00023 //     this list of conditions and the following disclaimer in the documentation
00024 //     and/or other materials provided with the distribution.
00025 //
00026 //   * The name of Intel Corporation may not be used to endorse or promote products
00027 //     derived from this software without specific prior written permission.
00028 //
00029 // This software is provided by the copyright holders and contributors "as is" and
00030 // any express or implied warranties, including, but not limited to, the implied
00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
00033 // indirect, incidental, special, exemplary, or consequential damages
00034 // (including, but not limited to, procurement of substitute goods or services;
00035 // loss of use, data, or profits; or business interruption) however caused
00036 // and on any theory of liability, whether in contract, strict liability,
00037 // or tort (including negligence or otherwise) arising in any way out of
00038 // the use of this software, even if advised of the possibility of such damage.
00039 //
00040 //M*/
00041 
00042 #ifndef __OPENCV_CVTYPES_H__
00043 #define __OPENCV_CVTYPES_H__
00044 
00045 #ifndef SKIP_INCLUDES
00046   #include <assert.h>
00047   #include <stdlib.h>
00048 #endif
00049 
00050 /* spatial and central moments */
00051 typedef struct CvMoments
00052 {
00053     double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */
00054     double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */
00055     double  inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */
00056 }
00057 CvMoments;
00058 
00059 /* Hu invariants */
00060 typedef struct CvHuMoments
00061 {
00062     double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */
00063 }
00064 CvHuMoments;
00065 
00066 /**************************** Connected Component  **************************************/
00067 
00068 typedef struct CvConnectedComp
00069 {
00070     double area;    /* area of the connected component  */
00071     CvScalar value; /* average color of the connected component */
00072     CvRect rect;    /* ROI of the component  */
00073     CvSeq* contour; /* optional component boundary
00074                       (the contour might have child contours corresponding to the holes)*/
00075 }
00076 CvConnectedComp;
00077 
00078 /*
00079 Internal structure that is used for sequental retrieving contours from the image.
00080 It supports both hierarchical and plane variants of Suzuki algorithm.
00081 */
00082 typedef struct _CvContourScanner* CvContourScanner;
00083 
00084 /* contour retrieval mode */
00085 #define CV_RETR_EXTERNAL 0
00086 #define CV_RETR_LIST     1
00087 #define CV_RETR_CCOMP    2
00088 #define CV_RETR_TREE     3
00089 
00090 /* contour approximation method */
00091 #define CV_CHAIN_CODE               0
00092 #define CV_CHAIN_APPROX_NONE        1
00093 #define CV_CHAIN_APPROX_SIMPLE      2
00094 #define CV_CHAIN_APPROX_TC89_L1     3
00095 #define CV_CHAIN_APPROX_TC89_KCOS   4
00096 #define CV_LINK_RUNS                5
00097 
00098 /* Freeman chain reader state */
00099 typedef struct CvChainPtReader
00100 {
00101     CV_SEQ_READER_FIELDS()
00102     char      code;
00103     CvPoint   pt;
00104     schar     deltas[8][2];
00105 }
00106 CvChainPtReader;
00107 
00108 /* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */
00109 #define  CV_INIT_3X3_DELTAS( deltas, step, nch )            \
00110     ((deltas)[0] =  (nch),  (deltas)[1] = -(step) + (nch),  \
00111      (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch),  \
00112      (deltas)[4] = -(nch),  (deltas)[5] =  (step) - (nch),  \
00113      (deltas)[6] =  (step), (deltas)[7] =  (step) + (nch))
00114 
00115 /* Contour tree header */
00116 typedef struct CvContourTree
00117 {
00118     CV_SEQUENCE_FIELDS()
00119     CvPoint p1;            /* the first point of the binary tree root segment */
00120     CvPoint p2;            /* the last point of the binary tree root segment */
00121 }
00122 CvContourTree;
00123 
00124 /* Finds a sequence of convexity defects of given contour */
00125 typedef struct CvConvexityDefect
00126 {
00127     CvPoint* start; /* point of the contour where the defect begins */
00128     CvPoint* end; /* point of the contour where the defect ends */
00129     CvPoint* depth_point; /* the farthest from the convex hull point within the defect */
00130     float depth; /* distance between the farthest point and the convex hull */
00131 }
00132 CvConvexityDefect;
00133 
00134 /************ Data structures and related enumerations for Planar Subdivisions ************/
00135 
00136 typedef size_t CvSubdiv2DEdge;
00137 
00138 #define CV_QUADEDGE2D_FIELDS()     \
00139     int flags;                     \
00140     struct CvSubdiv2DPoint* pt[4]; \
00141     CvSubdiv2DEdge  next[4];
00142 
00143 #define CV_SUBDIV2D_POINT_FIELDS()\
00144     int            flags;      \
00145     CvSubdiv2DEdge first;      \
00146     CvPoint2D32f   pt;         \
00147     int id;
00148 
00149 #define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30)
00150 
00151 typedef struct CvQuadEdge2D
00152 {
00153     CV_QUADEDGE2D_FIELDS()
00154 }
00155 CvQuadEdge2D;
00156 
00157 typedef struct CvSubdiv2DPoint
00158 {
00159     CV_SUBDIV2D_POINT_FIELDS()
00160 }
00161 CvSubdiv2DPoint;
00162 
00163 #define CV_SUBDIV2D_FIELDS()    \
00164     CV_GRAPH_FIELDS()           \
00165     int  quad_edges;            \
00166     int  is_geometry_valid;     \
00167     CvSubdiv2DEdge recent_edge; \
00168     CvPoint2D32f  topleft;      \
00169     CvPoint2D32f  bottomright;
00170 
00171 typedef struct CvSubdiv2D
00172 {
00173     CV_SUBDIV2D_FIELDS()
00174 }
00175 CvSubdiv2D;
00176 
00177 
00178 typedef enum CvSubdiv2DPointLocation
00179 {
00180     CV_PTLOC_ERROR = -2,
00181     CV_PTLOC_OUTSIDE_RECT = -1,
00182     CV_PTLOC_INSIDE = 0,
00183     CV_PTLOC_VERTEX = 1,
00184     CV_PTLOC_ON_EDGE = 2
00185 }
00186 CvSubdiv2DPointLocation;
00187 
00188 typedef enum CvNextEdgeType
00189 {
00190     CV_NEXT_AROUND_ORG   = 0x00,
00191     CV_NEXT_AROUND_DST   = 0x22,
00192     CV_PREV_AROUND_ORG   = 0x11,
00193     CV_PREV_AROUND_DST   = 0x33,
00194     CV_NEXT_AROUND_LEFT  = 0x13,
00195     CV_NEXT_AROUND_RIGHT = 0x31,
00196     CV_PREV_AROUND_LEFT  = 0x20,
00197     CV_PREV_AROUND_RIGHT = 0x02
00198 }
00199 CvNextEdgeType;
00200 
00201 /* get the next edge with the same origin point (counterwise) */
00202 #define  CV_SUBDIV2D_NEXT_EDGE( edge )  (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3])
00203 
00204 
00205 /* Defines for Distance Transform */
00206 #define CV_DIST_USER    -1  /* User defined distance */
00207 #define CV_DIST_L1      1   /* distance = |x1-x2| + |y1-y2| */
00208 #define CV_DIST_L2      2   /* the simple euclidean distance */
00209 #define CV_DIST_C       3   /* distance = max(|x1-x2|,|y1-y2|) */
00210 #define CV_DIST_L12     4   /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
00211 #define CV_DIST_FAIR    5   /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
00212 #define CV_DIST_WELSCH  6   /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
00213 #define CV_DIST_HUBER   7   /* distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */
00214 
00215 
00216 /* Filters used in pyramid decomposition */
00217 typedef enum CvFilter
00218 {
00219     CV_GAUSSIAN_5x5 = 7
00220 }
00221 CvFilter;
00222 
00223 /****************************************************************************************/
00224 /*                                    Older definitions                                 */
00225 /****************************************************************************************/
00226 
00227 typedef float*   CvVect32f;
00228 typedef float*   CvMatr32f;
00229 typedef double*  CvVect64d;
00230 typedef double*  CvMatr64d;
00231 
00232 typedef struct CvMatrix3
00233 {
00234     float m[3][3];
00235 }
00236 CvMatrix3;
00237 
00238 
00239 #ifdef __cplusplus
00240 extern "C" {
00241 #endif
00242 
00243 typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param );
00244 
00245 #ifdef __cplusplus
00246 }
00247 #endif
00248 
00249 
00250 /*
00251 standard Kalman filter (in G. Welch' and G. Bishop's notation):
00252 
00253   x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
00254   z(k)=H*x(k)+v(k),   p(v)~N(0,R)
00255 */
00256 typedef struct CvKalman
00257 {
00258     int MP;                     /* number of measurement vector dimensions */
00259     int DP;                     /* number of state vector dimensions */
00260     int CP;                     /* number of control vector dimensions */
00261 
00262     /* backward compatibility fields */
00263 #if 1
00264     float* PosterState;         /* =state_pre->data.fl */
00265     float* PriorState;          /* =state_post->data.fl */
00266     float* DynamMatr;           /* =transition_matrix->data.fl */
00267     float* MeasurementMatr;     /* =measurement_matrix->data.fl */
00268     float* MNCovariance;        /* =measurement_noise_cov->data.fl */
00269     float* PNCovariance;        /* =process_noise_cov->data.fl */
00270     float* KalmGainMatr;        /* =gain->data.fl */
00271     float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
00272     float* PosterErrorCovariance;/* =error_cov_post->data.fl */
00273     float* Temp1;               /* temp1->data.fl */
00274     float* Temp2;               /* temp2->data.fl */
00275 #endif
00276 
00277     CvMat* state_pre;           /* predicted state (x'(k)):
00278                                     x(k)=A*x(k-1)+B*u(k) */
00279     CvMat* state_post;          /* corrected state (x(k)):
00280                                     x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
00281     CvMat* transition_matrix;   /* state transition matrix (A) */
00282     CvMat* control_matrix;      /* control matrix (B)
00283                                    (it is not used if there is no control)*/
00284     CvMat* measurement_matrix;  /* measurement matrix (H) */
00285     CvMat* process_noise_cov;   /* process noise covariance matrix (Q) */
00286     CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
00287     CvMat* error_cov_pre;       /* priori error estimate covariance matrix (P'(k)):
00288                                     P'(k)=A*P(k-1)*At + Q)*/
00289     CvMat* gain;                /* Kalman gain matrix (K(k)):
00290                                     K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
00291     CvMat* error_cov_post;      /* posteriori error estimate covariance matrix (P(k)):
00292                                     P(k)=(I-K(k)*H)*P'(k) */
00293     CvMat* temp1;               /* temporary matrices */
00294     CvMat* temp2;
00295     CvMat* temp3;
00296     CvMat* temp4;
00297     CvMat* temp5;
00298 }
00299 CvKalman;
00300 
00301 
00302 /*********************** Haar-like Object Detection structures **************************/
00303 #define CV_HAAR_MAGIC_VAL    0x42500000
00304 #define CV_TYPE_NAME_HAAR    "opencv-haar-classifier"
00305 
00306 #define CV_IS_HAAR_CLASSIFIER( haar )                                                    \
00307     ((haar) != NULL &&                                                                   \
00308     (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
00309 
00310 #define CV_HAAR_FEATURE_MAX  3
00311 
00312 typedef struct CvHaarFeature
00313 {
00314     int  tilted;
00315     struct
00316     {
00317         CvRect r;
00318         float weight;
00319     } rect[CV_HAAR_FEATURE_MAX];
00320 }
00321 CvHaarFeature;
00322 
00323 typedef struct CvHaarClassifier
00324 {
00325     int count;
00326     CvHaarFeature* haar_feature;
00327     float* threshold;
00328     int* left;
00329     int* right;
00330     float* alpha;
00331 }
00332 CvHaarClassifier;
00333 
00334 typedef struct CvHaarStageClassifier
00335 {
00336     int  count;
00337     float threshold;
00338     CvHaarClassifier* classifier;
00339 
00340     int next;
00341     int child;
00342     int parent;
00343 }
00344 CvHaarStageClassifier;
00345 
00346 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
00347 
00348 typedef struct CvHaarClassifierCascade
00349 {
00350     int  flags;
00351     int  count;
00352     CvSize orig_window_size;
00353     CvSize real_window_size;
00354     double scale;
00355     CvHaarStageClassifier* stage_classifier;
00356     CvHidHaarClassifierCascade* hid_cascade;
00357 }
00358 CvHaarClassifierCascade;
00359 
00360 typedef struct CvAvgComp
00361 {
00362     CvRect rect;
00363     int neighbors;
00364 }
00365 CvAvgComp;
00366 
00367 struct CvFeatureTree;
00368 
00369 #endif /*_CVTYPES_H_*/
00370 
00371 /* End of file. */