cvaux.h
上传用户:soukeisyuu
上传日期:2022-07-03
资源大小:5943k
文件大小:62k
源码类别:

波变换

开发平台:

Visual C++

  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. #ifndef __CVAUX__H__
  42. #define __CVAUX__H__
  43. #include "cv.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. CVAPI(CvSeq*) cvSegmentImage( const CvArr* srcarr, CvArr* dstarr,
  48.                                     double canny_threshold,
  49.                                     double ffill_threshold,
  50.                                     CvMemStorage* storage );
  51. /****************************************************************************************
  52. *                                  Eigen objects                                         *
  53. ****************************************************************************************/
  54. typedef int (CV_CDECL * CvCallback)(int index, void* buffer, void* user_data);
  55. typedef union
  56. {
  57.     CvCallback callback;
  58.     void* data;
  59. }
  60. CvInput;
  61. #define CV_EIGOBJ_NO_CALLBACK     0
  62. #define CV_EIGOBJ_INPUT_CALLBACK  1
  63. #define CV_EIGOBJ_OUTPUT_CALLBACK 2
  64. #define CV_EIGOBJ_BOTH_CALLBACK   3
  65. /* Calculates covariation matrix of a set of arrays */
  66. CVAPI(void)  cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags,
  67.                                   int ioBufSize, uchar* buffer, void* userData,
  68.                                   IplImage* avg, float* covarMatrix );
  69. /* Calculates eigen values and vectors of covariation matrix of a set of
  70.    arrays */
  71. CVAPI(void)  cvCalcEigenObjects( int nObjects, void* input, void* output,
  72.                                  int ioFlags, int ioBufSize, void* userData,
  73.                                  CvTermCriteria* calcLimit, IplImage* avg,
  74.                                  float* eigVals );
  75. /* Calculates dot product (obj - avg) * eigObj (i.e. projects image to eigen vector) */
  76. CVAPI(double)  cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg );
  77. /* Projects image to eigen space (finds all decomposion coefficients */
  78. CVAPI(void)  cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput,
  79.                                  int ioFlags, void* userData, IplImage* avg,
  80.                                  float* coeffs );
  81. /* Projects original objects used to calculate eigen space basis to that space */
  82. CVAPI(void)  cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags,
  83.                                 void* userData, float* coeffs, IplImage* avg,
  84.                                 IplImage* proj );
  85. /****************************************************************************************
  86. *                                       1D/2D HMM                                        *
  87. ****************************************************************************************/
  88. typedef struct CvImgObsInfo
  89. {
  90.     int obs_x;
  91.     int obs_y;
  92.     int obs_size;
  93.     float* obs;//consequtive observations
  94.     int* state;/* arr of pairs superstate/state to which observation belong */
  95.     int* mix;  /* number of mixture to which observation belong */
  96. }
  97. CvImgObsInfo;/*struct for 1 image*/
  98. typedef CvImgObsInfo Cv1DObsInfo;
  99. typedef struct CvEHMMState
  100. {
  101.     int num_mix;        /*number of mixtures in this state*/
  102.     float* mu;          /*mean vectors corresponding to each mixture*/
  103.     float* inv_var;     /* square root of inversed variances corresp. to each mixture*/
  104.     float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */
  105.     float* weight;      /*array of mixture weights. Summ of all weights in state is 1. */
  106. }
  107. CvEHMMState;
  108. typedef struct CvEHMM
  109. {
  110.     int level; /* 0 - lowest(i.e its states are real states), ..... */
  111.     int num_states; /* number of HMM states */
  112.     float*  transP;/*transition probab. matrices for states */
  113.     float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm
  114.                         if level == 1 - martix of matrices */
  115.     union
  116.     {
  117.         CvEHMMState* state; /* if level == 0 points to real states array,
  118.                                if not - points to embedded hmms */
  119.         struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */
  120.     } u;
  121. }
  122. CvEHMM;
  123. /*CVAPI(int)  icvCreate1DHMM( CvEHMM** this_hmm,
  124.                                    int state_number, int* num_mix, int obs_size );
  125. CVAPI(int)  icvRelease1DHMM( CvEHMM** phmm );
  126. CVAPI(int)  icvUniform1DSegm( Cv1DObsInfo* obs_info, CvEHMM* hmm );
  127. CVAPI(int)  icvInit1DMixSegm( Cv1DObsInfo** obs_info_array, int num_img, CvEHMM* hmm);
  128. CVAPI(int)  icvEstimate1DHMMStateParams( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm);
  129. CVAPI(int)  icvEstimate1DObsProb( CvImgObsInfo* obs_info, CvEHMM* hmm );
  130. CVAPI(int)  icvEstimate1DTransProb( Cv1DObsInfo** obs_info_array,
  131.                                            int num_seq,
  132.                                            CvEHMM* hmm );
  133. CVAPI(float)  icvViterbi( Cv1DObsInfo* obs_info, CvEHMM* hmm);
  134. CVAPI(int)  icv1DMixSegmL2( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm );*/
  135. /*********************************** Embedded HMMs *************************************/
  136. /* Creates 2D HMM */
  137. CVAPI(CvEHMM*)  cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );
  138. /* Releases HMM */
  139. CVAPI(void)  cvRelease2DHMM( CvEHMM** hmm );
  140. #define CV_COUNT_OBS(roi, win, delta, numObs )                                       
  141. {                                                                                    
  142.    (numObs)->width  =((roi)->width  -(win)->width  +(delta)->width)/(delta)->width;  
  143.    (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;
  144. }
  145. /* Creates storage for observation vectors */
  146. CVAPI(CvImgObsInfo*)  cvCreateObsInfo( CvSize numObs, int obsSize );
  147. /* Releases storage for observation vectors */
  148. CVAPI(void)  cvReleaseObsInfo( CvImgObsInfo** obs_info );
  149. /* The function takes an image on input and and returns the sequnce of observations
  150.    to be used with an embedded HMM; Each observation is top-left block of DCT
  151.    coefficient matrix */
  152. CVAPI(void)  cvImgToObs_DCT( const CvArr* arr, float* obs, CvSize dctSize,
  153.                              CvSize obsSize, CvSize delta );
  154. /* Uniformly segments all observation vectors extracted from image */
  155. CVAPI(void)  cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm );
  156. /* Does mixture segmentation of the states of embedded HMM */
  157. CVAPI(void)  cvInitMixSegm( CvImgObsInfo** obs_info_array,
  158.                             int num_img, CvEHMM* hmm );
  159. /* Function calculates means, variances, weights of every Gaussian mixture
  160.    of every low-level state of embedded HMM */
  161. CVAPI(void)  cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array,
  162.                                        int num_img, CvEHMM* hmm );
  163. /* Function computes transition probability matrices of embedded HMM
  164.    given observations segmentation */
  165. CVAPI(void)  cvEstimateTransProb( CvImgObsInfo** obs_info_array,
  166.                                   int num_img, CvEHMM* hmm );
  167. /* Function computes probabilities of appearing observations at any state
  168.    (i.e. computes P(obs|state) for every pair(obs,state)) */
  169. CVAPI(void)  cvEstimateObsProb( CvImgObsInfo* obs_info,
  170.                                 CvEHMM* hmm );
  171. /* Runs Viterbi algorithm for embedded HMM */
  172. CVAPI(float)  cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm );
  173. /* Function clusters observation vectors from several images
  174.    given observations segmentation.
  175.    Euclidean distance used for clustering vectors.
  176.    Centers of clusters are given means of every mixture */
  177. CVAPI(void)  cvMixSegmL2( CvImgObsInfo** obs_info_array,
  178.                           int num_img, CvEHMM* hmm );
  179. /****************************************************************************************
  180. *               A few functions from old stereo gesture recognition demosions            *
  181. ****************************************************************************************/
  182. /* Creates hand mask image given several points on the hand */
  183. CVAPI(void)  cvCreateHandMask( CvSeq* hand_points,
  184.                                    IplImage *img_mask, CvRect *roi);
  185. /* Finds hand region in range image data */
  186. CVAPI(void)  cvFindHandRegion (CvPoint3D32f* points, int count,
  187.                                 CvSeq* indexs,
  188.                                 float* line, CvSize2D32f size, int flag,
  189.                                 CvPoint3D32f* center,
  190.                                 CvMemStorage* storage, CvSeq **numbers);
  191. /* Finds hand region in range image data (advanced version) */
  192. CVAPI(void)  cvFindHandRegionA( CvPoint3D32f* points, int count,
  193.                                 CvSeq* indexs,
  194.                                 float* line, CvSize2D32f size, int jc,
  195.                                 CvPoint3D32f* center,
  196.                                 CvMemStorage* storage, CvSeq **numbers);
  197. /****************************************************************************************
  198. *                           Additional operations on Subdivisions                        *
  199. ****************************************************************************************/
  200. // paints voronoi diagram: just demo function
  201. CVAPI(void)  icvDrawMosaic( CvSubdiv2D* subdiv, IplImage* src, IplImage* dst );
  202. // checks planar subdivision for correctness. It is not an absolute check,
  203. // but it verifies some relations between quad-edges
  204. CVAPI(int)   icvSubdiv2DCheck( CvSubdiv2D* subdiv );
  205. // returns squared distance between two 2D points with floating-point coordinates.
  206. CV_INLINE double icvSqDist2D32f( CvPoint2D32f pt1, CvPoint2D32f pt2 )
  207. {
  208.     double dx = pt1.x - pt2.x;
  209.     double dy = pt1.y - pt2.y;
  210.     return dx*dx + dy*dy;
  211. }
  212. /****************************************************************************************
  213. *                           More operations on sequences                                 *
  214. ****************************************************************************************/
  215. /*****************************************************************************************/
  216. #define CV_CURRENT_INT( reader ) (*((int *)(reader).ptr))
  217. #define CV_PREV_INT( reader ) (*((int *)(reader).prev_elem))
  218. #define  CV_GRAPH_WEIGHTED_VERTEX_FIELDS() CV_GRAPH_VERTEX_FIELDS()
  219.     float weight;
  220. #define  CV_GRAPH_WEIGHTED_EDGE_FIELDS() CV_GRAPH_EDGE_FIELDS()
  221. typedef struct CvGraphWeightedVtx
  222. {
  223.     CV_GRAPH_WEIGHTED_VERTEX_FIELDS()
  224. }
  225. CvGraphWeightedVtx;
  226. typedef struct CvGraphWeightedEdge
  227. {
  228.     CV_GRAPH_WEIGHTED_EDGE_FIELDS()
  229. }
  230. CvGraphWeightedEdge;
  231. typedef enum CvGraphWeightType
  232. {
  233.     CV_NOT_WEIGHTED,
  234.     CV_WEIGHTED_VTX,
  235.     CV_WEIGHTED_EDGE,
  236.     CV_WEIGHTED_ALL
  237. } CvGraphWeightType;
  238. /*****************************************************************************************/
  239. /*******************************Stereo correspondence*************************************/
  240. typedef struct CvCliqueFinder
  241. {   
  242.     CvGraph* graph;
  243.     int**    adj_matr;
  244.     int N; //graph size
  245.     // stacks, counters etc/
  246.     int k; //stack size
  247.     int* current_comp;
  248.     int** All;
  249.     
  250.     int* ne;
  251.     int* ce;
  252.     int* fixp; //node with minimal disconnections
  253.     int* nod;
  254.     int* s; //for selected candidate
  255.     int status;
  256.     int best_score;
  257.     int weighted;
  258.     int weighted_edges;    
  259.     float best_weight;
  260.     float* edge_weights;
  261.     float* vertex_weights;
  262.     float* cur_weight;
  263.     float* cand_weight;
  264. } CvCliqueFinder;
  265. #define CLIQUE_TIME_OFF 2
  266. #define CLIQUE_FOUND 1
  267. #define CLIQUE_END   0
  268. /*CVAPI(void) cvStartFindCliques( CvGraph* graph, CvCliqueFinder* finder, int reverse, 
  269.                                    int weighted CV_DEFAULT(0),  int weighted_edges CV_DEFAULT(0));
  270. CVAPI(int) cvFindNextMaximalClique( CvCliqueFinder* finder, int* clock_rest CV_DEFAULT(0) ); 
  271. CVAPI(void) cvEndFindCliques( CvCliqueFinder* finder );
  272. CVAPI(void) cvBronKerbosch( CvGraph* graph );*/
  273. /*F///////////////////////////////////////////////////////////////////////////////////////
  274. //
  275. //    Name:    cvSubgraphWeight
  276. //    Purpose: finds weight of subgraph in a graph
  277. //    Context:
  278. //    Parameters:
  279. //      graph - input graph.
  280. //      subgraph - sequence of pairwise different ints.  These are indices of vertices of subgraph.
  281. //      weight_type - describes the way we measure weight.
  282. //            one of the following:
  283. //            CV_NOT_WEIGHTED - weight of a clique is simply its size
  284. //            CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
  285. //            CV_WEIGHTED_EDGE - the same but edges
  286. //            CV_WEIGHTED_ALL - the same but both edges and vertices
  287. //      weight_vtx - optional vector of floats, with size = graph->total.
  288. //            If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
  289. //            weights of vertices must be provided.  If weight_vtx not zero
  290. //            these weights considered to be here, otherwise function assumes
  291. //            that vertices of graph are inherited from CvGraphWeightedVtx.
  292. //      weight_edge - optional matrix of floats, of width and height = graph->total.
  293. //            If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  294. //            weights of edges ought to be supplied.  If weight_edge is not zero
  295. //            function finds them here, otherwise function expects
  296. //            edges of graph to be inherited from CvGraphWeightedEdge.
  297. //            If this parameter is not zero structure of the graph is determined from matrix
  298. //            rather than from CvGraphEdge's.  In particular, elements corresponding to
  299. //            absent edges should be zero.
  300. //    Returns:
  301. //      weight of subgraph.
  302. //    Notes:
  303. //F*/
  304. /*CVAPI(float) cvSubgraphWeight( CvGraph *graph, CvSeq *subgraph,
  305.                                   CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
  306.                                   CvVect32f weight_vtx CV_DEFAULT(0),
  307.                                   CvMatr32f weight_edge CV_DEFAULT(0) );*/
  308. /*F///////////////////////////////////////////////////////////////////////////////////////
  309. //
  310. //    Name:    cvFindCliqueEx
  311. //    Purpose: tries to find clique with maximum possible weight in a graph
  312. //    Context:
  313. //    Parameters:
  314. //      graph - input graph.
  315. //      storage - memory storage to be used by the result.
  316. //      is_complementary - optional flag showing whether function should seek for clique
  317. //            in complementary graph.
  318. //      weight_type - describes our notion about weight.
  319. //            one of the following:
  320. //            CV_NOT_WEIGHTED - weight of a clique is simply its size
  321. //            CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
  322. //            CV_WEIGHTED_EDGE - the same but edges
  323. //            CV_WEIGHTED_ALL - the same but both edges and vertices
  324. //      weight_vtx - optional vector of floats, with size = graph->total.
  325. //            If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
  326. //            weights of vertices must be provided.  If weight_vtx not zero
  327. //            these weights considered to be here, otherwise function assumes
  328. //            that vertices of graph are inherited from CvGraphWeightedVtx.
  329. //      weight_edge - optional matrix of floats, of width and height = graph->total.
  330. //            If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  331. //            weights of edges ought to be supplied.  If weight_edge is not zero
  332. //            function finds them here, otherwise function expects
  333. //            edges of graph to be inherited from CvGraphWeightedEdge.
  334. //            Note that in case of CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  335. //            nonzero is_complementary implies nonzero weight_edge.
  336. //      start_clique - optional sequence of pairwise different ints.  They are indices of
  337. //            vertices that shall be present in the output clique.
  338. //      subgraph_of_ban - optional sequence of (maybe equal) ints.  They are indices of
  339. //            vertices that shall not be present in the output clique.
  340. //      clique_weight_ptr - optional output parameter.  Weight of found clique stored here.
  341. //      num_generations - optional number of generations in evolutionary part of algorithm,
  342. //            zero forces to return first found clique.
  343. //      quality - optional parameter determining degree of required quality/speed tradeoff.
  344. //            Must be in the range from 0 to 9.
  345. //            0 is fast and dirty, 9 is slow but hopefully yields good clique.
  346. //    Returns:
  347. //      sequence of pairwise different ints.
  348. //      These are indices of vertices that form found clique.
  349. //    Notes:
  350. //      in cases of CV_WEIGHTED_EDGE and CV_WEIGHTED_ALL weights should be nonnegative.
  351. //      start_clique has a priority over subgraph_of_ban.
  352. //F*/
  353. /*CVAPI(CvSeq*) cvFindCliqueEx( CvGraph *graph, CvMemStorage *storage,
  354.                                  int is_complementary CV_DEFAULT(0),
  355.                                  CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
  356.                                  CvVect32f weight_vtx CV_DEFAULT(0),
  357.                                  CvMatr32f weight_edge CV_DEFAULT(0),
  358.                                  CvSeq *start_clique CV_DEFAULT(0),
  359.                                  CvSeq *subgraph_of_ban CV_DEFAULT(0),
  360.                                  float *clique_weight_ptr CV_DEFAULT(0),
  361.                                  int num_generations CV_DEFAULT(3),
  362.                                  int quality CV_DEFAULT(2) );*/
  363. #define CV_UNDEF_SC_PARAM         12345 //default value of parameters
  364. #define CV_IDP_BIRCHFIELD_PARAM1  25    
  365. #define CV_IDP_BIRCHFIELD_PARAM2  5
  366. #define CV_IDP_BIRCHFIELD_PARAM3  12
  367. #define CV_IDP_BIRCHFIELD_PARAM4  15
  368. #define CV_IDP_BIRCHFIELD_PARAM5  25
  369. #define  CV_DISPARITY_BIRCHFIELD  0    
  370. /*F///////////////////////////////////////////////////////////////////////////
  371. //
  372. //    Name:    cvFindStereoCorrespondence
  373. //    Purpose: find stereo correspondence on stereo-pair
  374. //    Context:
  375. //    Parameters:
  376. //      leftImage - left image of stereo-pair (format 8uC1).
  377. //      rightImage - right image of stereo-pair (format 8uC1).
  378. //   mode - mode of correspondence retrieval (now CV_DISPARITY_BIRCHFIELD only)
  379. //      dispImage - destination disparity image
  380. //      maxDisparity - maximal disparity 
  381. //      param1, param2, param3, param4, param5 - parameters of algorithm
  382. //    Returns:
  383. //    Notes:
  384. //      Images must be rectified.
  385. //      All images must have format 8uC1.
  386. //F*/
  387. CVAPI(void) 
  388. cvFindStereoCorrespondence( 
  389.                    const  CvArr* leftImage, const  CvArr* rightImage,
  390.                    int     mode,
  391.                    CvArr*  dispImage,
  392.                    int     maxDisparity,                                
  393.                    double  param1 CV_DEFAULT(CV_UNDEF_SC_PARAM), 
  394.                    double  param2 CV_DEFAULT(CV_UNDEF_SC_PARAM), 
  395.                    double  param3 CV_DEFAULT(CV_UNDEF_SC_PARAM), 
  396.                    double  param4 CV_DEFAULT(CV_UNDEF_SC_PARAM), 
  397.                    double  param5 CV_DEFAULT(CV_UNDEF_SC_PARAM) );
  398. /*****************************************************************************************/
  399. /************ Epiline functions *******************/
  400. typedef struct CvStereoLineCoeff
  401. {
  402.     double Xcoef;
  403.     double XcoefA;
  404.     double XcoefB;
  405.     double XcoefAB;
  406.     double Ycoef;
  407.     double YcoefA;
  408.     double YcoefB;
  409.     double YcoefAB;
  410.     double Zcoef;
  411.     double ZcoefA;
  412.     double ZcoefB;
  413.     double ZcoefAB;
  414. }CvStereoLineCoeff;
  415. typedef struct CvCamera
  416. {
  417.     float   imgSize[2]; /* size of the camera view, used during calibration */
  418.     float   matrix[9]; /* intinsic camera parameters:  [ fx 0 cx; 0 fy cy; 0 0 1 ] */
  419.     float   distortion[4]; /* distortion coefficients - two coefficients for radial distortion
  420.                               and another two for tangential: [ k1 k2 p1 p2 ] */
  421.     float   rotMatr[9];
  422.     float   transVect[3]; /* rotation matrix and transition vector relatively
  423.                              to some reference point in the space. */
  424. }
  425. CvCamera;
  426. typedef struct CvStereoCamera
  427. {
  428.     CvCamera* camera[2]; /* two individual camera parameters */
  429.     float fundMatr[9]; /* fundamental matrix */
  430.     /* New part for stereo */
  431.     CvPoint3D32f epipole[2];
  432.     CvPoint2D32f quad[2][4]; /* coordinates of destination quadrangle after
  433.                                 epipolar geometry rectification */
  434.     double coeffs[2][3][3];/* coefficients for transformation */
  435.     CvPoint2D32f border[2][4];
  436.     CvSize warpSize;
  437.     CvStereoLineCoeff* lineCoeffs;
  438.     int needSwapCameras;/* flag set to 1 if need to swap cameras for good reconstruction */
  439.     float rotMatrix[9];
  440.     float transVector[3];
  441. }
  442. CvStereoCamera;
  443. typedef struct CvContourOrientation
  444. {
  445.     float egvals[2];
  446.     float egvects[4];
  447.     float max, min; // minimum and maximum projections
  448.     int imax, imin;
  449. } CvContourOrientation;
  450. #define CV_CAMERA_TO_WARP 1
  451. #define CV_WARP_TO_CAMERA 2
  452. CVAPI(int) icvConvertWarpCoordinates(double coeffs[3][3],
  453.                                 CvPoint2D32f* cameraPoint,
  454.                                 CvPoint2D32f* warpPoint,
  455.                                 int direction);
  456. CVAPI(int) icvGetSymPoint3D(  CvPoint3D64f pointCorner,
  457.                             CvPoint3D64f point1,
  458.                             CvPoint3D64f point2,
  459.                             CvPoint3D64f *pointSym2);
  460. CVAPI(void) icvGetPieceLength3D(CvPoint3D64f point1,CvPoint3D64f point2,double* dist);
  461. CVAPI(int) icvCompute3DPoint(    double alpha,double betta,
  462.                             CvStereoLineCoeff* coeffs,
  463.                             CvPoint3D64f* point);
  464. CVAPI(int) icvCreateConvertMatrVect( CvMatr64d     rotMatr1,
  465.                                 CvMatr64d     transVect1,
  466.                                 CvMatr64d     rotMatr2,
  467.                                 CvMatr64d     transVect2,
  468.                                 CvMatr64d     convRotMatr,
  469.                                 CvMatr64d     convTransVect);
  470. CVAPI(int) icvConvertPointSystem(CvPoint3D64f  M2,
  471.                             CvPoint3D64f* M1,
  472.                             CvMatr64d     rotMatr,
  473.                             CvMatr64d     transVect
  474.                             );
  475. CVAPI(int) icvComputeCoeffForStereo(  CvStereoCamera* stereoCamera);
  476. CVAPI(int) icvGetCrossPieceVector(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f v2_start,CvPoint2D32f v2_end,CvPoint2D32f *cross);
  477. CVAPI(int) icvGetCrossLineDirect(CvPoint2D32f p1,CvPoint2D32f p2,float a,float b,float c,CvPoint2D32f* cross);
  478. CVAPI(float) icvDefinePointPosition(CvPoint2D32f point1,CvPoint2D32f point2,CvPoint2D32f point);
  479. CVAPI(int) icvStereoCalibration( int numImages,
  480.                             int* nums,
  481.                             CvSize imageSize,
  482.                             CvPoint2D32f* imagePoints1,
  483.                             CvPoint2D32f* imagePoints2,
  484.                             CvPoint3D32f* objectPoints,
  485.                             CvStereoCamera* stereoparams
  486.                            );
  487. CVAPI(int) icvComputeRestStereoParams(CvStereoCamera *stereoparams);
  488. CVAPI(void) cvComputePerspectiveMap( const double coeffs[3][3], CvArr* rectMapX, CvArr* rectMapY );
  489. CVAPI(int) icvComCoeffForLine(   CvPoint2D64f point1,
  490.                             CvPoint2D64f point2,
  491.                             CvPoint2D64f point3,
  492.                             CvPoint2D64f point4,
  493.                             CvMatr64d    camMatr1,
  494.                             CvMatr64d    rotMatr1,
  495.                             CvMatr64d    transVect1,
  496.                             CvMatr64d    camMatr2,
  497.                             CvMatr64d    rotMatr2,
  498.                             CvMatr64d    transVect2,
  499.                             CvStereoLineCoeff*    coeffs,
  500.                             int* needSwapCameras);
  501. CVAPI(int) icvGetDirectionForPoint(  CvPoint2D64f point,
  502.                                 CvMatr64d camMatr,
  503.                                 CvPoint3D64f* direct);
  504. CVAPI(int) icvGetCrossLines(CvPoint3D64f point11,CvPoint3D64f point12,
  505.                        CvPoint3D64f point21,CvPoint3D64f point22,
  506.                        CvPoint3D64f* midPoint);
  507. CVAPI(int) icvComputeStereoLineCoeffs(   CvPoint3D64f pointA,
  508.                                     CvPoint3D64f pointB,
  509.                                     CvPoint3D64f pointCam1,
  510.                                     double gamma,
  511.                                     CvStereoLineCoeff*    coeffs);
  512. /*CVAPI(int) icvComputeFundMatrEpipoles ( CvMatr64d camMatr1, 
  513.                                     CvMatr64d     rotMatr1, 
  514.                                     CvVect64d     transVect1,
  515.                                     CvMatr64d     camMatr2,
  516.                                     CvMatr64d     rotMatr2,
  517.                                     CvVect64d     transVect2,
  518.                                     CvPoint2D64f* epipole1,
  519.                                     CvPoint2D64f* epipole2,
  520.                                     CvMatr64d     fundMatr);*/
  521. CVAPI(int) icvGetAngleLine( CvPoint2D64f startPoint, CvSize imageSize,CvPoint2D64f *point1,CvPoint2D64f *point2);
  522. CVAPI(void) icvGetCoefForPiece(   CvPoint2D64f p_start,CvPoint2D64f p_end,
  523.                         double *a,double *b,double *c,
  524.                         int* result);
  525. /*CVAPI(void) icvGetCommonArea( CvSize imageSize,
  526.                     CvPoint2D64f epipole1,CvPoint2D64f epipole2,
  527.                     CvMatr64d fundMatr,
  528.                     CvVect64d coeff11,CvVect64d coeff12,
  529.                     CvVect64d coeff21,CvVect64d coeff22,
  530.                     int* result);*/
  531. CVAPI(void) icvComputeeInfiniteProject1(CvMatr64d    rotMatr,
  532.                                      CvMatr64d    camMatr1,
  533.                                      CvMatr64d    camMatr2,
  534.                                      CvPoint2D32f point1,
  535.                                      CvPoint2D32f *point2);
  536. CVAPI(void) icvComputeeInfiniteProject2(CvMatr64d    rotMatr,
  537.                                      CvMatr64d    camMatr1,
  538.                                      CvMatr64d    camMatr2,
  539.                                      CvPoint2D32f* point1,
  540.                                      CvPoint2D32f point2);
  541. CVAPI(void) icvGetCrossDirectDirect(  CvVect64d direct1,CvVect64d direct2,
  542.                             CvPoint2D64f *cross,int* result);
  543. CVAPI(void) icvGetCrossPieceDirect(   CvPoint2D64f p_start,CvPoint2D64f p_end,
  544.                             double a,double b,double c,
  545.                             CvPoint2D64f *cross,int* result);
  546. CVAPI(void) icvGetCrossPiecePiece( CvPoint2D64f p1_start,CvPoint2D64f p1_end,
  547.                             CvPoint2D64f p2_start,CvPoint2D64f p2_end,
  548.                             CvPoint2D64f* cross,
  549.                             int* result);
  550.                             
  551. CVAPI(void) icvGetPieceLength(CvPoint2D64f point1,CvPoint2D64f point2,double* dist);
  552. CVAPI(void) icvGetCrossRectDirect(    CvSize imageSize,
  553.                             double a,double b,double c,
  554.                             CvPoint2D64f *start,CvPoint2D64f *end,
  555.                             int* result);
  556. CVAPI(void) icvProjectPointToImage(   CvPoint3D64f point,
  557.                             CvMatr64d camMatr,CvMatr64d rotMatr,CvVect64d transVect,
  558.                             CvPoint2D64f* projPoint);
  559. CVAPI(void) icvGetQuadsTransform( CvSize        imageSize,
  560.                         CvMatr64d     camMatr1,
  561.                         CvMatr64d     rotMatr1,
  562.                         CvVect64d     transVect1,
  563.                         CvMatr64d     camMatr2,
  564.                         CvMatr64d     rotMatr2,
  565.                         CvVect64d     transVect2,
  566.                         CvSize*       warpSize,
  567.                         double quad1[4][2],
  568.                         double quad2[4][2],
  569.                         CvMatr64d     fundMatr,
  570.                         CvPoint3D64f* epipole1,
  571.                         CvPoint3D64f* epipole2
  572.                         );
  573. CVAPI(void) icvGetQuadsTransformStruct(  CvStereoCamera* stereoCamera);
  574. CVAPI(void) icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera);
  575. CVAPI(void) icvGetCutPiece(   CvVect64d areaLineCoef1,CvVect64d areaLineCoef2,
  576.                     CvPoint2D64f epipole,
  577.                     CvSize imageSize,
  578.                     CvPoint2D64f* point11,CvPoint2D64f* point12,
  579.                     CvPoint2D64f* point21,CvPoint2D64f* point22,
  580.                     int* result);
  581. CVAPI(void) icvGetMiddleAnglePoint(   CvPoint2D64f basePoint,
  582.                             CvPoint2D64f point1,CvPoint2D64f point2,
  583.                             CvPoint2D64f* midPoint);
  584. CVAPI(void) icvGetNormalDirect(CvVect64d direct,CvPoint2D64f point,CvVect64d normDirect);
  585. CVAPI(double) icvGetVect(CvPoint2D64f basePoint,CvPoint2D64f point1,CvPoint2D64f point2);
  586. CVAPI(void) icvProjectPointToDirect(  CvPoint2D64f point,CvVect64d lineCoeff,
  587.                             CvPoint2D64f* projectPoint);
  588. CVAPI(void) icvGetDistanceFromPointToDirect( CvPoint2D64f point,CvVect64d lineCoef,double*dist);
  589. CVAPI(IplImage*) icvCreateIsometricImage( IplImage* src, IplImage* dst,
  590.                               int desired_depth, int desired_num_channels );
  591. CVAPI(void) cvDeInterlace( const CvArr* frame, CvArr* fieldEven, CvArr* fieldOdd );
  592. /*CVAPI(int) icvSelectBestRt(           int           numImages,
  593.                                     int*          numPoints,
  594.                                     CvSize        imageSize,
  595.                                     CvPoint2D32f* imagePoints1,
  596.                                     CvPoint2D32f* imagePoints2,
  597.                                     CvPoint3D32f* objectPoints,
  598.                                     CvMatr32f     cameraMatrix1,
  599.                                     CvVect32f     distortion1,
  600.                                     CvMatr32f     rotMatrs1,
  601.                                     CvVect32f     transVects1,
  602.                                     CvMatr32f     cameraMatrix2,
  603.                                     CvVect32f     distortion2,
  604.                                     CvMatr32f     rotMatrs2,
  605.                                     CvVect32f     transVects2,
  606.                                     CvMatr32f     bestRotMatr,
  607.                                     CvVect32f     bestTransVect
  608.                                     );*/
  609. /****************************************************************************************
  610. *                                   Contour Morphing                                     *
  611. ****************************************************************************************/
  612. /* finds correspondence between two contours */
  613. CvSeq* cvCalcContoursCorrespondence( const CvSeq* contour1,
  614.                                      const CvSeq* contour2, 
  615.                                      CvMemStorage* storage);
  616. /* morphs contours using the pre-calculated correspondence:
  617.    alpha=0 ~ contour1, alpha=1 ~ contour2 */
  618. CvSeq* cvMorphContours( const CvSeq* contour1, const CvSeq* contour2,
  619.                         CvSeq* corr, double alpha,
  620.                         CvMemStorage* storage );
  621. /****************************************************************************************
  622. *                                    Texture Descriptors                                 *
  623. ****************************************************************************************/
  624. #define CV_GLCM_OPTIMIZATION_NONE                   -2
  625. #define CV_GLCM_OPTIMIZATION_LUT                    -1
  626. #define CV_GLCM_OPTIMIZATION_HISTOGRAM              0
  627. #define CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST    10
  628. #define CV_GLCMDESC_OPTIMIZATION_ALLOWTRIPLENEST    11
  629. #define CV_GLCMDESC_OPTIMIZATION_HISTOGRAM          4
  630. #define CV_GLCMDESC_ENTROPY                         0
  631. #define CV_GLCMDESC_ENERGY                          1
  632. #define CV_GLCMDESC_HOMOGENITY                      2
  633. #define CV_GLCMDESC_CONTRAST                        3
  634. #define CV_GLCMDESC_CLUSTERTENDENCY                 4
  635. #define CV_GLCMDESC_CLUSTERSHADE                    5
  636. #define CV_GLCMDESC_CORRELATION                     6
  637. #define CV_GLCMDESC_CORRELATIONINFO1                7
  638. #define CV_GLCMDESC_CORRELATIONINFO2                8
  639. #define CV_GLCMDESC_MAXIMUMPROBABILITY              9
  640. #define CV_GLCM_ALL                                 0
  641. #define CV_GLCM_GLCM                                1
  642. #define CV_GLCM_DESC                                2
  643. typedef struct CvGLCM CvGLCM;
  644. CVAPI(CvGLCM*) cvCreateGLCM( const IplImage* srcImage,
  645.                                 int stepMagnitude,
  646.                                 const int* stepDirections CV_DEFAULT(0),
  647.                                 int numStepDirections CV_DEFAULT(0),
  648.                                 int optimizationType CV_DEFAULT(CV_GLCM_OPTIMIZATION_NONE));
  649. CVAPI(void) cvReleaseGLCM( CvGLCM** GLCM, int flag CV_DEFAULT(CV_GLCM_ALL));
  650. CVAPI(void) cvCreateGLCMDescriptors( CvGLCM* destGLCM,
  651.                                         int descriptorOptimizationType
  652.                                         CV_DEFAULT(CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST));
  653. CVAPI(double) cvGetGLCMDescriptor( CvGLCM* GLCM, int step, int descriptor );
  654. CVAPI(void) cvGetGLCMDescriptorStatistics( CvGLCM* GLCM, int descriptor,
  655.                                               double* average, double* standardDeviation );
  656. CVAPI(IplImage*) cvCreateGLCMImage( CvGLCM* GLCM, int step );
  657. /****************************************************************************************
  658. *                                  Face eyes&mouth tracking                              *
  659. ****************************************************************************************/
  660. typedef struct CvFaceTracker CvFaceTracker;
  661. #define CV_NUM_FACE_ELEMENTS    3 
  662. enum CV_FACE_ELEMENTS
  663. {
  664.     CV_FACE_MOUTH = 0,
  665.     CV_FACE_LEFT_EYE = 1,
  666.     CV_FACE_RIGHT_EYE = 2
  667. };
  668. CVAPI(CvFaceTracker*) cvInitFaceTracker(CvFaceTracker* pFaceTracking, const IplImage* imgGray,
  669.                                                 CvRect* pRects, int nRects);
  670. CVAPI(int) cvTrackFace( CvFaceTracker* pFaceTracker, IplImage* imgGray,
  671.                               CvRect* pRects, int nRects,
  672.                               CvPoint* ptRotate, double* dbAngleRotate);
  673. CVAPI(void) cvReleaseFaceTracker(CvFaceTracker** ppFaceTracker);
  674. typedef struct CvFace
  675. {
  676.     CvRect MouthRect;
  677.     CvRect LeftEyeRect;
  678.     CvRect RightEyeRect;
  679. } CvFaceData;
  680. CvSeq * cvFindFace(IplImage * Image,CvMemStorage* storage);
  681. CvSeq * cvPostBoostingFindFace(IplImage * Image,CvMemStorage* storage);
  682. /****************************************************************************************
  683. *                                         3D Tracker                                     *
  684. ****************************************************************************************/
  685. typedef unsigned char CvBool;
  686. typedef struct
  687. {
  688.     int id;
  689.     CvPoint2D32f p; // pgruebele: So we do not loose precision, this needs to be float
  690. } Cv3dTracker2dTrackedObject;
  691. CV_INLINE Cv3dTracker2dTrackedObject cv3dTracker2dTrackedObject(int id, CvPoint2D32f p)
  692. {
  693.     Cv3dTracker2dTrackedObject r;
  694.     r.id = id;
  695.     r.p = p;
  696.     return r;
  697. }
  698. typedef struct
  699. {
  700.     int id;
  701.     CvPoint3D32f p;             // location of the tracked object
  702. } Cv3dTrackerTrackedObject;
  703. CV_INLINE Cv3dTrackerTrackedObject cv3dTrackerTrackedObject(int id, CvPoint3D32f p)
  704. {
  705.     Cv3dTrackerTrackedObject r;
  706.     r.id = id;
  707.     r.p = p;
  708.     return r;
  709. }
  710. typedef struct
  711. {
  712.     CvBool valid;
  713.     float mat[4][4];              /* maps camera coordinates to world coordinates */
  714.     CvPoint2D32f principal_point; /* copied from intrinsics so this structure */
  715.                                   /* has all the info we need */
  716. } Cv3dTrackerCameraInfo;
  717. typedef struct
  718. {
  719.     CvPoint2D32f principal_point;
  720.     float focal_length[2];
  721.     float distortion[4];
  722. } Cv3dTrackerCameraIntrinsics;
  723. CVAPI(CvBool) cv3dTrackerCalibrateCameras(int num_cameras,
  724.                      const Cv3dTrackerCameraIntrinsics camera_intrinsics[], /* size is num_cameras */
  725.                      CvSize etalon_size,
  726.                      float square_size,
  727.                      IplImage *samples[],                                   /* size is num_cameras */
  728.                      Cv3dTrackerCameraInfo camera_info[]);                  /* size is num_cameras */
  729. CVAPI(int)  cv3dTrackerLocateObjects(int num_cameras, int num_objects,
  730.                    const Cv3dTrackerCameraInfo camera_info[],        /* size is num_cameras */
  731.                    const Cv3dTracker2dTrackedObject tracking_info[], /* size is num_objects*num_cameras */
  732.                    Cv3dTrackerTrackedObject tracked_objects[]);      /* size is num_objects */
  733. /****************************************************************************************
  734.  tracking_info is a rectangular array; one row per camera, num_objects elements per row.
  735.  The id field of any unused slots must be -1. Ids need not be ordered or consecutive. On
  736.  completion, the return value is the number of objects located; i.e., the number of objects
  737.  visible by more than one camera. The id field of any unused slots in tracked objects is
  738.  set to -1.
  739. ****************************************************************************************/
  740. /****************************************************************************************
  741. *                           Skeletons and Linear-Contour Models                          *
  742. ****************************************************************************************/
  743. typedef enum CvLeeParameters
  744. {
  745.     CV_LEE_INT = 0,
  746.     CV_LEE_FLOAT = 1,
  747.     CV_LEE_DOUBLE = 2,
  748.     CV_LEE_AUTO = -1,
  749.     CV_LEE_ERODE = 0,
  750.     CV_LEE_ZOOM = 1,
  751.     CV_LEE_NON = 2
  752. } CvLeeParameters;
  753. #define CV_NEXT_VORONOISITE2D( SITE ) ((SITE)->edge[0]->site[((SITE)->edge[0]->site[0] == (SITE))])
  754. #define CV_PREV_VORONOISITE2D( SITE ) ((SITE)->edge[1]->site[((SITE)->edge[1]->site[0] == (SITE))])
  755. #define CV_FIRST_VORONOIEDGE2D( SITE ) ((SITE)->edge[0])
  756. #define CV_LAST_VORONOIEDGE2D( SITE ) ((SITE)->edge[1])
  757. #define CV_NEXT_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[(EDGE)->site[0] != (SITE)])
  758. #define CV_PREV_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[2 + ((EDGE)->site[0] != (SITE))])
  759. #define CV_VORONOIEDGE2D_BEGINNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] != (SITE))])
  760. #define CV_VORONOIEDGE2D_ENDNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] == (SITE))])
  761. #define CV_TWIN_VORONOISITE2D( SITE, EDGE ) ( (EDGE)->site[((EDGE)->site[0] == (SITE))]) 
  762. #define CV_VORONOISITE2D_FIELDS()    
  763.     struct CvVoronoiNode2D *node[2]; 
  764.     struct CvVoronoiEdge2D *edge[2];
  765. typedef struct CvVoronoiSite2D
  766. {
  767.     CV_VORONOISITE2D_FIELDS()
  768.     struct CvVoronoiSite2D *next[2];
  769. } CvVoronoiSite2D;
  770. #define CV_VORONOIEDGE2D_FIELDS()    
  771.     struct CvVoronoiNode2D *node[2]; 
  772.     struct CvVoronoiSite2D *site[2]; 
  773.     struct CvVoronoiEdge2D *next[4];
  774. typedef struct CvVoronoiEdge2D
  775. {
  776.     CV_VORONOIEDGE2D_FIELDS()
  777. } CvVoronoiEdge2D;
  778. #define CV_VORONOINODE2D_FIELDS()       
  779.     CV_SET_ELEM_FIELDS(CvVoronoiNode2D) 
  780.     CvPoint2D32f pt;                    
  781.     float radius;
  782. typedef struct CvVoronoiNode2D
  783. {
  784.     CV_VORONOINODE2D_FIELDS()
  785. } CvVoronoiNode2D;
  786. #define CV_VORONOIDIAGRAM2D_FIELDS() 
  787.     CV_GRAPH_FIELDS()                
  788.     CvSet *sites;
  789. typedef struct CvVoronoiDiagram2D
  790. {
  791.     CV_VORONOIDIAGRAM2D_FIELDS()
  792. } CvVoronoiDiagram2D;
  793. /* Computes Voronoi Diagram for given polygons with holes */
  794. CVAPI(int)  cvVoronoiDiagramFromContour(CvSeq* ContourSeq,
  795.                                            CvVoronoiDiagram2D** VoronoiDiagram,
  796.                                            CvMemStorage* VoronoiStorage,
  797.                                            CvLeeParameters contour_type CV_DEFAULT(CV_LEE_INT),
  798.                                            int contour_orientation CV_DEFAULT(-1),
  799.                                            int attempt_number CV_DEFAULT(10));
  800. /* Computes Voronoi Diagram for domains in given image */
  801. CVAPI(int)  cvVoronoiDiagramFromImage(IplImage* pImage,
  802.                                          CvSeq** ContourSeq,
  803.                                          CvVoronoiDiagram2D** VoronoiDiagram,
  804.                                          CvMemStorage* VoronoiStorage,
  805.                                          CvLeeParameters regularization_method CV_DEFAULT(CV_LEE_NON),
  806.                                          float approx_precision CV_DEFAULT(CV_LEE_AUTO));
  807. /* Deallocates the storage */
  808. CVAPI(void) cvReleaseVoronoiStorage(CvVoronoiDiagram2D* VoronoiDiagram,
  809.                                           CvMemStorage** pVoronoiStorage);
  810. /*********************** Linear-Contour Model ****************************/
  811. struct CvLCMEdge;
  812. struct CvLCMNode;
  813. typedef struct CvLCMEdge
  814. {
  815.     CV_GRAPH_EDGE_FIELDS() 
  816.     CvSeq* chain;
  817.     float width;
  818.     int index1;
  819.     int index2;
  820. } CvLCMEdge;
  821. typedef struct CvLCMNode
  822. {
  823.     CV_GRAPH_VERTEX_FIELDS()
  824.     CvContour* contour; 
  825. } CvLCMNode;
  826. /* Computes hybrid model from Voronoi Diagram */
  827. CVAPI(CvGraph*) cvLinearContorModelFromVoronoiDiagram(CvVoronoiDiagram2D* VoronoiDiagram,
  828.                                                          float maxWidth);
  829. /* Releases hybrid model storage */
  830. CVAPI(int) cvReleaseLinearContorModelStorage(CvGraph** Graph);
  831. /* two stereo-related functions */
  832. CVAPI(void) cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f vertex[4], double matrix[3][3],
  833.                                               CvArr* rectMap );
  834. /*CVAPI(void) cvInitStereoRectification( CvStereoCamera* params,
  835.                                              CvArr* rectMap1, CvArr* rectMap2,
  836.                                              int do_undistortion );*/
  837. /*************************** View Morphing Functions ************************/
  838. /* The order of the function corresponds to the order they should appear in
  839.    the view morphing pipeline */ 
  840. /* Finds ending points of scanlines on left and right images of stereo-pair */
  841. CVAPI(void)  cvMakeScanlines( const CvMatrix3* matrix, CvSize  img_size,
  842.                               int*  scanlines1, int*  scanlines2,
  843.                               int*  lengths1, int*  lengths2,
  844.                               int*  line_count );
  845. /* Grab pixel values from scanlines and stores them sequentially
  846.    (some sort of perspective image transform) */
  847. CVAPI(void)  cvPreWarpImage( int       line_count,
  848.                              IplImage* img,
  849.                              uchar*    dst,
  850.                              int*      dst_nums,
  851.                              int*      scanlines);
  852. /* Approximate each grabbed scanline by a sequence of runs
  853.    (lossy run-length compression) */
  854. CVAPI(void)  cvFindRuns( int    line_count,
  855.                          uchar* prewarp1,
  856.                          uchar* prewarp2,
  857.                          int*   line_lengths1,
  858.                          int*   line_lengths2,
  859.                          int*   runs1,
  860.                          int*   runs2,
  861.                          int*   num_runs1,
  862.                          int*   num_runs2);
  863. /* Compares two sets of compressed scanlines */
  864. CVAPI(void)  cvDynamicCorrespondMulti( int  line_count,
  865.                                        int* first,
  866.                                        int* first_runs,
  867.                                        int* second,
  868.                                        int* second_runs,
  869.                                        int* first_corr,
  870.                                        int* second_corr);
  871. /* Finds scanline ending coordinates for some intermediate "virtual" camera position */
  872. CVAPI(void)  cvMakeAlphaScanlines( int*  scanlines1,
  873.                                    int*  scanlines2,
  874.                                    int*  scanlinesA,
  875.                                    int*  lengths,
  876.                                    int   line_count,
  877.                                    float alpha);
  878. /* Blends data of the left and right image scanlines to get
  879.    pixel values of "virtual" image scanlines */
  880. CVAPI(void)  cvMorphEpilinesMulti( int    line_count,
  881.                                    uchar* first_pix,
  882.                                    int*   first_num,
  883.                                    uchar* second_pix,
  884.                                    int*   second_num,
  885.                                    uchar* dst_pix,
  886.                                    int*   dst_num,
  887.                                    float  alpha,
  888.                                    int*   first,
  889.                                    int*   first_runs,
  890.                                    int*   second,
  891.                                    int*   second_runs,
  892.                                    int*   first_corr,
  893.                                    int*   second_corr);
  894. /* Does reverse warping of the morphing result to make
  895.    it fill the destination image rectangle */
  896. CVAPI(void)  cvPostWarpImage( int       line_count,
  897.                               uchar*    src,
  898.                               int*      src_nums,
  899.                               IplImage* img,
  900.                               int*      scanlines);
  901. /* Deletes Moire (missed pixels that appear due to discretization) */
  902. CVAPI(void)  cvDeleteMoire( IplImage*  img );
  903. /****************************************************************************************
  904. *                           Background/foreground segmentation                           *
  905. ****************************************************************************************/
  906. /* We discriminate between foreground and background pixels
  907.  * by building and maintaining a model of the background.
  908.  * Any pixel which does not fit this model is then deemed
  909.  * to be foreground.
  910.  *
  911.  * At present we support two core background models,
  912.  * one of which has two variations:
  913.  *
  914.  *  o CV_BG_MODEL_FGD: latest and greatest algorithm, described in
  915.  *    
  916.  *  Foreground Object Detection from Videos Containing Complex Background.
  917.  *  Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. 
  918.  *  ACM MM2003 9p
  919.  *
  920.  *  o CV_BG_MODEL_FGD_SIMPLE:
  921.  *       A code comment describes this as a simplified version of the above,
  922.  *       but the code is in fact currently identical
  923.  *
  924.  *  o CV_BG_MODEL_MOG: "Mixture of Gaussians", older algorithm, described in
  925.  *
  926.  *       Moving target classification and tracking from real-time video.
  927.  *       A Lipton, H Fujijoshi, R Patil
  928.  *       Proceedings IEEE Workshop on Application of Computer Vision pp 8-14 1998
  929.  *
  930.  *       Learning patterns of activity using real-time tracking
  931.  *       C Stauffer and W Grimson  August 2000
  932.  *       IEEE Transactions on Pattern Analysis and Machine Intelligence 22(8):747-757
  933.  */
  934. #define CV_BG_MODEL_FGD 0
  935. #define CV_BG_MODEL_MOG 1 /* "Mixture of Gaussians". */
  936. #define CV_BG_MODEL_FGD_SIMPLE 2
  937. struct CvBGStatModel;
  938. typedef void (CV_CDECL * CvReleaseBGStatModel)( struct CvBGStatModel** bg_model );
  939. typedef int (CV_CDECL * CvUpdateBGStatModel)( IplImage* curr_frame, struct CvBGStatModel* bg_model );
  940. #define CV_BG_STAT_MODEL_FIELDS()                                                   
  941.     int             type; /*type of BG model*/                                      
  942.     CvReleaseBGStatModel release;                                                   
  943.     CvUpdateBGStatModel update;                                                     
  944.     IplImage*       background;   /*8UC3 reference background image*/               
  945.     IplImage*       foreground;   /*8UC1 foreground image*/                         
  946.     IplImage**      layers;       /*8UC3 reference background image, can be null */ 
  947.     int             layer_count;  /* can be zero */                                 
  948.     CvMemStorage*   storage;      /*storage for foreground_regions*/                
  949.     CvSeq*          foreground_regions /*foreground object contours*/
  950. typedef struct CvBGStatModel
  951. {
  952.     CV_BG_STAT_MODEL_FIELDS();
  953. }
  954. CvBGStatModel;
  955. // 
  956. // Releases memory used by BGStatModel
  957. CV_INLINE void cvReleaseBGStatModel( CvBGStatModel** bg_model )
  958. {
  959.     if( bg_model && *bg_model && (*bg_model)->release )
  960.         (*bg_model)->release( bg_model );
  961. }
  962. // Updates statistical model and returns number of found foreground regions
  963. CV_INLINE int cvUpdateBGStatModel( IplImage* current_frame, CvBGStatModel*  bg_model )
  964. {
  965.     return bg_model && bg_model->update ? bg_model->update( current_frame, bg_model ) : 0;
  966. }
  967. // Performs FG post-processing using segmentation
  968. // (all pixels of a region will be classified as foreground if majority of pixels of the region are FG).
  969. // parameters:
  970. //      segments - pointer to result of segmentation (for example MeanShiftSegmentation)
  971. //      bg_model - pointer to CvBGStatModel structure
  972. CVAPI(void) cvRefineForegroundMaskBySegm( CvSeq* segments, CvBGStatModel*  bg_model );
  973. /* Common use change detection function */
  974. CVAPI(int)  cvChangeDetection( IplImage*  prev_frame,
  975.                                IplImage*  curr_frame,
  976.                                IplImage*  change_mask );
  977. /*
  978.   Interface of ACM MM2003 algorithm
  979. */
  980. /* Default parameters of foreground detection algorithm: */
  981. #define  CV_BGFG_FGD_LC              128
  982. #define  CV_BGFG_FGD_N1C             15
  983. #define  CV_BGFG_FGD_N2C             25
  984. #define  CV_BGFG_FGD_LCC             64
  985. #define  CV_BGFG_FGD_N1CC            25
  986. #define  CV_BGFG_FGD_N2CC            40
  987. /* Background reference image update parameter: */
  988. #define  CV_BGFG_FGD_ALPHA_1         0.1f
  989. /* stat model update parameter
  990.  * 0.002f ~ 1K frame(~45sec), 0.005 ~ 18sec (if 25fps and absolutely static BG)
  991.  */
  992. #define  CV_BGFG_FGD_ALPHA_2         0.005f
  993. /* start value for alpha parameter (to fast initiate statistic model) */
  994. #define  CV_BGFG_FGD_ALPHA_3         0.1f
  995. #define  CV_BGFG_FGD_DELTA           2
  996. #define  CV_BGFG_FGD_T               0.9f
  997. #define  CV_BGFG_FGD_MINAREA         15.f
  998. #define  CV_BGFG_FGD_BG_UPDATE_TRESH 0.5f
  999. /* See the above-referenced Li/Huang/Gu/Tian paper
  1000.  * for a full description of these background-model
  1001.  * tuning parameters.
  1002.  *
  1003.  * Nomenclature:  'c'  == "color", a three-component red/green/blue vector.
  1004.  *                         We use histograms of these to model the range of
  1005.  *                         colors we've seen at a given background pixel.
  1006.  *
  1007.  *                'cc' == "color co-occurrence", a six-component vector giving
  1008.  *                         RGB color for both this frame and preceding frame.
  1009.  *                             We use histograms of these to model the range of
  1010.  *                         color CHANGES we've seen at a given background pixel.
  1011.  */
  1012. typedef struct CvFGDStatModelParams
  1013. {
  1014.     int    Lc; /* Quantized levels per 'color' component. Power of two, typically 32, 64 or 128. */
  1015.     int    N1c; /* Number of color vectors used to model normal background color variation at a given pixel. */
  1016.     int    N2c; /* Number of color vectors retained at given pixel.  Must be > N1c, typically ~ 5/3 of N1c. */
  1017. /* Used to allow the first N1c vectors to adapt over time to changing background. */
  1018.     int    Lcc; /* Quantized levels per 'color co-occurrence' component.  Power of two, typically 16, 32 or 64. */
  1019.     int    N1cc; /* Number of color co-occurrence vectors used to model normal background color variation at a given pixel. */
  1020.     int    N2cc; /* Number of color co-occurrence vectors retained at given pixel.  Must be > N1cc, typically ~ 5/3 of N1cc. */
  1021. /* Used to allow the first N1cc vectors to adapt over time to changing background. */
  1022.     int    is_obj_without_holes;/* If TRUE we ignore holes within foreground blobs. Defaults to TRUE. */
  1023.     int    perform_morphing; /* Number of erode-dilate-erode foreground-blob cleanup iterations. */
  1024. /* These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1. */
  1025.     float  alpha1; /* How quickly we forget old background pixel values seen.  Typically set to 0.1   */
  1026.     float  alpha2; /* "Controls speed of feature learning". Depends on T. Typical value circa 0.005.  */
  1027.     float  alpha3; /* Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1. */
  1028.     float  delta; /* Affects color and color co-occurrence quantization, typically set to 2. */
  1029.     float  T; /* "A percentage value which determines when new features can be recognized as new background." (Typically 0.9).*/
  1030.     float  minArea; /* Discard foreground blobs whose bounding box is smaller than this threshold. */
  1031. }
  1032. CvFGDStatModelParams;
  1033. typedef struct CvBGPixelCStatTable
  1034. {
  1035.     float          Pv, Pvb;
  1036.     uchar          v[3];
  1037. }
  1038. CvBGPixelCStatTable;
  1039. typedef struct CvBGPixelCCStatTable
  1040. {
  1041.     float          Pv, Pvb;
  1042.     uchar          v[6];
  1043. }
  1044. CvBGPixelCCStatTable;
  1045. typedef struct CvBGPixelStat
  1046. {
  1047.     float                 Pbc;
  1048.     float                 Pbcc;
  1049.     CvBGPixelCStatTable*  ctable;
  1050.     CvBGPixelCCStatTable* cctable;
  1051.     uchar                 is_trained_st_model;
  1052.     uchar                 is_trained_dyn_model;
  1053. }
  1054. CvBGPixelStat;
  1055. typedef struct CvFGDStatModel
  1056. {
  1057.     CV_BG_STAT_MODEL_FIELDS();
  1058.     CvBGPixelStat*         pixel_stat;
  1059.     IplImage*              Ftd;
  1060.     IplImage*              Fbd;
  1061.     IplImage*              prev_frame;
  1062.     CvFGDStatModelParams   params;
  1063. }
  1064. CvFGDStatModel;
  1065. /* Creates FGD model */
  1066. CVAPI(CvBGStatModel*) cvCreateFGDStatModel( IplImage* first_frame,
  1067.                     CvFGDStatModelParams* parameters CV_DEFAULT(NULL));
  1068. /* 
  1069.    Interface of Gaussian mixture algorithm
  1070.    "An improved adaptive background mixture model for real-time tracking with shadow detection"
  1071.    P. KadewTraKuPong and R. Bowden,
  1072.    Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001."
  1073.    http://personal.ee.surrey.ac.uk/Personal/R.Bowden/publications/avbs01/avbs01.pdf
  1074. */
  1075. /* Note:  "MOG" == "Mixture Of Gaussians": */
  1076. #define CV_BGFG_MOG_MAX_NGAUSSIANS 500
  1077. /* default parameters of gaussian background detection algorithm */
  1078. #define CV_BGFG_MOG_BACKGROUND_THRESHOLD     0.7     /* threshold sum of weights for background test */
  1079. #define CV_BGFG_MOG_STD_THRESHOLD            2.5     /* lambda=2.5 is 99% */
  1080. #define CV_BGFG_MOG_WINDOW_SIZE              200     /* Learning rate; alpha = 1/CV_GBG_WINDOW_SIZE */
  1081. #define CV_BGFG_MOG_NGAUSSIANS               5       /* = K = number of Gaussians in mixture */
  1082. #define CV_BGFG_MOG_WEIGHT_INIT              0.05
  1083. #define CV_BGFG_MOG_SIGMA_INIT               30
  1084. #define CV_BGFG_MOG_MINAREA                  15.f
  1085. #define CV_BGFG_MOG_NCOLORS                  3
  1086. typedef struct CvGaussBGStatModelParams
  1087. {    
  1088.     int     win_size;               /* = 1/alpha */
  1089.     int     n_gauss;
  1090.     double  bg_threshold, std_threshold, minArea;
  1091.     double  weight_init, variance_init;
  1092. }CvGaussBGStatModelParams;
  1093. typedef struct CvGaussBGValues
  1094. {
  1095.     int         match_sum;
  1096.     double      weight;
  1097.     double      variance[CV_BGFG_MOG_NCOLORS];
  1098.     double      mean[CV_BGFG_MOG_NCOLORS];
  1099. }
  1100. CvGaussBGValues;
  1101. typedef struct CvGaussBGPoint
  1102. {
  1103.     CvGaussBGValues* g_values;
  1104. }
  1105. CvGaussBGPoint;
  1106. typedef struct CvGaussBGModel
  1107. {
  1108.     CV_BG_STAT_MODEL_FIELDS();
  1109.     CvGaussBGStatModelParams   params;    
  1110.     CvGaussBGPoint*            g_point;    
  1111.     int                        countFrames;
  1112. }
  1113. CvGaussBGModel;
  1114. /* Creates Gaussian mixture background model */
  1115. CVAPI(CvBGStatModel*) cvCreateGaussianBGModel( IplImage* first_frame,
  1116.                 CvGaussBGStatModelParams* parameters CV_DEFAULT(NULL));
  1117. typedef struct CvBGCodeBookElem
  1118. {
  1119.     struct CvBGCodeBookElem* next;
  1120.     int tLastUpdate;
  1121.     int stale;
  1122.     uchar boxMin[3];
  1123.     uchar boxMax[3];
  1124.     uchar learnMin[3];
  1125.     uchar learnMax[3];
  1126. }
  1127. CvBGCodeBookElem;
  1128. typedef struct CvBGCodeBookModel
  1129. {
  1130.     CvSize size;
  1131.     int t;
  1132.     uchar cbBounds[3];
  1133.     uchar modMin[3];
  1134.     uchar modMax[3];
  1135.     CvBGCodeBookElem** cbmap;
  1136.     CvMemStorage* storage;
  1137.     CvBGCodeBookElem* freeList;
  1138. }
  1139. CvBGCodeBookModel;
  1140. CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel();
  1141. CVAPI(void) cvReleaseBGCodeBookModel( CvBGCodeBookModel** model );
  1142. CVAPI(void) cvBGCodeBookUpdate( CvBGCodeBookModel* model, const CvArr* image,
  1143.                                 CvRect roi CV_DEFAULT(cvRect(0,0,0,0)),
  1144.                                 const CvArr* mask CV_DEFAULT(0) );
  1145. CVAPI(int) cvBGCodeBookDiff( const CvBGCodeBookModel* model, const CvArr* image,
  1146.                              CvArr* fgmask, CvRect roi CV_DEFAULT(cvRect(0,0,0,0)) );
  1147. CVAPI(void) cvBGCodeBookClearStale( CvBGCodeBookModel* model, int staleThresh,
  1148.                                     CvRect roi CV_DEFAULT(cvRect(0,0,0,0)),
  1149.                                     const CvArr* mask CV_DEFAULT(0) );
  1150. CVAPI(CvSeq*) cvSegmentFGMask( CvArr *fgmask, int poly1Hull0 CV_DEFAULT(1),
  1151.                                float perimScale CV_DEFAULT(4.f),
  1152.                                CvMemStorage* storage CV_DEFAULT(0),
  1153.                                CvPoint offset CV_DEFAULT(cvPoint(0,0)));
  1154. #ifdef __cplusplus
  1155. }
  1156. #endif
  1157. #ifdef __cplusplus
  1158. /****************************************************************************************
  1159. *                                   Calibration engine                                   *
  1160. ****************************************************************************************/
  1161. typedef enum CvCalibEtalonType
  1162. {
  1163.     CV_CALIB_ETALON_USER = -1,
  1164.     CV_CALIB_ETALON_CHESSBOARD = 0,
  1165.     CV_CALIB_ETALON_CHECKERBOARD = CV_CALIB_ETALON_CHESSBOARD
  1166. }
  1167. CvCalibEtalonType;
  1168. class CV_EXPORTS CvCalibFilter
  1169. {
  1170. public:
  1171.     /* Constructor & destructor */
  1172.     CvCalibFilter();
  1173.     virtual ~CvCalibFilter();
  1174.     /* Sets etalon type - one for all cameras.
  1175.        etalonParams is used in case of pre-defined etalons (such as chessboard).
  1176.        Number of elements in etalonParams is determined by etalonType.
  1177.        E.g., if etalon type is CV_ETALON_TYPE_CHESSBOARD then:
  1178.          etalonParams[0] is number of squares per one side of etalon
  1179.          etalonParams[1] is number of squares per another side of etalon
  1180.          etalonParams[2] is linear size of squares in the board in arbitrary units.
  1181.        pointCount & points are used in case of
  1182.        CV_CALIB_ETALON_USER (user-defined) etalon. */
  1183.     virtual bool
  1184.         SetEtalon( CvCalibEtalonType etalonType, double* etalonParams,
  1185.                    int pointCount = 0, CvPoint2D32f* points = 0 );
  1186.     /* Retrieves etalon parameters/or and points */
  1187.     virtual CvCalibEtalonType
  1188.         GetEtalon( int* paramCount = 0, const double** etalonParams = 0,
  1189.                    int* pointCount = 0, const CvPoint2D32f** etalonPoints = 0 ) const;
  1190.     /* Sets number of cameras calibrated simultaneously. It is equal to 1 initially */
  1191.     virtual void SetCameraCount( int cameraCount );
  1192.     /* Retrieves number of cameras */
  1193.     int GetCameraCount() const { return cameraCount; }
  1194.     /* Starts cameras calibration */
  1195.     virtual bool SetFrames( int totalFrames );
  1196.     
  1197.     /* Stops cameras calibration */
  1198.     virtual void Stop( bool calibrate = false );
  1199.     /* Retrieves number of cameras */
  1200.     bool IsCalibrated() const { return isCalibrated; }
  1201.     /* Feeds another serie of snapshots (one per each camera) to filter.
  1202.        Etalon points on these images are found automatically.
  1203.        If the function can't locate points, it returns false */
  1204.     virtual bool FindEtalon( IplImage** imgs );
  1205.     /* The same but takes matrices */
  1206.     virtual bool FindEtalon( CvMat** imgs );
  1207.     /* Lower-level function for feeding filter with already found etalon points.
  1208.        Array of point arrays for each camera is passed. */
  1209.     virtual bool Push( const CvPoint2D32f** points = 0 );
  1210.     /* Returns total number of accepted frames and, optionally,
  1211.        total number of frames to collect */
  1212.     virtual int GetFrameCount( int* framesTotal = 0 ) const;
  1213.     /* Retrieves camera parameters for specified camera.
  1214.        If camera is not calibrated the function returns 0 */
  1215.     virtual const CvCamera* GetCameraParams( int idx = 0 ) const;
  1216.     virtual const CvStereoCamera* GetStereoParams() const;
  1217.     /* Sets camera parameters for all cameras */
  1218.     virtual bool SetCameraParams( CvCamera* params );
  1219.     /* Saves all camera parameters to file */
  1220.     virtual bool SaveCameraParams( const char* filename );
  1221.     
  1222.     /* Loads all camera parameters from file */
  1223.     virtual bool LoadCameraParams( const char* filename );
  1224.     /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
  1225.     virtual bool Undistort( IplImage** src, IplImage** dst );
  1226.     /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
  1227.     virtual bool Undistort( CvMat** src, CvMat** dst );
  1228.     /* Returns array of etalon points detected/partally detected
  1229.        on the latest frame for idx-th camera */
  1230.     virtual bool GetLatestPoints( int idx, CvPoint2D32f** pts,
  1231.                                                   int* count, bool* found );
  1232.     /* Draw the latest detected/partially detected etalon */
  1233.     virtual void DrawPoints( IplImage** dst );
  1234.     /* Draw the latest detected/partially detected etalon */
  1235.     virtual void DrawPoints( CvMat** dst );
  1236.     virtual bool Rectify( IplImage** srcarr, IplImage** dstarr );
  1237.     virtual bool Rectify( CvMat** srcarr, CvMat** dstarr );
  1238. protected:
  1239.     enum { MAX_CAMERAS = 3 };
  1240.     /* etalon data */
  1241.     CvCalibEtalonType  etalonType;
  1242.     int     etalonParamCount;
  1243.     double* etalonParams;
  1244.     int     etalonPointCount;
  1245.     CvPoint2D32f* etalonPoints;
  1246.     CvSize  imgSize;
  1247.     CvMat*  grayImg;
  1248.     CvMat*  tempImg;
  1249.     CvMemStorage* storage;
  1250.     /* camera data */
  1251.     int     cameraCount;
  1252.     CvCamera cameraParams[MAX_CAMERAS];
  1253.     CvStereoCamera stereo;
  1254.     CvPoint2D32f* points[MAX_CAMERAS];
  1255.     CvMat*  undistMap[MAX_CAMERAS][2];
  1256.     CvMat*  undistImg;
  1257.     int     latestCounts[MAX_CAMERAS];
  1258.     CvPoint2D32f* latestPoints[MAX_CAMERAS];
  1259.     CvMat*  rectMap[MAX_CAMERAS][2];
  1260.     /* Added by Valery */
  1261.     //CvStereoCamera stereoParams;
  1262.     int     maxPoints;
  1263.     int     framesTotal;
  1264.     int     framesAccepted;
  1265.     bool    isCalibrated;
  1266. };
  1267. #include "cvaux.hpp"
  1268. #include "cvvidsurv.hpp"
  1269. #endif
  1270. #endif
  1271. /* End of file. */