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_AUX_H__ 00043 #define __OPENCV_AUX_H__ 00044 00045 #include "cv.h" 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 CVAPI(CvSeq*) cvSegmentImage( const CvArr* srcarr, CvArr* dstarr, 00052 double canny_threshold, 00053 double ffill_threshold, 00054 CvMemStorage* storage ); 00055 00056 /****************************************************************************************\ 00057 * Eigen objects * 00058 \****************************************************************************************/ 00059 00060 typedef int (CV_CDECL * CvCallback)(int index, void* buffer, void* user_data); 00061 typedef union 00062 { 00063 CvCallback callback; 00064 void* data; 00065 } 00066 CvInput; 00067 00068 #define CV_EIGOBJ_NO_CALLBACK 0 00069 #define CV_EIGOBJ_INPUT_CALLBACK 1 00070 #define CV_EIGOBJ_OUTPUT_CALLBACK 2 00071 #define CV_EIGOBJ_BOTH_CALLBACK 3 00072 00073 /* Calculates covariation matrix of a set of arrays */ 00074 CVAPI(void) cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags, 00075 int ioBufSize, uchar* buffer, void* userData, 00076 IplImage* avg, float* covarMatrix ); 00077 00078 /* Calculates eigen values and vectors of covariation matrix of a set of 00079 arrays */ 00080 CVAPI(void) cvCalcEigenObjects( int nObjects, void* input, void* output, 00081 int ioFlags, int ioBufSize, void* userData, 00082 CvTermCriteria* calcLimit, IplImage* avg, 00083 float* eigVals ); 00084 00085 /* Calculates dot product (obj - avg) * eigObj (i.e. projects image to eigen vector) */ 00086 CVAPI(double) cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg ); 00087 00088 /* Projects image to eigen space (finds all decomposion coefficients */ 00089 CVAPI(void) cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput, 00090 int ioFlags, void* userData, IplImage* avg, 00091 float* coeffs ); 00092 00093 /* Projects original objects used to calculate eigen space basis to that space */ 00094 CVAPI(void) cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags, 00095 void* userData, float* coeffs, IplImage* avg, 00096 IplImage* proj ); 00097 00098 /****************************************************************************************\ 00099 * 1D/2D HMM * 00100 \****************************************************************************************/ 00101 00102 typedef struct CvImgObsInfo 00103 { 00104 int obs_x; 00105 int obs_y; 00106 int obs_size; 00107 float* obs;//consequtive observations 00108 00109 int* state;/* arr of pairs superstate/state to which observation belong */ 00110 int* mix; /* number of mixture to which observation belong */ 00111 00112 } 00113 CvImgObsInfo;/*struct for 1 image*/ 00114 00115 typedef CvImgObsInfo Cv1DObsInfo; 00116 00117 typedef struct CvEHMMState 00118 { 00119 int num_mix; /*number of mixtures in this state*/ 00120 float* mu; /*mean vectors corresponding to each mixture*/ 00121 float* inv_var; /* square root of inversed variances corresp. to each mixture*/ 00122 float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */ 00123 float* weight; /*array of mixture weights. Summ of all weights in state is 1. */ 00124 00125 } 00126 CvEHMMState; 00127 00128 typedef struct CvEHMM 00129 { 00130 int level; /* 0 - lowest(i.e its states are real states), ..... */ 00131 int num_states; /* number of HMM states */ 00132 float* transP;/*transition probab. matrices for states */ 00133 float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm 00134 if level == 1 - martix of matrices */ 00135 union 00136 { 00137 CvEHMMState* state; /* if level == 0 points to real states array, 00138 if not - points to embedded hmms */ 00139 struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */ 00140 } u; 00141 00142 } 00143 CvEHMM; 00144 00145 /*CVAPI(int) icvCreate1DHMM( CvEHMM** this_hmm, 00146 int state_number, int* num_mix, int obs_size ); 00147 00148 CVAPI(int) icvRelease1DHMM( CvEHMM** phmm ); 00149 00150 CVAPI(int) icvUniform1DSegm( Cv1DObsInfo* obs_info, CvEHMM* hmm ); 00151 00152 CVAPI(int) icvInit1DMixSegm( Cv1DObsInfo** obs_info_array, int num_img, CvEHMM* hmm); 00153 00154 CVAPI(int) icvEstimate1DHMMStateParams( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm); 00155 00156 CVAPI(int) icvEstimate1DObsProb( CvImgObsInfo* obs_info, CvEHMM* hmm ); 00157 00158 CVAPI(int) icvEstimate1DTransProb( Cv1DObsInfo** obs_info_array, 00159 int num_seq, 00160 CvEHMM* hmm ); 00161 00162 CVAPI(float) icvViterbi( Cv1DObsInfo* obs_info, CvEHMM* hmm); 00163 00164 CVAPI(int) icv1DMixSegmL2( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm );*/ 00165 00166 /*********************************** Embedded HMMs *************************************/ 00167 00168 /* Creates 2D HMM */ 00169 CVAPI(CvEHMM*) cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize ); 00170 00171 /* Releases HMM */ 00172 CVAPI(void) cvRelease2DHMM( CvEHMM** hmm ); 00173 00174 #define CV_COUNT_OBS(roi, win, delta, numObs ) \ 00175 { \ 00176 (numObs)->width =((roi)->width -(win)->width +(delta)->width)/(delta)->width; \ 00177 (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;\ 00178 } 00179 00180 /* Creates storage for observation vectors */ 00181 CVAPI(CvImgObsInfo*) cvCreateObsInfo( CvSize numObs, int obsSize ); 00182 00183 /* Releases storage for observation vectors */ 00184 CVAPI(void) cvReleaseObsInfo( CvImgObsInfo** obs_info ); 00185 00186 00187 /* The function takes an image on input and and returns the sequnce of observations 00188 to be used with an embedded HMM; Each observation is top-left block of DCT 00189 coefficient matrix */ 00190 CVAPI(void) cvImgToObs_DCT( const CvArr* arr, float* obs, CvSize dctSize, 00191 CvSize obsSize, CvSize delta ); 00192 00193 00194 /* Uniformly segments all observation vectors extracted from image */ 00195 CVAPI(void) cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm ); 00196 00197 /* Does mixture segmentation of the states of embedded HMM */ 00198 CVAPI(void) cvInitMixSegm( CvImgObsInfo** obs_info_array, 00199 int num_img, CvEHMM* hmm ); 00200 00201 /* Function calculates means, variances, weights of every Gaussian mixture 00202 of every low-level state of embedded HMM */ 00203 CVAPI(void) cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array, 00204 int num_img, CvEHMM* hmm ); 00205 00206 /* Function computes transition probability matrices of embedded HMM 00207 given observations segmentation */ 00208 CVAPI(void) cvEstimateTransProb( CvImgObsInfo** obs_info_array, 00209 int num_img, CvEHMM* hmm ); 00210 00211 /* Function computes probabilities of appearing observations at any state 00212 (i.e. computes P(obs|state) for every pair(obs,state)) */ 00213 CVAPI(void) cvEstimateObsProb( CvImgObsInfo* obs_info, 00214 CvEHMM* hmm ); 00215 00216 /* Runs Viterbi algorithm for embedded HMM */ 00217 CVAPI(float) cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm ); 00218 00219 00220 /* Function clusters observation vectors from several images 00221 given observations segmentation. 00222 Euclidean distance used for clustering vectors. 00223 Centers of clusters are given means of every mixture */ 00224 CVAPI(void) cvMixSegmL2( CvImgObsInfo** obs_info_array, 00225 int num_img, CvEHMM* hmm ); 00226 00227 /****************************************************************************************\ 00228 * A few functions from old stereo gesture recognition demosions * 00229 \****************************************************************************************/ 00230 00231 /* Creates hand mask image given several points on the hand */ 00232 CVAPI(void) cvCreateHandMask( CvSeq* hand_points, 00233 IplImage *img_mask, CvRect *roi); 00234 00235 /* Finds hand region in range image data */ 00236 CVAPI(void) cvFindHandRegion (CvPoint3D32f* points, int count, 00237 CvSeq* indexs, 00238 float* line, CvSize2D32f size, int flag, 00239 CvPoint3D32f* center, 00240 CvMemStorage* storage, CvSeq **numbers); 00241 00242 /* Finds hand region in range image data (advanced version) */ 00243 CVAPI(void) cvFindHandRegionA( CvPoint3D32f* points, int count, 00244 CvSeq* indexs, 00245 float* line, CvSize2D32f size, int jc, 00246 CvPoint3D32f* center, 00247 CvMemStorage* storage, CvSeq **numbers); 00248 00249 /* Calculates the cooficients of the homography matrix */ 00250 CVAPI(void) cvCalcImageHomography( float* line, CvPoint3D32f* center, 00251 float* intrinsic, float* homography ); 00252 00253 /****************************************************************************************\ 00254 * Additional operations on Subdivisions * 00255 \****************************************************************************************/ 00256 00257 // paints voronoi diagram: just demo function 00258 CVAPI(void) icvDrawMosaic( CvSubdiv2D* subdiv, IplImage* src, IplImage* dst ); 00259 00260 // checks planar subdivision for correctness. It is not an absolute check, 00261 // but it verifies some relations between quad-edges 00262 CVAPI(int) icvSubdiv2DCheck( CvSubdiv2D* subdiv ); 00263 00264 // returns squared distance between two 2D points with floating-point coordinates. 00265 CV_INLINE double icvSqDist2D32f( CvPoint2D32f pt1, CvPoint2D32f pt2 ) 00266 { 00267 double dx = pt1.x - pt2.x; 00268 double dy = pt1.y - pt2.y; 00269 00270 return dx*dx + dy*dy; 00271 } 00272 00273 00274 /****************************************************************************************\ 00275 * More operations on sequences * 00276 \****************************************************************************************/ 00277 00278 /*****************************************************************************************/ 00279 00280 #define CV_CURRENT_INT( reader ) (*((int *)(reader).ptr)) 00281 #define CV_PREV_INT( reader ) (*((int *)(reader).prev_elem)) 00282 00283 #define CV_GRAPH_WEIGHTED_VERTEX_FIELDS() CV_GRAPH_VERTEX_FIELDS()\ 00284 float weight; 00285 00286 #define CV_GRAPH_WEIGHTED_EDGE_FIELDS() CV_GRAPH_EDGE_FIELDS() 00287 00288 typedef struct CvGraphWeightedVtx 00289 { 00290 CV_GRAPH_WEIGHTED_VERTEX_FIELDS() 00291 } 00292 CvGraphWeightedVtx; 00293 00294 typedef struct CvGraphWeightedEdge 00295 { 00296 CV_GRAPH_WEIGHTED_EDGE_FIELDS() 00297 } 00298 CvGraphWeightedEdge; 00299 00300 typedef enum CvGraphWeightType 00301 { 00302 CV_NOT_WEIGHTED, 00303 CV_WEIGHTED_VTX, 00304 CV_WEIGHTED_EDGE, 00305 CV_WEIGHTED_ALL 00306 } CvGraphWeightType; 00307 00308 00309 /* Calculates histogram of a contour */ 00310 CVAPI(void) cvCalcPGH( const CvSeq* contour, CvHistogram* hist ); 00311 00312 #define CV_DOMINANT_IPAN 1 00313 00314 /* Finds high-curvature points of the contour */ 00315 CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage, 00316 int method CV_DEFAULT(CV_DOMINANT_IPAN), 00317 double parameter1 CV_DEFAULT(0), 00318 double parameter2 CV_DEFAULT(0), 00319 double parameter3 CV_DEFAULT(0), 00320 double parameter4 CV_DEFAULT(0)); 00321 00322 /*****************************************************************************************/ 00323 00324 00325 /*******************************Stereo correspondence*************************************/ 00326 00327 typedef struct CvCliqueFinder 00328 { 00329 CvGraph* graph; 00330 int** adj_matr; 00331 int N; //graph size 00332 00333 // stacks, counters etc/ 00334 int k; //stack size 00335 int* current_comp; 00336 int** All; 00337 00338 int* ne; 00339 int* ce; 00340 int* fixp; //node with minimal disconnections 00341 int* nod; 00342 int* s; //for selected candidate 00343 int status; 00344 int best_score; 00345 int weighted; 00346 int weighted_edges; 00347 float best_weight; 00348 float* edge_weights; 00349 float* vertex_weights; 00350 float* cur_weight; 00351 float* cand_weight; 00352 00353 } CvCliqueFinder; 00354 00355 #define CLIQUE_TIME_OFF 2 00356 #define CLIQUE_FOUND 1 00357 #define CLIQUE_END 0 00358 00359 /*CVAPI(void) cvStartFindCliques( CvGraph* graph, CvCliqueFinder* finder, int reverse, 00360 int weighted CV_DEFAULT(0), int weighted_edges CV_DEFAULT(0)); 00361 CVAPI(int) cvFindNextMaximalClique( CvCliqueFinder* finder, int* clock_rest CV_DEFAULT(0) ); 00362 CVAPI(void) cvEndFindCliques( CvCliqueFinder* finder ); 00363 00364 CVAPI(void) cvBronKerbosch( CvGraph* graph );*/ 00365 00366 00367 /*F/////////////////////////////////////////////////////////////////////////////////////// 00368 // 00369 // Name: cvSubgraphWeight 00370 // Purpose: finds weight of subgraph in a graph 00371 // Context: 00372 // Parameters: 00373 // graph - input graph. 00374 // subgraph - sequence of pairwise different ints. These are indices of vertices of subgraph. 00375 // weight_type - describes the way we measure weight. 00376 // one of the following: 00377 // CV_NOT_WEIGHTED - weight of a clique is simply its size 00378 // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices 00379 // CV_WEIGHTED_EDGE - the same but edges 00380 // CV_WEIGHTED_ALL - the same but both edges and vertices 00381 // weight_vtx - optional vector of floats, with size = graph->total. 00382 // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL 00383 // weights of vertices must be provided. If weight_vtx not zero 00384 // these weights considered to be here, otherwise function assumes 00385 // that vertices of graph are inherited from CvGraphWeightedVtx. 00386 // weight_edge - optional matrix of floats, of width and height = graph->total. 00387 // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL 00388 // weights of edges ought to be supplied. If weight_edge is not zero 00389 // function finds them here, otherwise function expects 00390 // edges of graph to be inherited from CvGraphWeightedEdge. 00391 // If this parameter is not zero structure of the graph is determined from matrix 00392 // rather than from CvGraphEdge's. In particular, elements corresponding to 00393 // absent edges should be zero. 00394 // Returns: 00395 // weight of subgraph. 00396 // Notes: 00397 //F*/ 00398 /*CVAPI(float) cvSubgraphWeight( CvGraph *graph, CvSeq *subgraph, 00399 CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED), 00400 CvVect32f weight_vtx CV_DEFAULT(0), 00401 CvMatr32f weight_edge CV_DEFAULT(0) );*/ 00402 00403 00404 /*F/////////////////////////////////////////////////////////////////////////////////////// 00405 // 00406 // Name: cvFindCliqueEx 00407 // Purpose: tries to find clique with maximum possible weight in a graph 00408 // Context: 00409 // Parameters: 00410 // graph - input graph. 00411 // storage - memory storage to be used by the result. 00412 // is_complementary - optional flag showing whether function should seek for clique 00413 // in complementary graph. 00414 // weight_type - describes our notion about weight. 00415 // one of the following: 00416 // CV_NOT_WEIGHTED - weight of a clique is simply its size 00417 // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices 00418 // CV_WEIGHTED_EDGE - the same but edges 00419 // CV_WEIGHTED_ALL - the same but both edges and vertices 00420 // weight_vtx - optional vector of floats, with size = graph->total. 00421 // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL 00422 // weights of vertices must be provided. If weight_vtx not zero 00423 // these weights considered to be here, otherwise function assumes 00424 // that vertices of graph are inherited from CvGraphWeightedVtx. 00425 // weight_edge - optional matrix of floats, of width and height = graph->total. 00426 // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL 00427 // weights of edges ought to be supplied. If weight_edge is not zero 00428 // function finds them here, otherwise function expects 00429 // edges of graph to be inherited from CvGraphWeightedEdge. 00430 // Note that in case of CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL 00431 // nonzero is_complementary implies nonzero weight_edge. 00432 // start_clique - optional sequence of pairwise different ints. They are indices of 00433 // vertices that shall be present in the output clique. 00434 // subgraph_of_ban - optional sequence of (maybe equal) ints. They are indices of 00435 // vertices that shall not be present in the output clique. 00436 // clique_weight_ptr - optional output parameter. Weight of found clique stored here. 00437 // num_generations - optional number of generations in evolutionary part of algorithm, 00438 // zero forces to return first found clique. 00439 // quality - optional parameter determining degree of required quality/speed tradeoff. 00440 // Must be in the range from 0 to 9. 00441 // 0 is fast and dirty, 9 is slow but hopefully yields good clique. 00442 // Returns: 00443 // sequence of pairwise different ints. 00444 // These are indices of vertices that form found clique. 00445 // Notes: 00446 // in cases of CV_WEIGHTED_EDGE and CV_WEIGHTED_ALL weights should be nonnegative. 00447 // start_clique has a priority over subgraph_of_ban. 00448 //F*/ 00449 /*CVAPI(CvSeq*) cvFindCliqueEx( CvGraph *graph, CvMemStorage *storage, 00450 int is_complementary CV_DEFAULT(0), 00451 CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED), 00452 CvVect32f weight_vtx CV_DEFAULT(0), 00453 CvMatr32f weight_edge CV_DEFAULT(0), 00454 CvSeq *start_clique CV_DEFAULT(0), 00455 CvSeq *subgraph_of_ban CV_DEFAULT(0), 00456 float *clique_weight_ptr CV_DEFAULT(0), 00457 int num_generations CV_DEFAULT(3), 00458 int quality CV_DEFAULT(2) );*/ 00459 00460 00461 #define CV_UNDEF_SC_PARAM 12345 //default value of parameters 00462 00463 #define CV_IDP_BIRCHFIELD_PARAM1 25 00464 #define CV_IDP_BIRCHFIELD_PARAM2 5 00465 #define CV_IDP_BIRCHFIELD_PARAM3 12 00466 #define CV_IDP_BIRCHFIELD_PARAM4 15 00467 #define CV_IDP_BIRCHFIELD_PARAM5 25 00468 00469 00470 #define CV_DISPARITY_BIRCHFIELD 0 00471 00472 00473 /*F/////////////////////////////////////////////////////////////////////////// 00474 // 00475 // Name: cvFindStereoCorrespondence 00476 // Purpose: find stereo correspondence on stereo-pair 00477 // Context: 00478 // Parameters: 00479 // leftImage - left image of stereo-pair (format 8uC1). 00480 // rightImage - right image of stereo-pair (format 8uC1). 00481 // mode - mode of correspondence retrieval (now CV_DISPARITY_BIRCHFIELD only) 00482 // dispImage - destination disparity image 00483 // maxDisparity - maximal disparity 00484 // param1, param2, param3, param4, param5 - parameters of algorithm 00485 // Returns: 00486 // Notes: 00487 // Images must be rectified. 00488 // All images must have format 8uC1. 00489 //F*/ 00490 CVAPI(void) 00491 cvFindStereoCorrespondence( 00492 const CvArr* leftImage, const CvArr* rightImage, 00493 int mode, 00494 CvArr* dispImage, 00495 int maxDisparity, 00496 double param1 CV_DEFAULT(CV_UNDEF_SC_PARAM), 00497 double param2 CV_DEFAULT(CV_UNDEF_SC_PARAM), 00498 double param3 CV_DEFAULT(CV_UNDEF_SC_PARAM), 00499 double param4 CV_DEFAULT(CV_UNDEF_SC_PARAM), 00500 double param5 CV_DEFAULT(CV_UNDEF_SC_PARAM) ); 00501 00502 /*****************************************************************************************/ 00503 /************ Epiline functions *******************/ 00504 00505 00506 00507 typedef struct CvStereoLineCoeff 00508 { 00509 double Xcoef; 00510 double XcoefA; 00511 double XcoefB; 00512 double XcoefAB; 00513 00514 double Ycoef; 00515 double YcoefA; 00516 double YcoefB; 00517 double YcoefAB; 00518 00519 double Zcoef; 00520 double ZcoefA; 00521 double ZcoefB; 00522 double ZcoefAB; 00523 }CvStereoLineCoeff; 00524 00525 00526 typedef struct CvCamera 00527 { 00528 float imgSize[2]; /* size of the camera view, used during calibration */ 00529 float matrix[9]; /* intinsic camera parameters: [ fx 0 cx; 0 fy cy; 0 0 1 ] */ 00530 float distortion[4]; /* distortion coefficients - two coefficients for radial distortion 00531 and another two for tangential: [ k1 k2 p1 p2 ] */ 00532 float rotMatr[9]; 00533 float transVect[3]; /* rotation matrix and transition vector relatively 00534 to some reference point in the space. */ 00535 } 00536 CvCamera; 00537 00538 typedef struct CvStereoCamera 00539 { 00540 CvCamera* camera[2]; /* two individual camera parameters */ 00541 float fundMatr[9]; /* fundamental matrix */ 00542 00543 /* New part for stereo */ 00544 CvPoint3D32f epipole[2]; 00545 CvPoint2D32f quad[2][4]; /* coordinates of destination quadrangle after 00546 epipolar geometry rectification */ 00547 double coeffs[2][3][3];/* coefficients for transformation */ 00548 CvPoint2D32f border[2][4]; 00549 CvSize warpSize; 00550 CvStereoLineCoeff* lineCoeffs; 00551 int needSwapCameras;/* flag set to 1 if need to swap cameras for good reconstruction */ 00552 float rotMatrix[9]; 00553 float transVector[3]; 00554 } 00555 CvStereoCamera; 00556 00557 00558 typedef struct CvContourOrientation 00559 { 00560 float egvals[2]; 00561 float egvects[4]; 00562 00563 float max, min; // minimum and maximum projections 00564 int imax, imin; 00565 } CvContourOrientation; 00566 00567 #define CV_CAMERA_TO_WARP 1 00568 #define CV_WARP_TO_CAMERA 2 00569 00570 CVAPI(int) icvConvertWarpCoordinates(double coeffs[3][3], 00571 CvPoint2D32f* cameraPoint, 00572 CvPoint2D32f* warpPoint, 00573 int direction); 00574 00575 CVAPI(int) icvGetSymPoint3D( CvPoint3D64f pointCorner, 00576 CvPoint3D64f point1, 00577 CvPoint3D64f point2, 00578 CvPoint3D64f *pointSym2); 00579 00580 CVAPI(void) icvGetPieceLength3D(CvPoint3D64f point1,CvPoint3D64f point2,double* dist); 00581 00582 CVAPI(int) icvCompute3DPoint( double alpha,double betta, 00583 CvStereoLineCoeff* coeffs, 00584 CvPoint3D64f* point); 00585 00586 CVAPI(int) icvCreateConvertMatrVect( CvMatr64d rotMatr1, 00587 CvMatr64d transVect1, 00588 CvMatr64d rotMatr2, 00589 CvMatr64d transVect2, 00590 CvMatr64d convRotMatr, 00591 CvMatr64d convTransVect); 00592 00593 CVAPI(int) icvConvertPointSystem(CvPoint3D64f M2, 00594 CvPoint3D64f* M1, 00595 CvMatr64d rotMatr, 00596 CvMatr64d transVect 00597 ); 00598 00599 CVAPI(int) icvComputeCoeffForStereo( CvStereoCamera* stereoCamera); 00600 00601 CVAPI(int) icvGetCrossPieceVector(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f v2_start,CvPoint2D32f v2_end,CvPoint2D32f *cross); 00602 CVAPI(int) icvGetCrossLineDirect(CvPoint2D32f p1,CvPoint2D32f p2,float a,float b,float c,CvPoint2D32f* cross); 00603 CVAPI(float) icvDefinePointPosition(CvPoint2D32f point1,CvPoint2D32f point2,CvPoint2D32f point); 00604 CVAPI(int) icvStereoCalibration( int numImages, 00605 int* nums, 00606 CvSize imageSize, 00607 CvPoint2D32f* imagePoints1, 00608 CvPoint2D32f* imagePoints2, 00609 CvPoint3D32f* objectPoints, 00610 CvStereoCamera* stereoparams 00611 ); 00612 00613 00614 CVAPI(int) icvComputeRestStereoParams(CvStereoCamera *stereoparams); 00615 00616 CVAPI(void) cvComputePerspectiveMap( const double coeffs[3][3], CvArr* rectMapX, CvArr* rectMapY ); 00617 00618 CVAPI(int) icvComCoeffForLine( CvPoint2D64f point1, 00619 CvPoint2D64f point2, 00620 CvPoint2D64f point3, 00621 CvPoint2D64f point4, 00622 CvMatr64d camMatr1, 00623 CvMatr64d rotMatr1, 00624 CvMatr64d transVect1, 00625 CvMatr64d camMatr2, 00626 CvMatr64d rotMatr2, 00627 CvMatr64d transVect2, 00628 CvStereoLineCoeff* coeffs, 00629 int* needSwapCameras); 00630 00631 CVAPI(int) icvGetDirectionForPoint( CvPoint2D64f point, 00632 CvMatr64d camMatr, 00633 CvPoint3D64f* direct); 00634 00635 CVAPI(int) icvGetCrossLines(CvPoint3D64f point11,CvPoint3D64f point12, 00636 CvPoint3D64f point21,CvPoint3D64f point22, 00637 CvPoint3D64f* midPoint); 00638 00639 CVAPI(int) icvComputeStereoLineCoeffs( CvPoint3D64f pointA, 00640 CvPoint3D64f pointB, 00641 CvPoint3D64f pointCam1, 00642 double gamma, 00643 CvStereoLineCoeff* coeffs); 00644 00645 /*CVAPI(int) icvComputeFundMatrEpipoles ( CvMatr64d camMatr1, 00646 CvMatr64d rotMatr1, 00647 CvVect64d transVect1, 00648 CvMatr64d camMatr2, 00649 CvMatr64d rotMatr2, 00650 CvVect64d transVect2, 00651 CvPoint2D64f* epipole1, 00652 CvPoint2D64f* epipole2, 00653 CvMatr64d fundMatr);*/ 00654 00655 CVAPI(int) icvGetAngleLine( CvPoint2D64f startPoint, CvSize imageSize,CvPoint2D64f *point1,CvPoint2D64f *point2); 00656 00657 CVAPI(void) icvGetCoefForPiece( CvPoint2D64f p_start,CvPoint2D64f p_end, 00658 double *a,double *b,double *c, 00659 int* result); 00660 00661 /*CVAPI(void) icvGetCommonArea( CvSize imageSize, 00662 CvPoint2D64f epipole1,CvPoint2D64f epipole2, 00663 CvMatr64d fundMatr, 00664 CvVect64d coeff11,CvVect64d coeff12, 00665 CvVect64d coeff21,CvVect64d coeff22, 00666 int* result);*/ 00667 00668 CVAPI(void) icvComputeeInfiniteProject1(CvMatr64d rotMatr, 00669 CvMatr64d camMatr1, 00670 CvMatr64d camMatr2, 00671 CvPoint2D32f point1, 00672 CvPoint2D32f *point2); 00673 00674 CVAPI(void) icvComputeeInfiniteProject2(CvMatr64d rotMatr, 00675 CvMatr64d camMatr1, 00676 CvMatr64d camMatr2, 00677 CvPoint2D32f* point1, 00678 CvPoint2D32f point2); 00679 00680 CVAPI(void) icvGetCrossDirectDirect( CvVect64d direct1,CvVect64d direct2, 00681 CvPoint2D64f *cross,int* result); 00682 00683 CVAPI(void) icvGetCrossPieceDirect( CvPoint2D64f p_start,CvPoint2D64f p_end, 00684 double a,double b,double c, 00685 CvPoint2D64f *cross,int* result); 00686 00687 CVAPI(void) icvGetCrossPiecePiece( CvPoint2D64f p1_start,CvPoint2D64f p1_end, 00688 CvPoint2D64f p2_start,CvPoint2D64f p2_end, 00689 CvPoint2D64f* cross, 00690 int* result); 00691 00692 CVAPI(void) icvGetPieceLength(CvPoint2D64f point1,CvPoint2D64f point2,double* dist); 00693 00694 CVAPI(void) icvGetCrossRectDirect( CvSize imageSize, 00695 double a,double b,double c, 00696 CvPoint2D64f *start,CvPoint2D64f *end, 00697 int* result); 00698 00699 CVAPI(void) icvProjectPointToImage( CvPoint3D64f point, 00700 CvMatr64d camMatr,CvMatr64d rotMatr,CvVect64d transVect, 00701 CvPoint2D64f* projPoint); 00702 00703 CVAPI(void) icvGetQuadsTransform( CvSize imageSize, 00704 CvMatr64d camMatr1, 00705 CvMatr64d rotMatr1, 00706 CvVect64d transVect1, 00707 CvMatr64d camMatr2, 00708 CvMatr64d rotMatr2, 00709 CvVect64d transVect2, 00710 CvSize* warpSize, 00711 double quad1[4][2], 00712 double quad2[4][2], 00713 CvMatr64d fundMatr, 00714 CvPoint3D64f* epipole1, 00715 CvPoint3D64f* epipole2 00716 ); 00717 00718 CVAPI(void) icvGetQuadsTransformStruct( CvStereoCamera* stereoCamera); 00719 00720 CVAPI(void) icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera); 00721 00722 CVAPI(void) icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, 00723 CvPoint2D64f epipole, 00724 CvSize imageSize, 00725 CvPoint2D64f* point11,CvPoint2D64f* point12, 00726 CvPoint2D64f* point21,CvPoint2D64f* point22, 00727 int* result); 00728 00729 CVAPI(void) icvGetMiddleAnglePoint( CvPoint2D64f basePoint, 00730 CvPoint2D64f point1,CvPoint2D64f point2, 00731 CvPoint2D64f* midPoint); 00732 00733 CVAPI(void) icvGetNormalDirect(CvVect64d direct,CvPoint2D64f point,CvVect64d normDirect); 00734 00735 CVAPI(double) icvGetVect(CvPoint2D64f basePoint,CvPoint2D64f point1,CvPoint2D64f point2); 00736 00737 CVAPI(void) icvProjectPointToDirect( CvPoint2D64f point,CvVect64d lineCoeff, 00738 CvPoint2D64f* projectPoint); 00739 00740 CVAPI(void) icvGetDistanceFromPointToDirect( CvPoint2D64f point,CvVect64d lineCoef,double*dist); 00741 00742 CVAPI(IplImage*) icvCreateIsometricImage( IplImage* src, IplImage* dst, 00743 int desired_depth, int desired_num_channels ); 00744 00745 CVAPI(void) cvDeInterlace( const CvArr* frame, CvArr* fieldEven, CvArr* fieldOdd ); 00746 00747 /*CVAPI(int) icvSelectBestRt( int numImages, 00748 int* numPoints, 00749 CvSize imageSize, 00750 CvPoint2D32f* imagePoints1, 00751 CvPoint2D32f* imagePoints2, 00752 CvPoint3D32f* objectPoints, 00753 00754 CvMatr32f cameraMatrix1, 00755 CvVect32f distortion1, 00756 CvMatr32f rotMatrs1, 00757 CvVect32f transVects1, 00758 00759 CvMatr32f cameraMatrix2, 00760 CvVect32f distortion2, 00761 CvMatr32f rotMatrs2, 00762 CvVect32f transVects2, 00763 00764 CvMatr32f bestRotMatr, 00765 CvVect32f bestTransVect 00766 );*/ 00767 00768 /****************************************************************************************\ 00769 * Contour Morphing * 00770 \****************************************************************************************/ 00771 00772 /* finds correspondence between two contours */ 00773 CvSeq* cvCalcContoursCorrespondence( const CvSeq* contour1, 00774 const CvSeq* contour2, 00775 CvMemStorage* storage); 00776 00777 /* morphs contours using the pre-calculated correspondence: 00778 alpha=0 ~ contour1, alpha=1 ~ contour2 */ 00779 CvSeq* cvMorphContours( const CvSeq* contour1, const CvSeq* contour2, 00780 CvSeq* corr, double alpha, 00781 CvMemStorage* storage ); 00782 00783 /****************************************************************************************\ 00784 * Texture Descriptors * 00785 \****************************************************************************************/ 00786 00787 #define CV_GLCM_OPTIMIZATION_NONE -2 00788 #define CV_GLCM_OPTIMIZATION_LUT -1 00789 #define CV_GLCM_OPTIMIZATION_HISTOGRAM 0 00790 00791 #define CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST 10 00792 #define CV_GLCMDESC_OPTIMIZATION_ALLOWTRIPLENEST 11 00793 #define CV_GLCMDESC_OPTIMIZATION_HISTOGRAM 4 00794 00795 #define CV_GLCMDESC_ENTROPY 0 00796 #define CV_GLCMDESC_ENERGY 1 00797 #define CV_GLCMDESC_HOMOGENITY 2 00798 #define CV_GLCMDESC_CONTRAST 3 00799 #define CV_GLCMDESC_CLUSTERTENDENCY 4 00800 #define CV_GLCMDESC_CLUSTERSHADE 5 00801 #define CV_GLCMDESC_CORRELATION 6 00802 #define CV_GLCMDESC_CORRELATIONINFO1 7 00803 #define CV_GLCMDESC_CORRELATIONINFO2 8 00804 #define CV_GLCMDESC_MAXIMUMPROBABILITY 9 00805 00806 #define CV_GLCM_ALL 0 00807 #define CV_GLCM_GLCM 1 00808 #define CV_GLCM_DESC 2 00809 00810 typedef struct CvGLCM CvGLCM; 00811 00812 CVAPI(CvGLCM*) cvCreateGLCM( const IplImage* srcImage, 00813 int stepMagnitude, 00814 const int* stepDirections CV_DEFAULT(0), 00815 int numStepDirections CV_DEFAULT(0), 00816 int optimizationType CV_DEFAULT(CV_GLCM_OPTIMIZATION_NONE)); 00817 00818 CVAPI(void) cvReleaseGLCM( CvGLCM** GLCM, int flag CV_DEFAULT(CV_GLCM_ALL)); 00819 00820 CVAPI(void) cvCreateGLCMDescriptors( CvGLCM* destGLCM, 00821 int descriptorOptimizationType 00822 CV_DEFAULT(CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST)); 00823 00824 CVAPI(double) cvGetGLCMDescriptor( CvGLCM* GLCM, int step, int descriptor ); 00825 00826 CVAPI(void) cvGetGLCMDescriptorStatistics( CvGLCM* GLCM, int descriptor, 00827 double* average, double* standardDeviation ); 00828 00829 CVAPI(IplImage*) cvCreateGLCMImage( CvGLCM* GLCM, int step ); 00830 00831 /****************************************************************************************\ 00832 * Face eyes&mouth tracking * 00833 \****************************************************************************************/ 00834 00835 00836 typedef struct CvFaceTracker CvFaceTracker; 00837 00838 #define CV_NUM_FACE_ELEMENTS 3 00839 enum CV_FACE_ELEMENTS 00840 { 00841 CV_FACE_MOUTH = 0, 00842 CV_FACE_LEFT_EYE = 1, 00843 CV_FACE_RIGHT_EYE = 2 00844 }; 00845 00846 CVAPI(CvFaceTracker*) cvInitFaceTracker(CvFaceTracker* pFaceTracking, const IplImage* imgGray, 00847 CvRect* pRects, int nRects); 00848 CVAPI(int) cvTrackFace( CvFaceTracker* pFaceTracker, IplImage* imgGray, 00849 CvRect* pRects, int nRects, 00850 CvPoint* ptRotate, double* dbAngleRotate); 00851 CVAPI(void) cvReleaseFaceTracker(CvFaceTracker** ppFaceTracker); 00852 00853 00854 typedef struct CvFace 00855 { 00856 CvRect MouthRect; 00857 CvRect LeftEyeRect; 00858 CvRect RightEyeRect; 00859 } CvFaceData; 00860 00861 CvSeq * cvFindFace(IplImage * Image,CvMemStorage* storage); 00862 CvSeq * cvPostBoostingFindFace(IplImage * Image,CvMemStorage* storage); 00863 00864 00865 /****************************************************************************************\ 00866 * 3D Tracker * 00867 \****************************************************************************************/ 00868 00869 typedef unsigned char CvBool; 00870 00871 typedef struct 00872 { 00873 int id; 00874 CvPoint2D32f p; // pgruebele: So we do not loose precision, this needs to be float 00875 } Cv3dTracker2dTrackedObject; 00876 00877 CV_INLINE Cv3dTracker2dTrackedObject cv3dTracker2dTrackedObject(int id, CvPoint2D32f p) 00878 { 00879 Cv3dTracker2dTrackedObject r; 00880 r.id = id; 00881 r.p = p; 00882 return r; 00883 } 00884 00885 typedef struct 00886 { 00887 int id; 00888 CvPoint3D32f p; // location of the tracked object 00889 } Cv3dTrackerTrackedObject; 00890 00891 CV_INLINE Cv3dTrackerTrackedObject cv3dTrackerTrackedObject(int id, CvPoint3D32f p) 00892 { 00893 Cv3dTrackerTrackedObject r; 00894 r.id = id; 00895 r.p = p; 00896 return r; 00897 } 00898 00899 typedef struct 00900 { 00901 CvBool valid; 00902 float mat[4][4]; /* maps camera coordinates to world coordinates */ 00903 CvPoint2D32f principal_point; /* copied from intrinsics so this structure */ 00904 /* has all the info we need */ 00905 } Cv3dTrackerCameraInfo; 00906 00907 typedef struct 00908 { 00909 CvPoint2D32f principal_point; 00910 float focal_length[2]; 00911 float distortion[4]; 00912 } Cv3dTrackerCameraIntrinsics; 00913 00914 CVAPI(CvBool) cv3dTrackerCalibrateCameras(int num_cameras, 00915 const Cv3dTrackerCameraIntrinsics camera_intrinsics[], /* size is num_cameras */ 00916 CvSize etalon_size, 00917 float square_size, 00918 IplImage *samples[], /* size is num_cameras */ 00919 Cv3dTrackerCameraInfo camera_info[]); /* size is num_cameras */ 00920 00921 CVAPI(int) cv3dTrackerLocateObjects(int num_cameras, int num_objects, 00922 const Cv3dTrackerCameraInfo camera_info[], /* size is num_cameras */ 00923 const Cv3dTracker2dTrackedObject tracking_info[], /* size is num_objects*num_cameras */ 00924 Cv3dTrackerTrackedObject tracked_objects[]); /* size is num_objects */ 00925 /**************************************************************************************** 00926 tracking_info is a rectangular array; one row per camera, num_objects elements per row. 00927 The id field of any unused slots must be -1. Ids need not be ordered or consecutive. On 00928 completion, the return value is the number of objects located; i.e., the number of objects 00929 visible by more than one camera. The id field of any unused slots in tracked objects is 00930 set to -1. 00931 ****************************************************************************************/ 00932 00933 00934 /****************************************************************************************\ 00935 * Skeletons and Linear-Contour Models * 00936 \****************************************************************************************/ 00937 00938 typedef enum CvLeeParameters 00939 { 00940 CV_LEE_INT = 0, 00941 CV_LEE_FLOAT = 1, 00942 CV_LEE_DOUBLE = 2, 00943 CV_LEE_AUTO = -1, 00944 CV_LEE_ERODE = 0, 00945 CV_LEE_ZOOM = 1, 00946 CV_LEE_NON = 2 00947 } CvLeeParameters; 00948 00949 #define CV_NEXT_VORONOISITE2D( SITE ) ((SITE)->edge[0]->site[((SITE)->edge[0]->site[0] == (SITE))]) 00950 #define CV_PREV_VORONOISITE2D( SITE ) ((SITE)->edge[1]->site[((SITE)->edge[1]->site[0] == (SITE))]) 00951 #define CV_FIRST_VORONOIEDGE2D( SITE ) ((SITE)->edge[0]) 00952 #define CV_LAST_VORONOIEDGE2D( SITE ) ((SITE)->edge[1]) 00953 #define CV_NEXT_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[(EDGE)->site[0] != (SITE)]) 00954 #define CV_PREV_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[2 + ((EDGE)->site[0] != (SITE))]) 00955 #define CV_VORONOIEDGE2D_BEGINNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] != (SITE))]) 00956 #define CV_VORONOIEDGE2D_ENDNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] == (SITE))]) 00957 #define CV_TWIN_VORONOISITE2D( SITE, EDGE ) ( (EDGE)->site[((EDGE)->site[0] == (SITE))]) 00958 00959 #define CV_VORONOISITE2D_FIELDS() \ 00960 struct CvVoronoiNode2D *node[2]; \ 00961 struct CvVoronoiEdge2D *edge[2]; 00962 00963 typedef struct CvVoronoiSite2D 00964 { 00965 CV_VORONOISITE2D_FIELDS() 00966 struct CvVoronoiSite2D *next[2]; 00967 } CvVoronoiSite2D; 00968 00969 #define CV_VORONOIEDGE2D_FIELDS() \ 00970 struct CvVoronoiNode2D *node[2]; \ 00971 struct CvVoronoiSite2D *site[2]; \ 00972 struct CvVoronoiEdge2D *next[4]; 00973 00974 typedef struct CvVoronoiEdge2D 00975 { 00976 CV_VORONOIEDGE2D_FIELDS() 00977 } CvVoronoiEdge2D; 00978 00979 #define CV_VORONOINODE2D_FIELDS() \ 00980 CV_SET_ELEM_FIELDS(CvVoronoiNode2D) \ 00981 CvPoint2D32f pt; \ 00982 float radius; 00983 00984 typedef struct CvVoronoiNode2D 00985 { 00986 CV_VORONOINODE2D_FIELDS() 00987 } CvVoronoiNode2D; 00988 00989 #define CV_VORONOIDIAGRAM2D_FIELDS() \ 00990 CV_GRAPH_FIELDS() \ 00991 CvSet *sites; 00992 00993 typedef struct CvVoronoiDiagram2D 00994 { 00995 CV_VORONOIDIAGRAM2D_FIELDS() 00996 } CvVoronoiDiagram2D; 00997 00998 /* Computes Voronoi Diagram for given polygons with holes */ 00999 CVAPI(int) cvVoronoiDiagramFromContour(CvSeq* ContourSeq, 01000 CvVoronoiDiagram2D** VoronoiDiagram, 01001 CvMemStorage* VoronoiStorage, 01002 CvLeeParameters contour_type CV_DEFAULT(CV_LEE_INT), 01003 int contour_orientation CV_DEFAULT(-1), 01004 int attempt_number CV_DEFAULT(10)); 01005 01006 /* Computes Voronoi Diagram for domains in given image */ 01007 CVAPI(int) cvVoronoiDiagramFromImage(IplImage* pImage, 01008 CvSeq** ContourSeq, 01009 CvVoronoiDiagram2D** VoronoiDiagram, 01010 CvMemStorage* VoronoiStorage, 01011 CvLeeParameters regularization_method CV_DEFAULT(CV_LEE_NON), 01012 float approx_precision CV_DEFAULT(CV_LEE_AUTO)); 01013 01014 /* Deallocates the storage */ 01015 CVAPI(void) cvReleaseVoronoiStorage(CvVoronoiDiagram2D* VoronoiDiagram, 01016 CvMemStorage** pVoronoiStorage); 01017 01018 /*********************** Linear-Contour Model ****************************/ 01019 01020 struct CvLCMEdge; 01021 struct CvLCMNode; 01022 01023 typedef struct CvLCMEdge 01024 { 01025 CV_GRAPH_EDGE_FIELDS() 01026 CvSeq* chain; 01027 float width; 01028 int index1; 01029 int index2; 01030 } CvLCMEdge; 01031 01032 typedef struct CvLCMNode 01033 { 01034 CV_GRAPH_VERTEX_FIELDS() 01035 CvContour* contour; 01036 } CvLCMNode; 01037 01038 01039 /* Computes hybrid model from Voronoi Diagram */ 01040 CVAPI(CvGraph*) cvLinearContorModelFromVoronoiDiagram(CvVoronoiDiagram2D* VoronoiDiagram, 01041 float maxWidth); 01042 01043 /* Releases hybrid model storage */ 01044 CVAPI(int) cvReleaseLinearContorModelStorage(CvGraph** Graph); 01045 01046 01047 /* two stereo-related functions */ 01048 01049 CVAPI(void) cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f vertex[4], double matrix[3][3], 01050 CvArr* rectMap ); 01051 01052 /*CVAPI(void) cvInitStereoRectification( CvStereoCamera* params, 01053 CvArr* rectMap1, CvArr* rectMap2, 01054 int do_undistortion );*/ 01055 01056 /*************************** View Morphing Functions ************************/ 01057 01058 /* The order of the function corresponds to the order they should appear in 01059 the view morphing pipeline */ 01060 01061 /* Finds ending points of scanlines on left and right images of stereo-pair */ 01062 CVAPI(void) cvMakeScanlines( const CvMatrix3* matrix, CvSize img_size, 01063 int* scanlines1, int* scanlines2, 01064 int* lengths1, int* lengths2, 01065 int* line_count ); 01066 01067 /* Grab pixel values from scanlines and stores them sequentially 01068 (some sort of perspective image transform) */ 01069 CVAPI(void) cvPreWarpImage( int line_count, 01070 IplImage* img, 01071 uchar* dst, 01072 int* dst_nums, 01073 int* scanlines); 01074 01075 /* Approximate each grabbed scanline by a sequence of runs 01076 (lossy run-length compression) */ 01077 CVAPI(void) cvFindRuns( int line_count, 01078 uchar* prewarp1, 01079 uchar* prewarp2, 01080 int* line_lengths1, 01081 int* line_lengths2, 01082 int* runs1, 01083 int* runs2, 01084 int* num_runs1, 01085 int* num_runs2); 01086 01087 /* Compares two sets of compressed scanlines */ 01088 CVAPI(void) cvDynamicCorrespondMulti( int line_count, 01089 int* first, 01090 int* first_runs, 01091 int* second, 01092 int* second_runs, 01093 int* first_corr, 01094 int* second_corr); 01095 01096 /* Finds scanline ending coordinates for some intermediate "virtual" camera position */ 01097 CVAPI(void) cvMakeAlphaScanlines( int* scanlines1, 01098 int* scanlines2, 01099 int* scanlinesA, 01100 int* lengths, 01101 int line_count, 01102 float alpha); 01103 01104 /* Blends data of the left and right image scanlines to get 01105 pixel values of "virtual" image scanlines */ 01106 CVAPI(void) cvMorphEpilinesMulti( int line_count, 01107 uchar* first_pix, 01108 int* first_num, 01109 uchar* second_pix, 01110 int* second_num, 01111 uchar* dst_pix, 01112 int* dst_num, 01113 float alpha, 01114 int* first, 01115 int* first_runs, 01116 int* second, 01117 int* second_runs, 01118 int* first_corr, 01119 int* second_corr); 01120 01121 /* Does reverse warping of the morphing result to make 01122 it fill the destination image rectangle */ 01123 CVAPI(void) cvPostWarpImage( int line_count, 01124 uchar* src, 01125 int* src_nums, 01126 IplImage* img, 01127 int* scanlines); 01128 01129 /* Deletes Moire (missed pixels that appear due to discretization) */ 01130 CVAPI(void) cvDeleteMoire( IplImage* img ); 01131 01132 01133 /****************************************************************************************\ 01134 * Background/foreground segmentation * 01135 \****************************************************************************************/ 01136 01137 /* We discriminate between foreground and background pixels 01138 * by building and maintaining a model of the background. 01139 * Any pixel which does not fit this model is then deemed 01140 * to be foreground. 01141 * 01142 * At present we support two core background models, 01143 * one of which has two variations: 01144 * 01145 * o CV_BG_MODEL_FGD: latest and greatest algorithm, described in 01146 * 01147 * Foreground Object Detection from Videos Containing Complex Background. 01148 * Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. 01149 * ACM MM2003 9p 01150 * 01151 * o CV_BG_MODEL_FGD_SIMPLE: 01152 * A code comment describes this as a simplified version of the above, 01153 * but the code is in fact currently identical 01154 * 01155 * o CV_BG_MODEL_MOG: "Mixture of Gaussians", older algorithm, described in 01156 * 01157 * Moving target classification and tracking from real-time video. 01158 * A Lipton, H Fujijoshi, R Patil 01159 * Proceedings IEEE Workshop on Application of Computer Vision pp 8-14 1998 01160 * 01161 * Learning patterns of activity using real-time tracking 01162 * C Stauffer and W Grimson August 2000 01163 * IEEE Transactions on Pattern Analysis and Machine Intelligence 22(8):747-757 01164 */ 01165 01166 01167 #define CV_BG_MODEL_FGD 0 01168 #define CV_BG_MODEL_MOG 1 /* "Mixture of Gaussians". */ 01169 #define CV_BG_MODEL_FGD_SIMPLE 2 01170 01171 struct CvBGStatModel; 01172 01173 typedef void (CV_CDECL * CvReleaseBGStatModel)( struct CvBGStatModel** bg_model ); 01174 typedef int (CV_CDECL * CvUpdateBGStatModel)( IplImage* curr_frame, struct CvBGStatModel* bg_model, 01175 double learningRate ); 01176 01177 #define CV_BG_STAT_MODEL_FIELDS() \ 01178 int type; /*type of BG model*/ \ 01179 CvReleaseBGStatModel release; \ 01180 CvUpdateBGStatModel update; \ 01181 IplImage* background; /*8UC3 reference background image*/ \ 01182 IplImage* foreground; /*8UC1 foreground image*/ \ 01183 IplImage** layers; /*8UC3 reference background image, can be null */ \ 01184 int layer_count; /* can be zero */ \ 01185 CvMemStorage* storage; /*storage for foreground_regions*/ \ 01186 CvSeq* foreground_regions /*foreground object contours*/ 01187 01188 typedef struct CvBGStatModel 01189 { 01190 CV_BG_STAT_MODEL_FIELDS(); 01191 } 01192 CvBGStatModel; 01193 01194 // 01195 01196 // Releases memory used by BGStatModel 01197 CV_INLINE void cvReleaseBGStatModel( CvBGStatModel** bg_model ) 01198 { 01199 if( bg_model && *bg_model && (*bg_model)->release ) 01200 (*bg_model)->release( bg_model ); 01201 } 01202 01203 // Updates statistical model and returns number of found foreground regions 01204 CV_INLINE int cvUpdateBGStatModel( IplImage* current_frame, CvBGStatModel* bg_model, double learningRate CV_DEFAULT(-1)) 01205 { 01206 return bg_model && bg_model->update ? bg_model->update( current_frame, bg_model, learningRate ) : 0; 01207 } 01208 01209 // Performs FG post-processing using segmentation 01210 // (all pixels of a region will be classified as foreground if majority of pixels of the region are FG). 01211 // parameters: 01212 // segments - pointer to result of segmentation (for example MeanShiftSegmentation) 01213 // bg_model - pointer to CvBGStatModel structure 01214 CVAPI(void) cvRefineForegroundMaskBySegm( CvSeq* segments, CvBGStatModel* bg_model ); 01215 01216 /* Common use change detection function */ 01217 CVAPI(int) cvChangeDetection( IplImage* prev_frame, 01218 IplImage* curr_frame, 01219 IplImage* change_mask ); 01220 01221 /* 01222 Interface of ACM MM2003 algorithm 01223 */ 01224 01225 /* Default parameters of foreground detection algorithm: */ 01226 #define CV_BGFG_FGD_LC 128 01227 #define CV_BGFG_FGD_N1C 15 01228 #define CV_BGFG_FGD_N2C 25 01229 01230 #define CV_BGFG_FGD_LCC 64 01231 #define CV_BGFG_FGD_N1CC 25 01232 #define CV_BGFG_FGD_N2CC 40 01233 01234 /* Background reference image update parameter: */ 01235 #define CV_BGFG_FGD_ALPHA_1 0.1f 01236 01237 /* stat model update parameter 01238 * 0.002f ~ 1K frame(~45sec), 0.005 ~ 18sec (if 25fps and absolutely static BG) 01239 */ 01240 #define CV_BGFG_FGD_ALPHA_2 0.005f 01241 01242 /* start value for alpha parameter (to fast initiate statistic model) */ 01243 #define CV_BGFG_FGD_ALPHA_3 0.1f 01244 01245 #define CV_BGFG_FGD_DELTA 2 01246 01247 #define CV_BGFG_FGD_T 0.9f 01248 01249 #define CV_BGFG_FGD_MINAREA 15.f 01250 01251 #define CV_BGFG_FGD_BG_UPDATE_TRESH 0.5f 01252 01253 /* See the above-referenced Li/Huang/Gu/Tian paper 01254 * for a full description of these background-model 01255 * tuning parameters. 01256 * 01257 * Nomenclature: 'c' == "color", a three-component red/green/blue vector. 01258 * We use histograms of these to model the range of 01259 * colors we've seen at a given background pixel. 01260 * 01261 * 'cc' == "color co-occurrence", a six-component vector giving 01262 * RGB color for both this frame and preceding frame. 01263 * We use histograms of these to model the range of 01264 * color CHANGES we've seen at a given background pixel. 01265 */ 01266 typedef struct CvFGDStatModelParams 01267 { 01268 int Lc; /* Quantized levels per 'color' component. Power of two, typically 32, 64 or 128. */ 01269 int N1c; /* Number of color vectors used to model normal background color variation at a given pixel. */ 01270 int N2c; /* Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c. */ 01271 /* Used to allow the first N1c vectors to adapt over time to changing background. */ 01272 01273 int Lcc; /* Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64. */ 01274 int N1cc; /* Number of color co-occurrence vectors used to model normal background color variation at a given pixel. */ 01275 int N2cc; /* Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc. */ 01276 /* Used to allow the first N1cc vectors to adapt over time to changing background. */ 01277 01278 int is_obj_without_holes;/* If TRUE we ignore holes within foreground blobs. Defaults to TRUE. */ 01279 int perform_morphing; /* Number of erode-dilate-erode foreground-blob cleanup iterations. */ 01280 /* These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1. */ 01281 01282 float alpha1; /* How quickly we forget old background pixel values seen. Typically set to 0.1 */ 01283 float alpha2; /* "Controls speed of feature learning". Depends on T. Typical value circa 0.005. */ 01284 float alpha3; /* Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1. */ 01285 01286 float delta; /* Affects color and color co-occurrence quantization, typically set to 2. */ 01287 float T; /* "A percentage value which determines when new features can be recognized as new background." (Typically 0.9).*/ 01288 float minArea; /* Discard foreground blobs whose bounding box is smaller than this threshold. */ 01289 } 01290 CvFGDStatModelParams; 01291 01292 typedef struct CvBGPixelCStatTable 01293 { 01294 float Pv, Pvb; 01295 uchar v[3]; 01296 } 01297 CvBGPixelCStatTable; 01298 01299 typedef struct CvBGPixelCCStatTable 01300 { 01301 float Pv, Pvb; 01302 uchar v[6]; 01303 } 01304 CvBGPixelCCStatTable; 01305 01306 typedef struct CvBGPixelStat 01307 { 01308 float Pbc; 01309 float Pbcc; 01310 CvBGPixelCStatTable* ctable; 01311 CvBGPixelCCStatTable* cctable; 01312 uchar is_trained_st_model; 01313 uchar is_trained_dyn_model; 01314 } 01315 CvBGPixelStat; 01316 01317 01318 typedef struct CvFGDStatModel 01319 { 01320 CV_BG_STAT_MODEL_FIELDS(); 01321 CvBGPixelStat* pixel_stat; 01322 IplImage* Ftd; 01323 IplImage* Fbd; 01324 IplImage* prev_frame; 01325 CvFGDStatModelParams params; 01326 } 01327 CvFGDStatModel; 01328 01329 /* Creates FGD model */ 01330 CVAPI(CvBGStatModel*) cvCreateFGDStatModel( IplImage* first_frame, 01331 CvFGDStatModelParams* parameters CV_DEFAULT(NULL)); 01332 01333 /* 01334 Interface of Gaussian mixture algorithm 01335 01336 "An improved adaptive background mixture model for real-time tracking with shadow detection" 01337 P. KadewTraKuPong and R. Bowden, 01338 Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001." 01339 http://personal.ee.surrey.ac.uk/Personal/R.Bowden/publications/avbs01/avbs01.pdf 01340 */ 01341 01342 /* Note: "MOG" == "Mixture Of Gaussians": */ 01343 01344 #define CV_BGFG_MOG_MAX_NGAUSSIANS 500 01345 01346 /* default parameters of gaussian background detection algorithm */ 01347 #define CV_BGFG_MOG_BACKGROUND_THRESHOLD 0.7 /* threshold sum of weights for background test */ 01348 #define CV_BGFG_MOG_STD_THRESHOLD 2.5 /* lambda=2.5 is 99% */ 01349 #define CV_BGFG_MOG_WINDOW_SIZE 200 /* Learning rate; alpha = 1/CV_GBG_WINDOW_SIZE */ 01350 #define CV_BGFG_MOG_NGAUSSIANS 5 /* = K = number of Gaussians in mixture */ 01351 #define CV_BGFG_MOG_WEIGHT_INIT 0.05 01352 #define CV_BGFG_MOG_SIGMA_INIT 30 01353 #define CV_BGFG_MOG_MINAREA 15.f 01354 01355 01356 #define CV_BGFG_MOG_NCOLORS 3 01357 01358 typedef struct CvGaussBGStatModelParams 01359 { 01360 int win_size; /* = 1/alpha */ 01361 int n_gauss; 01362 double bg_threshold, std_threshold, minArea; 01363 double weight_init, variance_init; 01364 }CvGaussBGStatModelParams; 01365 01366 typedef struct CvGaussBGValues 01367 { 01368 int match_sum; 01369 double weight; 01370 double variance[CV_BGFG_MOG_NCOLORS]; 01371 double mean[CV_BGFG_MOG_NCOLORS]; 01372 } 01373 CvGaussBGValues; 01374 01375 typedef struct CvGaussBGPoint 01376 { 01377 CvGaussBGValues* g_values; 01378 } 01379 CvGaussBGPoint; 01380 01381 01382 typedef struct CvGaussBGModel 01383 { 01384 CV_BG_STAT_MODEL_FIELDS(); 01385 CvGaussBGStatModelParams params; 01386 CvGaussBGPoint* g_point; 01387 int countFrames; 01388 } 01389 CvGaussBGModel; 01390 01391 01392 /* Creates Gaussian mixture background model */ 01393 CVAPI(CvBGStatModel*) cvCreateGaussianBGModel( IplImage* first_frame, 01394 CvGaussBGStatModelParams* parameters CV_DEFAULT(NULL)); 01395 01396 01397 typedef struct CvBGCodeBookElem 01398 { 01399 struct CvBGCodeBookElem* next; 01400 int tLastUpdate; 01401 int stale; 01402 uchar boxMin[3]; 01403 uchar boxMax[3]; 01404 uchar learnMin[3]; 01405 uchar learnMax[3]; 01406 } 01407 CvBGCodeBookElem; 01408 01409 typedef struct CvBGCodeBookModel 01410 { 01411 CvSize size; 01412 int t; 01413 uchar cbBounds[3]; 01414 uchar modMin[3]; 01415 uchar modMax[3]; 01416 CvBGCodeBookElem** cbmap; 01417 CvMemStorage* storage; 01418 CvBGCodeBookElem* freeList; 01419 } 01420 CvBGCodeBookModel; 01421 01422 CVAPI(CvBGCodeBookModel*) cvCreateBGCodeBookModel(); 01423 CVAPI(void) cvReleaseBGCodeBookModel( CvBGCodeBookModel** model ); 01424 01425 CVAPI(void) cvBGCodeBookUpdate( CvBGCodeBookModel* model, const CvArr* image, 01426 CvRect roi CV_DEFAULT(cvRect(0,0,0,0)), 01427 const CvArr* mask CV_DEFAULT(0) ); 01428 01429 CVAPI(int) cvBGCodeBookDiff( const CvBGCodeBookModel* model, const CvArr* image, 01430 CvArr* fgmask, CvRect roi CV_DEFAULT(cvRect(0,0,0,0)) ); 01431 01432 CVAPI(void) cvBGCodeBookClearStale( CvBGCodeBookModel* model, int staleThresh, 01433 CvRect roi CV_DEFAULT(cvRect(0,0,0,0)), 01434 const CvArr* mask CV_DEFAULT(0) ); 01435 01436 CVAPI(CvSeq*) cvSegmentFGMask( CvArr *fgmask, int poly1Hull0 CV_DEFAULT(1), 01437 float perimScale CV_DEFAULT(4.f), 01438 CvMemStorage* storage CV_DEFAULT(0), 01439 CvPoint offset CV_DEFAULT(cvPoint(0,0))); 01440 01441 typedef struct CvConDensation 01442 { 01443 int MP; 01444 int DP; 01445 float* DynamMatr; /* Matrix of the linear Dynamics system */ 01446 float* State; /* Vector of State */ 01447 int SamplesNum; /* Number of the Samples */ 01448 float** flSamples; /* arr of the Sample Vectors */ 01449 float** flNewSamples; /* temporary array of the Sample Vectors */ 01450 float* flConfidence; /* Confidence for each Sample */ 01451 float* flCumulative; /* Cumulative confidence */ 01452 float* Temp; /* Temporary vector */ 01453 float* RandomSample; /* RandomVector to update sample set */ 01454 struct CvRandState* RandS; /* Array of structures to generate random vectors */ 01455 } 01456 CvConDensation; 01457 01458 /* Creates ConDensation filter state */ 01459 CVAPI(CvConDensation*) cvCreateConDensation( int dynam_params, 01460 int measure_params, 01461 int sample_count ); 01462 01463 /* Releases ConDensation filter state */ 01464 CVAPI(void) cvReleaseConDensation( CvConDensation** condens ); 01465 01466 /* Updates ConDensation filter by time (predict future state of the system) */ 01467 CVAPI(void) cvConDensUpdateByTime( CvConDensation* condens); 01468 01469 /* Initializes ConDensation filter samples */ 01470 CVAPI(void) cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound ); 01471 01472 #ifdef __cplusplus 01473 } 01474 #endif 01475 01476 #ifdef __cplusplus 01477 01478 /****************************************************************************************\ 01479 * Calibration engine * 01480 \****************************************************************************************/ 01481 01482 typedef enum CvCalibEtalonType 01483 { 01484 CV_CALIB_ETALON_USER = -1, 01485 CV_CALIB_ETALON_CHESSBOARD = 0, 01486 CV_CALIB_ETALON_CHECKERBOARD = CV_CALIB_ETALON_CHESSBOARD 01487 } 01488 CvCalibEtalonType; 01489 01490 class CV_EXPORTS CvCalibFilter 01491 { 01492 public: 01493 /* Constructor & destructor */ 01494 CvCalibFilter(); 01495 virtual ~CvCalibFilter(); 01496 01497 /* Sets etalon type - one for all cameras. 01498 etalonParams is used in case of pre-defined etalons (such as chessboard). 01499 Number of elements in etalonParams is determined by etalonType. 01500 E.g., if etalon type is CV_ETALON_TYPE_CHESSBOARD then: 01501 etalonParams[0] is number of squares per one side of etalon 01502 etalonParams[1] is number of squares per another side of etalon 01503 etalonParams[2] is linear size of squares in the board in arbitrary units. 01504 pointCount & points are used in case of 01505 CV_CALIB_ETALON_USER (user-defined) etalon. */ 01506 virtual bool 01507 SetEtalon( CvCalibEtalonType etalonType, double* etalonParams, 01508 int pointCount = 0, CvPoint2D32f* points = 0 ); 01509 01510 /* Retrieves etalon parameters/or and points */ 01511 virtual CvCalibEtalonType 01512 GetEtalon( int* paramCount = 0, const double** etalonParams = 0, 01513 int* pointCount = 0, const CvPoint2D32f** etalonPoints = 0 ) const; 01514 01515 /* Sets number of cameras calibrated simultaneously. It is equal to 1 initially */ 01516 virtual void SetCameraCount( int cameraCount ); 01517 01518 /* Retrieves number of cameras */ 01519 int GetCameraCount() const { return cameraCount; } 01520 01521 /* Starts cameras calibration */ 01522 virtual bool SetFrames( int totalFrames ); 01523 01524 /* Stops cameras calibration */ 01525 virtual void Stop( bool calibrate = false ); 01526 01527 /* Retrieves number of cameras */ 01528 bool IsCalibrated() const { return isCalibrated; } 01529 01530 /* Feeds another serie of snapshots (one per each camera) to filter. 01531 Etalon points on these images are found automatically. 01532 If the function can't locate points, it returns false */ 01533 virtual bool FindEtalon( IplImage** imgs ); 01534 01535 /* The same but takes matrices */ 01536 virtual bool FindEtalon( CvMat** imgs ); 01537 01538 /* Lower-level function for feeding filter with already found etalon points. 01539 Array of point arrays for each camera is passed. */ 01540 virtual bool Push( const CvPoint2D32f** points = 0 ); 01541 01542 /* Returns total number of accepted frames and, optionally, 01543 total number of frames to collect */ 01544 virtual int GetFrameCount( int* framesTotal = 0 ) const; 01545 01546 /* Retrieves camera parameters for specified camera. 01547 If camera is not calibrated the function returns 0 */ 01548 virtual const CvCamera* GetCameraParams( int idx = 0 ) const; 01549 01550 virtual const CvStereoCamera* GetStereoParams() const; 01551 01552 /* Sets camera parameters for all cameras */ 01553 virtual bool SetCameraParams( CvCamera* params ); 01554 01555 /* Saves all camera parameters to file */ 01556 virtual bool SaveCameraParams( const char* filename ); 01557 01558 /* Loads all camera parameters from file */ 01559 virtual bool LoadCameraParams( const char* filename ); 01560 01561 /* Undistorts images using camera parameters. Some of src pointers can be NULL. */ 01562 virtual bool Undistort( IplImage** src, IplImage** dst ); 01563 01564 /* Undistorts images using camera parameters. Some of src pointers can be NULL. */ 01565 virtual bool Undistort( CvMat** src, CvMat** dst ); 01566 01567 /* Returns array of etalon points detected/partally detected 01568 on the latest frame for idx-th camera */ 01569 virtual bool GetLatestPoints( int idx, CvPoint2D32f** pts, 01570 int* count, bool* found ); 01571 01572 /* Draw the latest detected/partially detected etalon */ 01573 virtual void DrawPoints( IplImage** dst ); 01574 01575 /* Draw the latest detected/partially detected etalon */ 01576 virtual void DrawPoints( CvMat** dst ); 01577 01578 virtual bool Rectify( IplImage** srcarr, IplImage** dstarr ); 01579 virtual bool Rectify( CvMat** srcarr, CvMat** dstarr ); 01580 01581 protected: 01582 01583 enum { MAX_CAMERAS = 3 }; 01584 01585 /* etalon data */ 01586 CvCalibEtalonType etalonType; 01587 int etalonParamCount; 01588 double* etalonParams; 01589 int etalonPointCount; 01590 CvPoint2D32f* etalonPoints; 01591 CvSize imgSize; 01592 CvMat* grayImg; 01593 CvMat* tempImg; 01594 CvMemStorage* storage; 01595 01596 /* camera data */ 01597 int cameraCount; 01598 CvCamera cameraParams[MAX_CAMERAS]; 01599 CvStereoCamera stereo; 01600 CvPoint2D32f* points[MAX_CAMERAS]; 01601 CvMat* undistMap[MAX_CAMERAS][2]; 01602 CvMat* undistImg; 01603 int latestCounts[MAX_CAMERAS]; 01604 CvPoint2D32f* latestPoints[MAX_CAMERAS]; 01605 CvMat* rectMap[MAX_CAMERAS][2]; 01606 01607 /* Added by Valery */ 01608 //CvStereoCamera stereoParams; 01609 01610 int maxPoints; 01611 int framesTotal; 01612 int framesAccepted; 01613 bool isCalibrated; 01614 }; 01615 01616 #include "cvaux.hpp" 01617 #include "cvvidsurv.hpp" 01618 #endif 01619 01620 #endif 01621 01622 /* End of file. */