cvaux.h 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  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. int* ne;
  250. int* ce;
  251. int* fixp; //node with minimal disconnections
  252. int* nod;
  253. int* s; //for selected candidate
  254. int status;
  255. int best_score;
  256. int weighted;
  257. int weighted_edges;
  258. float best_weight;
  259. float* edge_weights;
  260. float* vertex_weights;
  261. float* cur_weight;
  262. float* cand_weight;
  263. } CvCliqueFinder;
  264. #define CLIQUE_TIME_OFF 2
  265. #define CLIQUE_FOUND 1
  266. #define CLIQUE_END 0
  267. /*CVAPI(void) cvStartFindCliques( CvGraph* graph, CvCliqueFinder* finder, int reverse,
  268. int weighted CV_DEFAULT(0), int weighted_edges CV_DEFAULT(0));
  269. CVAPI(int) cvFindNextMaximalClique( CvCliqueFinder* finder, int* clock_rest CV_DEFAULT(0) );
  270. CVAPI(void) cvEndFindCliques( CvCliqueFinder* finder );
  271. CVAPI(void) cvBronKerbosch( CvGraph* graph );*/
  272. /*F///////////////////////////////////////////////////////////////////////////////////////
  273. //
  274. // Name: cvSubgraphWeight
  275. // Purpose: finds weight of subgraph in a graph
  276. // Context:
  277. // Parameters:
  278. // graph - input graph.
  279. // subgraph - sequence of pairwise different ints. These are indices of vertices of subgraph.
  280. // weight_type - describes the way we measure weight.
  281. // one of the following:
  282. // CV_NOT_WEIGHTED - weight of a clique is simply its size
  283. // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
  284. // CV_WEIGHTED_EDGE - the same but edges
  285. // CV_WEIGHTED_ALL - the same but both edges and vertices
  286. // weight_vtx - optional vector of floats, with size = graph->total.
  287. // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
  288. // weights of vertices must be provided. If weight_vtx not zero
  289. // these weights considered to be here, otherwise function assumes
  290. // that vertices of graph are inherited from CvGraphWeightedVtx.
  291. // weight_edge - optional matrix of floats, of width and height = graph->total.
  292. // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  293. // weights of edges ought to be supplied. If weight_edge is not zero
  294. // function finds them here, otherwise function expects
  295. // edges of graph to be inherited from CvGraphWeightedEdge.
  296. // If this parameter is not zero structure of the graph is determined from matrix
  297. // rather than from CvGraphEdge's. In particular, elements corresponding to
  298. // absent edges should be zero.
  299. // Returns:
  300. // weight of subgraph.
  301. // Notes:
  302. //F*/
  303. /*CVAPI(float) cvSubgraphWeight( CvGraph *graph, CvSeq *subgraph,
  304. CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
  305. CvVect32f weight_vtx CV_DEFAULT(0),
  306. CvMatr32f weight_edge CV_DEFAULT(0) );*/
  307. /*F///////////////////////////////////////////////////////////////////////////////////////
  308. //
  309. // Name: cvFindCliqueEx
  310. // Purpose: tries to find clique with maximum possible weight in a graph
  311. // Context:
  312. // Parameters:
  313. // graph - input graph.
  314. // storage - memory storage to be used by the result.
  315. // is_complementary - optional flag showing whether function should seek for clique
  316. // in complementary graph.
  317. // weight_type - describes our notion about weight.
  318. // one of the following:
  319. // CV_NOT_WEIGHTED - weight of a clique is simply its size
  320. // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
  321. // CV_WEIGHTED_EDGE - the same but edges
  322. // CV_WEIGHTED_ALL - the same but both edges and vertices
  323. // weight_vtx - optional vector of floats, with size = graph->total.
  324. // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
  325. // weights of vertices must be provided. If weight_vtx not zero
  326. // these weights considered to be here, otherwise function assumes
  327. // that vertices of graph are inherited from CvGraphWeightedVtx.
  328. // weight_edge - optional matrix of floats, of width and height = graph->total.
  329. // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  330. // weights of edges ought to be supplied. If weight_edge is not zero
  331. // function finds them here, otherwise function expects
  332. // edges of graph to be inherited from CvGraphWeightedEdge.
  333. // Note that in case of CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
  334. // nonzero is_complementary implies nonzero weight_edge.
  335. // start_clique - optional sequence of pairwise different ints. They are indices of
  336. // vertices that shall be present in the output clique.
  337. // subgraph_of_ban - optional sequence of (maybe equal) ints. They are indices of
  338. // vertices that shall not be present in the output clique.
  339. // clique_weight_ptr - optional output parameter. Weight of found clique stored here.
  340. // num_generations - optional number of generations in evolutionary part of algorithm,
  341. // zero forces to return first found clique.
  342. // quality - optional parameter determining degree of required quality/speed tradeoff.
  343. // Must be in the range from 0 to 9.
  344. // 0 is fast and dirty, 9 is slow but hopefully yields good clique.
  345. // Returns:
  346. // sequence of pairwise different ints.
  347. // These are indices of vertices that form found clique.
  348. // Notes:
  349. // in cases of CV_WEIGHTED_EDGE and CV_WEIGHTED_ALL weights should be nonnegative.
  350. // start_clique has a priority over subgraph_of_ban.
  351. //F*/
  352. /*CVAPI(CvSeq*) cvFindCliqueEx( CvGraph *graph, CvMemStorage *storage,
  353. int is_complementary CV_DEFAULT(0),
  354. CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
  355. CvVect32f weight_vtx CV_DEFAULT(0),
  356. CvMatr32f weight_edge CV_DEFAULT(0),
  357. CvSeq *start_clique CV_DEFAULT(0),
  358. CvSeq *subgraph_of_ban CV_DEFAULT(0),
  359. float *clique_weight_ptr CV_DEFAULT(0),
  360. int num_generations CV_DEFAULT(3),
  361. int quality CV_DEFAULT(2) );*/
  362. #define CV_UNDEF_SC_PARAM 12345 //default value of parameters
  363. #define CV_IDP_BIRCHFIELD_PARAM1 25
  364. #define CV_IDP_BIRCHFIELD_PARAM2 5
  365. #define CV_IDP_BIRCHFIELD_PARAM3 12
  366. #define CV_IDP_BIRCHFIELD_PARAM4 15
  367. #define CV_IDP_BIRCHFIELD_PARAM5 25
  368. #define CV_DISPARITY_BIRCHFIELD 0
  369. /*F///////////////////////////////////////////////////////////////////////////
  370. //
  371. // Name: cvFindStereoCorrespondence
  372. // Purpose: find stereo correspondence on stereo-pair
  373. // Context:
  374. // Parameters:
  375. // leftImage - left image of stereo-pair (format 8uC1).
  376. // rightImage - right image of stereo-pair (format 8uC1).
  377. // mode - mode of correspondence retrieval (now CV_DISPARITY_BIRCHFIELD only)
  378. // dispImage - destination disparity image
  379. // maxDisparity - maximal disparity
  380. // param1, param2, param3, param4, param5 - parameters of algorithm
  381. // Returns:
  382. // Notes:
  383. // Images must be rectified.
  384. // All images must have format 8uC1.
  385. //F*/
  386. CVAPI(void)
  387. cvFindStereoCorrespondence(
  388. const CvArr* leftImage, const CvArr* rightImage,
  389. int mode,
  390. CvArr* dispImage,
  391. int maxDisparity,
  392. double param1 CV_DEFAULT(CV_UNDEF_SC_PARAM),
  393. double param2 CV_DEFAULT(CV_UNDEF_SC_PARAM),
  394. double param3 CV_DEFAULT(CV_UNDEF_SC_PARAM),
  395. double param4 CV_DEFAULT(CV_UNDEF_SC_PARAM),
  396. double param5 CV_DEFAULT(CV_UNDEF_SC_PARAM) );
  397. /*****************************************************************************************/
  398. /************ Epiline functions *******************/
  399. typedef struct CvStereoLineCoeff
  400. {
  401. double Xcoef;
  402. double XcoefA;
  403. double XcoefB;
  404. double XcoefAB;
  405. double Ycoef;
  406. double YcoefA;
  407. double YcoefB;
  408. double YcoefAB;
  409. double Zcoef;
  410. double ZcoefA;
  411. double ZcoefB;
  412. double ZcoefAB;
  413. }CvStereoLineCoeff;
  414. typedef struct CvCamera
  415. {
  416. float imgSize[2]; /* size of the camera view, used during calibration */
  417. float matrix[9]; /* intinsic camera parameters: [ fx 0 cx; 0 fy cy; 0 0 1 ] */
  418. float distortion[4]; /* distortion coefficients - two coefficients for radial distortion
  419. and another two for tangential: [ k1 k2 p1 p2 ] */
  420. float rotMatr[9];
  421. float transVect[3]; /* rotation matrix and transition vector relatively
  422. to some reference point in the space. */
  423. }
  424. CvCamera;
  425. typedef struct CvStereoCamera
  426. {
  427. CvCamera* camera[2]; /* two individual camera parameters */
  428. float fundMatr[9]; /* fundamental matrix */
  429. /* New part for stereo */
  430. CvPoint3D32f epipole[2];
  431. CvPoint2D32f quad[2][4]; /* coordinates of destination quadrangle after
  432. epipolar geometry rectification */
  433. double coeffs[2][3][3];/* coefficients for transformation */
  434. CvPoint2D32f border[2][4];
  435. CvSize warpSize;
  436. CvStereoLineCoeff* lineCoeffs;
  437. int needSwapCameras;/* flag set to 1 if need to swap cameras for good reconstruction */
  438. float rotMatrix[9];
  439. float transVector[3];
  440. }
  441. CvStereoCamera;
  442. typedef struct CvContourOrientation
  443. {
  444. float egvals[2];
  445. float egvects[4];
  446. float max, min; // minimum and maximum projections
  447. int imax, imin;
  448. } CvContourOrientation;
  449. #define CV_CAMERA_TO_WARP 1
  450. #define CV_WARP_TO_CAMERA 2
  451. CVAPI(int) icvConvertWarpCoordinates(double coeffs[3][3],
  452. CvPoint2D32f* cameraPoint,
  453. CvPoint2D32f* warpPoint,
  454. int direction);
  455. CVAPI(int) icvGetSymPoint3D( CvPoint3D64d pointCorner,
  456. CvPoint3D64d point1,
  457. CvPoint3D64d point2,
  458. CvPoint3D64d *pointSym2);
  459. CVAPI(void) icvGetPieceLength3D(CvPoint3D64d point1,CvPoint3D64d point2,double* dist);
  460. CVAPI(int) icvCompute3DPoint( double alpha,double betta,
  461. CvStereoLineCoeff* coeffs,
  462. CvPoint3D64d* point);
  463. CVAPI(int) icvCreateConvertMatrVect( CvMatr64d rotMatr1,
  464. CvMatr64d transVect1,
  465. CvMatr64d rotMatr2,
  466. CvMatr64d transVect2,
  467. CvMatr64d convRotMatr,
  468. CvMatr64d convTransVect);
  469. CVAPI(int) icvConvertPointSystem(CvPoint3D64d M2,
  470. CvPoint3D64d* M1,
  471. CvMatr64d rotMatr,
  472. CvMatr64d transVect
  473. );
  474. CVAPI(int) icvComputeCoeffForStereo( CvStereoCamera* stereoCamera);
  475. CVAPI(int) icvGetCrossPieceVector(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f v2_start,CvPoint2D32f v2_end,CvPoint2D32f *cross);
  476. CVAPI(int) icvGetCrossLineDirect(CvPoint2D32f p1,CvPoint2D32f p2,float a,float b,float c,CvPoint2D32f* cross);
  477. CVAPI(float) icvDefinePointPosition(CvPoint2D32f point1,CvPoint2D32f point2,CvPoint2D32f point);
  478. CVAPI(int) icvStereoCalibration( int numImages,
  479. int* nums,
  480. CvSize imageSize,
  481. CvPoint2D32f* imagePoints1,
  482. CvPoint2D32f* imagePoints2,
  483. CvPoint3D32f* objectPoints,
  484. CvStereoCamera* stereoparams
  485. );
  486. CVAPI(int) icvComputeRestStereoParams(CvStereoCamera *stereoparams);
  487. CVAPI(void) cvComputePerspectiveMap( const double coeffs[3][3], CvArr* rectMapX, CvArr* rectMapY );
  488. CVAPI(int) icvComCoeffForLine( CvPoint2D64d point1,
  489. CvPoint2D64d point2,
  490. CvPoint2D64d point3,
  491. CvPoint2D64d point4,
  492. CvMatr64d camMatr1,
  493. CvMatr64d rotMatr1,
  494. CvMatr64d transVect1,
  495. CvMatr64d camMatr2,
  496. CvMatr64d rotMatr2,
  497. CvMatr64d transVect2,
  498. CvStereoLineCoeff* coeffs,
  499. int* needSwapCameras);
  500. CVAPI(int) icvGetDirectionForPoint( CvPoint2D64d point,
  501. CvMatr64d camMatr,
  502. CvPoint3D64d* direct);
  503. CVAPI(int) icvGetCrossLines(CvPoint3D64d point11,CvPoint3D64d point12,
  504. CvPoint3D64d point21,CvPoint3D64d point22,
  505. CvPoint3D64d* midPoint);
  506. CVAPI(int) icvComputeStereoLineCoeffs( CvPoint3D64d pointA,
  507. CvPoint3D64d pointB,
  508. CvPoint3D64d pointCam1,
  509. double gamma,
  510. CvStereoLineCoeff* coeffs);
  511. /*CVAPI(int) icvComputeFundMatrEpipoles ( CvMatr64d camMatr1,
  512. CvMatr64d rotMatr1,
  513. CvVect64d transVect1,
  514. CvMatr64d camMatr2,
  515. CvMatr64d rotMatr2,
  516. CvVect64d transVect2,
  517. CvPoint2D64d* epipole1,
  518. CvPoint2D64d* epipole2,
  519. CvMatr64d fundMatr);*/
  520. CVAPI(int) icvGetAngleLine( CvPoint2D64d startPoint, CvSize imageSize,CvPoint2D64d *point1,CvPoint2D64d *point2);
  521. CVAPI(void) icvGetCoefForPiece( CvPoint2D64d p_start,CvPoint2D64d p_end,
  522. double *a,double *b,double *c,
  523. int* result);
  524. /*CVAPI(void) icvGetCommonArea( CvSize imageSize,
  525. CvPoint2D64d epipole1,CvPoint2D64d epipole2,
  526. CvMatr64d fundMatr,
  527. CvVect64d coeff11,CvVect64d coeff12,
  528. CvVect64d coeff21,CvVect64d coeff22,
  529. int* result);*/
  530. CVAPI(void) icvComputeeInfiniteProject1(CvMatr64d rotMatr,
  531. CvMatr64d camMatr1,
  532. CvMatr64d camMatr2,
  533. CvPoint2D32f point1,
  534. CvPoint2D32f *point2);
  535. CVAPI(void) icvComputeeInfiniteProject2(CvMatr64d rotMatr,
  536. CvMatr64d camMatr1,
  537. CvMatr64d camMatr2,
  538. CvPoint2D32f* point1,
  539. CvPoint2D32f point2);
  540. CVAPI(void) icvGetCrossDirectDirect( CvVect64d direct1,CvVect64d direct2,
  541. CvPoint2D64d *cross,int* result);
  542. CVAPI(void) icvGetCrossPieceDirect( CvPoint2D64d p_start,CvPoint2D64d p_end,
  543. double a,double b,double c,
  544. CvPoint2D64d *cross,int* result);
  545. CVAPI(void) icvGetCrossPiecePiece( CvPoint2D64d p1_start,CvPoint2D64d p1_end,
  546. CvPoint2D64d p2_start,CvPoint2D64d p2_end,
  547. CvPoint2D64d* cross,
  548. int* result);
  549. CVAPI(void) icvGetPieceLength(CvPoint2D64d point1,CvPoint2D64d point2,double* dist);
  550. CVAPI(void) icvGetCrossRectDirect( CvSize imageSize,
  551. double a,double b,double c,
  552. CvPoint2D64d *start,CvPoint2D64d *end,
  553. int* result);
  554. CVAPI(void) icvProjectPointToImage( CvPoint3D64d point,
  555. CvMatr64d camMatr,CvMatr64d rotMatr,CvVect64d transVect,
  556. CvPoint2D64d* projPoint);
  557. CVAPI(void) icvGetQuadsTransform( CvSize imageSize,
  558. CvMatr64d camMatr1,
  559. CvMatr64d rotMatr1,
  560. CvVect64d transVect1,
  561. CvMatr64d camMatr2,
  562. CvMatr64d rotMatr2,
  563. CvVect64d transVect2,
  564. CvSize* warpSize,
  565. double quad1[4][2],
  566. double quad2[4][2],
  567. CvMatr64d fundMatr,
  568. CvPoint3D64d* epipole1,
  569. CvPoint3D64d* epipole2
  570. );
  571. CVAPI(void) icvGetQuadsTransformStruct( CvStereoCamera* stereoCamera);
  572. CVAPI(void) icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera);
  573. CVAPI(void) icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2,
  574. CvPoint2D64d epipole,
  575. CvSize imageSize,
  576. CvPoint2D64d* point11,CvPoint2D64d* point12,
  577. CvPoint2D64d* point21,CvPoint2D64d* point22,
  578. int* result);
  579. CVAPI(void) icvGetMiddleAnglePoint( CvPoint2D64d basePoint,
  580. CvPoint2D64d point1,CvPoint2D64d point2,
  581. CvPoint2D64d* midPoint);
  582. CVAPI(void) icvGetNormalDirect(CvVect64d direct,CvPoint2D64d point,CvVect64d normDirect);
  583. CVAPI(double) icvGetVect(CvPoint2D64d basePoint,CvPoint2D64d point1,CvPoint2D64d point2);
  584. CVAPI(void) icvProjectPointToDirect( CvPoint2D64d point,CvVect64d lineCoeff,
  585. CvPoint2D64d* projectPoint);
  586. CVAPI(void) icvGetDistanceFromPointToDirect( CvPoint2D64d point,CvVect64d lineCoef,double*dist);
  587. CVAPI(IplImage*) icvCreateIsometricImage( IplImage* src, IplImage* dst,
  588. int desired_depth, int desired_num_channels );
  589. CVAPI(void) cvDeInterlace( const CvArr* frame, CvArr* fieldEven, CvArr* fieldOdd );
  590. /*CVAPI(int) icvSelectBestRt( int numImages,
  591. int* numPoints,
  592. CvSize imageSize,
  593. CvPoint2D32f* imagePoints1,
  594. CvPoint2D32f* imagePoints2,
  595. CvPoint3D32f* objectPoints,
  596. CvMatr32f cameraMatrix1,
  597. CvVect32f distortion1,
  598. CvMatr32f rotMatrs1,
  599. CvVect32f transVects1,
  600. CvMatr32f cameraMatrix2,
  601. CvVect32f distortion2,
  602. CvMatr32f rotMatrs2,
  603. CvVect32f transVects2,
  604. CvMatr32f bestRotMatr,
  605. CvVect32f bestTransVect
  606. );*/
  607. /****************************************************************************************\
  608. * Contour Morphing *
  609. \****************************************************************************************/
  610. /* finds correspondence between two contours */
  611. CvSeq* cvCalcContoursCorrespondence( const CvSeq* contour1,
  612. const CvSeq* contour2,
  613. CvMemStorage* storage);
  614. /* morphs contours using the pre-calculated correspondence:
  615. alpha=0 ~ contour1, alpha=1 ~ contour2 */
  616. CvSeq* cvMorphContours( const CvSeq* contour1, const CvSeq* contour2,
  617. CvSeq* corr, double alpha,
  618. CvMemStorage* storage );
  619. /****************************************************************************************\
  620. * Texture Descriptors *
  621. \****************************************************************************************/
  622. #define CV_GLCM_OPTIMIZATION_NONE -2
  623. #define CV_GLCM_OPTIMIZATION_LUT -1
  624. #define CV_GLCM_OPTIMIZATION_HISTOGRAM 0
  625. #define CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST 10
  626. #define CV_GLCMDESC_OPTIMIZATION_ALLOWTRIPLENEST 11
  627. #define CV_GLCMDESC_OPTIMIZATION_HISTOGRAM 4
  628. #define CV_GLCMDESC_ENTROPY 0
  629. #define CV_GLCMDESC_ENERGY 1
  630. #define CV_GLCMDESC_HOMOGENITY 2
  631. #define CV_GLCMDESC_CONTRAST 3
  632. #define CV_GLCMDESC_CLUSTERTENDENCY 4
  633. #define CV_GLCMDESC_CLUSTERSHADE 5
  634. #define CV_GLCMDESC_CORRELATION 6
  635. #define CV_GLCMDESC_CORRELATIONINFO1 7
  636. #define CV_GLCMDESC_CORRELATIONINFO2 8
  637. #define CV_GLCMDESC_MAXIMUMPROBABILITY 9
  638. #define CV_GLCM_ALL 0
  639. #define CV_GLCM_GLCM 1
  640. #define CV_GLCM_DESC 2
  641. typedef struct CvGLCM CvGLCM;
  642. CVAPI(CvGLCM*) cvCreateGLCM( const IplImage* srcImage,
  643. int stepMagnitude,
  644. const int* stepDirections CV_DEFAULT(0),
  645. int numStepDirections CV_DEFAULT(0),
  646. int optimizationType CV_DEFAULT(CV_GLCM_OPTIMIZATION_NONE));
  647. CVAPI(void) cvReleaseGLCM( CvGLCM** GLCM, int flag CV_DEFAULT(CV_GLCM_ALL));
  648. CVAPI(void) cvCreateGLCMDescriptors( CvGLCM* destGLCM,
  649. int descriptorOptimizationType
  650. CV_DEFAULT(CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST));
  651. CVAPI(double) cvGetGLCMDescriptor( CvGLCM* GLCM, int step, int descriptor );
  652. CVAPI(void) cvGetGLCMDescriptorStatistics( CvGLCM* GLCM, int descriptor,
  653. double* average, double* standardDeviation );
  654. CVAPI(IplImage*) cvCreateGLCMImage( CvGLCM* GLCM, int step );
  655. /****************************************************************************************\
  656. * Face eyes&mouth tracking *
  657. \****************************************************************************************/
  658. typedef struct CvFaceTracker CvFaceTracker;
  659. #define CV_NUM_FACE_ELEMENTS 3
  660. enum CV_FACE_ELEMENTS
  661. {
  662. CV_FACE_MOUTH = 0,
  663. CV_FACE_LEFT_EYE = 1,
  664. CV_FACE_RIGHT_EYE = 2
  665. };
  666. CVAPI(CvFaceTracker*) cvInitFaceTracker(CvFaceTracker* pFaceTracking, const IplImage* imgGray,
  667. CvRect* pRects, int nRects);
  668. CVAPI(int) cvTrackFace( CvFaceTracker* pFaceTracker, IplImage* imgGray,
  669. CvRect* pRects, int nRects,
  670. CvPoint* ptRotate, double* dbAngleRotate);
  671. CVAPI(void) cvReleaseFaceTracker(CvFaceTracker** ppFaceTracker);
  672. typedef struct CvFace
  673. {
  674. CvRect MouthRect;
  675. CvRect LeftEyeRect;
  676. CvRect RightEyeRect;
  677. } CvFaceData;
  678. CvSeq * cvFindFace(IplImage * Image,CvMemStorage* storage);
  679. CvSeq * cvPostBoostingFindFace(IplImage * Image,CvMemStorage* storage);
  680. /****************************************************************************************\
  681. * 3D Tracker *
  682. \****************************************************************************************/
  683. typedef unsigned char CvBool;
  684. typedef struct
  685. {
  686. int id;
  687. CvPoint2D32f p; // pgruebele: So we do not loose precision, this needs to be float
  688. } Cv3dTracker2dTrackedObject;
  689. CV_INLINE Cv3dTracker2dTrackedObject cv3dTracker2dTrackedObject(int id, CvPoint2D32f p)
  690. {
  691. Cv3dTracker2dTrackedObject r;
  692. r.id = id;
  693. r.p = p;
  694. return r;
  695. }
  696. typedef struct
  697. {
  698. int id;
  699. CvPoint3D32f p; // location of the tracked object
  700. } Cv3dTrackerTrackedObject;
  701. CV_INLINE Cv3dTrackerTrackedObject cv3dTrackerTrackedObject(int id, CvPoint3D32f p)
  702. {
  703. Cv3dTrackerTrackedObject r;
  704. r.id = id;
  705. r.p = p;
  706. return r;
  707. }
  708. typedef struct
  709. {
  710. CvBool valid;
  711. float mat[4][4]; /* maps camera coordinates to world coordinates */
  712. CvPoint2D32f principal_point; /* copied from intrinsics so this structure */
  713. /* has all the info we need */
  714. } Cv3dTrackerCameraInfo;
  715. typedef struct
  716. {
  717. CvPoint2D32f principal_point;
  718. float focal_length[2];
  719. float distortion[4];
  720. } Cv3dTrackerCameraIntrinsics;
  721. CVAPI(CvBool) cv3dTrackerCalibrateCameras(int num_cameras,
  722. const Cv3dTrackerCameraIntrinsics camera_intrinsics[], /* size is num_cameras */
  723. CvSize etalon_size,
  724. float square_size,
  725. IplImage *samples[], /* size is num_cameras */
  726. Cv3dTrackerCameraInfo camera_info[]); /* size is num_cameras */
  727. CVAPI(int) cv3dTrackerLocateObjects(int num_cameras, int num_objects,
  728. const Cv3dTrackerCameraInfo camera_info[], /* size is num_cameras */
  729. const Cv3dTracker2dTrackedObject tracking_info[], /* size is num_objects*num_cameras */
  730. Cv3dTrackerTrackedObject tracked_objects[]); /* size is num_objects */
  731. /****************************************************************************************
  732. tracking_info is a rectangular array; one row per camera, num_objects elements per row.
  733. The id field of any unused slots must be -1. Ids need not be ordered or consecutive. On
  734. completion, the return value is the number of objects located; i.e., the number of objects
  735. visible by more than one camera. The id field of any unused slots in tracked objects is
  736. set to -1.
  737. ****************************************************************************************/
  738. /****************************************************************************************\
  739. * Skeletons and Linear-Contour Models *
  740. \****************************************************************************************/
  741. typedef enum CvLeeParameters
  742. {
  743. CV_LEE_INT = 0,
  744. CV_LEE_FLOAT = 1,
  745. CV_LEE_DOUBLE = 2,
  746. CV_LEE_AUTO = -1,
  747. CV_LEE_ERODE = 0,
  748. CV_LEE_ZOOM = 1,
  749. CV_LEE_NON = 2
  750. } CvLeeParameters;
  751. #define CV_NEXT_VORONOISITE2D( SITE ) ((SITE)->edge[0]->site[((SITE)->edge[0]->site[0] == (SITE))])
  752. #define CV_PREV_VORONOISITE2D( SITE ) ((SITE)->edge[1]->site[((SITE)->edge[1]->site[0] == (SITE))])
  753. #define CV_FIRST_VORONOIEDGE2D( SITE ) ((SITE)->edge[0])
  754. #define CV_LAST_VORONOIEDGE2D( SITE ) ((SITE)->edge[1])
  755. #define CV_NEXT_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[(EDGE)->site[0] != (SITE)])
  756. #define CV_PREV_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[2 + ((EDGE)->site[0] != (SITE))])
  757. #define CV_VORONOIEDGE2D_BEGINNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] != (SITE))])
  758. #define CV_VORONOIEDGE2D_ENDNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] == (SITE))])
  759. #define CV_TWIN_VORONOISITE2D( SITE, EDGE ) ( (EDGE)->site[((EDGE)->site[0] == (SITE))])
  760. #define CV_VORONOISITE2D_FIELDS() \
  761. struct CvVoronoiNode2D *node[2]; \
  762. struct CvVoronoiEdge2D *edge[2];
  763. typedef struct CvVoronoiSite2D
  764. {
  765. CV_VORONOISITE2D_FIELDS()
  766. struct CvVoronoiSite2D *next[2];
  767. } CvVoronoiSite2D;
  768. #define CV_VORONOIEDGE2D_FIELDS() \
  769. struct CvVoronoiNode2D *node[2]; \
  770. struct CvVoronoiSite2D *site[2]; \
  771. struct CvVoronoiEdge2D *next[4];
  772. typedef struct CvVoronoiEdge2D
  773. {
  774. CV_VORONOIEDGE2D_FIELDS()
  775. } CvVoronoiEdge2D;
  776. #define CV_VORONOINODE2D_FIELDS() \
  777. CV_SET_ELEM_FIELDS(CvVoronoiNode2D) \
  778. CvPoint2D32f pt; \
  779. float radius;
  780. typedef struct CvVoronoiNode2D
  781. {
  782. CV_VORONOINODE2D_FIELDS()
  783. } CvVoronoiNode2D;
  784. #define CV_VORONOIDIAGRAM2D_FIELDS() \
  785. CV_GRAPH_FIELDS() \
  786. CvSet *sites;
  787. typedef struct CvVoronoiDiagram2D
  788. {
  789. CV_VORONOIDIAGRAM2D_FIELDS()
  790. } CvVoronoiDiagram2D;
  791. /* Computes Voronoi Diagram for given polygons with holes */
  792. CVAPI(int) cvVoronoiDiagramFromContour(CvSeq* ContourSeq,
  793. CvVoronoiDiagram2D** VoronoiDiagram,
  794. CvMemStorage* VoronoiStorage,
  795. CvLeeParameters contour_type CV_DEFAULT(CV_LEE_INT),
  796. int contour_orientation CV_DEFAULT(-1),
  797. int attempt_number CV_DEFAULT(10));
  798. /* Computes Voronoi Diagram for domains in given image */
  799. CVAPI(int) cvVoronoiDiagramFromImage(IplImage* pImage,
  800. CvSeq** ContourSeq,
  801. CvVoronoiDiagram2D** VoronoiDiagram,
  802. CvMemStorage* VoronoiStorage,
  803. CvLeeParameters regularization_method CV_DEFAULT(CV_LEE_NON),
  804. float approx_precision CV_DEFAULT(CV_LEE_AUTO));
  805. /* Deallocates the storage */
  806. CVAPI(void) cvReleaseVoronoiStorage(CvVoronoiDiagram2D* VoronoiDiagram,
  807. CvMemStorage** pVoronoiStorage);
  808. /*********************** Linear-Contour Model ****************************/
  809. struct CvLCMEdge;
  810. struct CvLCMNode;
  811. typedef struct CvLCMEdge
  812. {
  813. CV_GRAPH_EDGE_FIELDS()
  814. CvSeq* chain;
  815. float width;
  816. int index1;
  817. int index2;
  818. } CvLCMEdge;
  819. typedef struct CvLCMNode
  820. {
  821. CV_GRAPH_VERTEX_FIELDS()
  822. CvContour* contour;
  823. } CvLCMNode;
  824. /* Computes hybrid model from Voronoi Diagram */
  825. CVAPI(CvGraph*) cvLinearContorModelFromVoronoiDiagram(CvVoronoiDiagram2D* VoronoiDiagram,
  826. float maxWidth);
  827. /* Releases hybrid model storage */
  828. CVAPI(int) cvReleaseLinearContorModelStorage(CvGraph** Graph);
  829. /* two stereo-related functions */
  830. CVAPI(void) cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f vertex[4], double matrix[3][3],
  831. CvArr* rectMap );
  832. /*CVAPI(void) cvInitStereoRectification( CvStereoCamera* params,
  833. CvArr* rectMap1, CvArr* rectMap2,
  834. int do_undistortion );*/
  835. /*************************** View Morphing Functions ************************/
  836. /* The order of the function corresponds to the order they should appear in
  837. the view morphing pipeline */
  838. /* Finds ending points of scanlines on left and right images of stereo-pair */
  839. CVAPI(void) cvMakeScanlines( const CvMatrix3* matrix, CvSize img_size,
  840. int* scanlines1, int* scanlines2,
  841. int* lengths1, int* lengths2,
  842. int* line_count );
  843. /* Grab pixel values from scanlines and stores them sequentially
  844. (some sort of perspective image transform) */
  845. CVAPI(void) cvPreWarpImage( int line_count,
  846. IplImage* img,
  847. uchar* dst,
  848. int* dst_nums,
  849. int* scanlines);
  850. /* Approximate each grabbed scanline by a sequence of runs
  851. (lossy run-length compression) */
  852. CVAPI(void) cvFindRuns( int line_count,
  853. uchar* prewarp1,
  854. uchar* prewarp2,
  855. int* line_lengths1,
  856. int* line_lengths2,
  857. int* runs1,
  858. int* runs2,
  859. int* num_runs1,
  860. int* num_runs2);
  861. /* Compares two sets of compressed scanlines */
  862. CVAPI(void) cvDynamicCorrespondMulti( int line_count,
  863. int* first,
  864. int* first_runs,
  865. int* second,
  866. int* second_runs,
  867. int* first_corr,
  868. int* second_corr);
  869. /* Finds scanline ending coordinates for some intermediate "virtual" camera position */
  870. CVAPI(void) cvMakeAlphaScanlines( int* scanlines1,
  871. int* scanlines2,
  872. int* scanlinesA,
  873. int* lengths,
  874. int line_count,
  875. float alpha);
  876. /* Blends data of the left and right image scanlines to get
  877. pixel values of "virtual" image scanlines */
  878. CVAPI(void) cvMorphEpilinesMulti( int line_count,
  879. uchar* first_pix,
  880. int* first_num,
  881. uchar* second_pix,
  882. int* second_num,
  883. uchar* dst_pix,
  884. int* dst_num,
  885. float alpha,
  886. int* first,
  887. int* first_runs,
  888. int* second,
  889. int* second_runs,
  890. int* first_corr,
  891. int* second_corr);
  892. /* Does reverse warping of the morphing result to make
  893. it fill the destination image rectangle */
  894. CVAPI(void) cvPostWarpImage( int line_count,
  895. uchar* src,
  896. int* src_nums,
  897. IplImage* img,
  898. int* scanlines);
  899. /* Deletes Moire (missed pixels that appear due to discretization) */
  900. CVAPI(void) cvDeleteMoire( IplImage* img );
  901. /****************************************************************************************\
  902. * Background/foreground segmentation *
  903. \****************************************************************************************/
  904. #define CV_BG_MODEL_FGD 0
  905. #define CV_BG_MODEL_MOG 1
  906. #define CV_BG_MODEL_FGD_SIMPLE 2
  907. struct CvBGStatModel;
  908. typedef void (CV_CDECL * CvReleaseBGStatModel)( struct CvBGStatModel** bg_model );
  909. typedef int (CV_CDECL * CvUpdateBGStatModel)( IplImage* curr_frame, struct CvBGStatModel* bg_model );
  910. #define CV_BG_STAT_MODEL_FIELDS() \
  911. int type; /*type of BG model*/ \
  912. CvReleaseBGStatModel release; \
  913. CvUpdateBGStatModel update; \
  914. IplImage* background; /*8UC3 reference background image*/ \
  915. IplImage* foreground; /*8UC1 foreground image*/ \
  916. IplImage** layers; /*8UC3 reference background image, can be null */ \
  917. int layer_count; /* can be zero */ \
  918. CvMemStorage* storage; /*storage for “foreground_regions*/ \
  919. CvSeq* foreground_regions /*foreground object contours*/
  920. typedef struct CvBGStatModel
  921. {
  922. CV_BG_STAT_MODEL_FIELDS();
  923. }
  924. CvBGStatModel;
  925. //
  926. // Releases memory used by BGStatModel
  927. CV_INLINE void cvReleaseBGStatModel( CvBGStatModel** bg_model )
  928. {
  929. if( bg_model && *bg_model && (*bg_model)->release )
  930. (*bg_model)->release( bg_model );
  931. }
  932. // Updates statistical model and returns number of found foreground regions
  933. CV_INLINE int cvUpdateBGStatModel( IplImage* current_frame, CvBGStatModel* bg_model )
  934. {
  935. return bg_model && bg_model->update ? bg_model->update( current_frame, bg_model ) : 0;
  936. }
  937. // Performs FG post-processing using segmentation
  938. // (all pixels of a region will be classified as foreground if majority of pixels of the region are FG).
  939. // parameters:
  940. // segments - pointer to result of segmentation (for example MeanShiftSegmentation)
  941. // bg_model - pointer to CvBGStatModel structure
  942. CVAPI(void) cvRefineForegroundMaskBySegm( CvSeq* segments, CvBGStatModel* bg_model );
  943. /* Common use change detection function */
  944. CVAPI(int) cvChangeDetection( IplImage* prev_frame,
  945. IplImage* curr_frame,
  946. IplImage* change_mask );
  947. /*
  948. Interface of ACM MM2003 algorithm
  949. (Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
  950. "Foreground Object Detection from Videos Containing Complex Background. ACM MM2003")
  951. */
  952. /* default paremeters of foreground detection algorithm */
  953. #define CV_BGFG_FGD_LC 128
  954. #define CV_BGFG_FGD_N1C 15
  955. #define CV_BGFG_FGD_N2C 25
  956. #define CV_BGFG_FGD_LCC 64
  957. #define CV_BGFG_FGD_N1CC 25
  958. #define CV_BGFG_FGD_N2CC 40
  959. /* BG reference image update parameter */
  960. #define CV_BGFG_FGD_ALPHA_1 0.1f
  961. /* stat model update parameter
  962. 0.002f ~ 1K frame(~45sec), 0.005 ~ 18sec (if 25fps and absolutely static BG) */
  963. #define CV_BGFG_FGD_ALPHA_2 0.005f
  964. /* start value for alpha parameter (to fast initiate statistic model) */
  965. #define CV_BGFG_FGD_ALPHA_3 0.1f
  966. #define CV_BGFG_FGD_DELTA 2
  967. #define CV_BGFG_FGD_T 0.9f
  968. #define CV_BGFG_FGD_MINAREA 15.f
  969. #define CV_BGFG_FGD_BG_UPDATE_TRESH 0.5f
  970. typedef struct CvFGDStatModelParams
  971. {
  972. int Lc, N1c, N2c, Lcc, N1cc, N2cc, is_obj_without_holes, perform_morphing;
  973. float alpha1, alpha2, alpha3, delta, T, minArea;
  974. }
  975. CvFGDStatModelParams;
  976. typedef struct CvBGPixelCStatTable
  977. {
  978. float Pv, Pvb;
  979. uchar v[3];
  980. }
  981. CvBGPixelCStatTable;
  982. typedef struct CvBGPixelCCStatTable
  983. {
  984. float Pv, Pvb;
  985. uchar v[6];
  986. }
  987. CvBGPixelCCStatTable;
  988. typedef struct CvBGPixelStat
  989. {
  990. float Pbc;
  991. float Pbcc;
  992. CvBGPixelCStatTable* ctable;
  993. CvBGPixelCCStatTable* cctable;
  994. uchar is_trained_st_model;
  995. uchar is_trained_dyn_model;
  996. }
  997. CvBGPixelStat;
  998. typedef struct CvFGDStatModel
  999. {
  1000. CV_BG_STAT_MODEL_FIELDS();
  1001. CvBGPixelStat* pixel_stat;
  1002. IplImage* Ftd;
  1003. IplImage* Fbd;
  1004. IplImage* prev_frame;
  1005. CvFGDStatModelParams params;
  1006. }
  1007. CvFGDStatModel;
  1008. /* Creates FGD model */
  1009. CVAPI(CvBGStatModel*) cvCreateFGDStatModel( IplImage* first_frame,
  1010. CvFGDStatModelParams* parameters CV_DEFAULT(NULL));
  1011. /*
  1012. Interface of Gaussian mixture algorithm
  1013. (P. KadewTraKuPong and R. Bowden,
  1014. "An improved adaptive background mixture model for real-time tracking with shadow detection"
  1015. in Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001.")
  1016. */
  1017. #define CV_BGFG_MOG_MAX_NGAUSSIANS 500
  1018. /* default parameters of gaussian background detection algorithm */
  1019. #define CV_BGFG_MOG_BACKGROUND_THRESHOLD 0.7 /* threshold sum of weights for background test */
  1020. #define CV_BGFG_MOG_STD_THRESHOLD 2.5 /* lambda=2.5 is 99% */
  1021. #define CV_BGFG_MOG_WINDOW_SIZE 200 /* Learning rate; alpha = 1/CV_GBG_WINDOW_SIZE */
  1022. #define CV_BGFG_MOG_NGAUSSIANS 5 /* = K = number of Gaussians in mixture */
  1023. #define CV_BGFG_MOG_WEIGHT_INIT 0.05
  1024. #define CV_BGFG_MOG_SIGMA_INIT 30
  1025. #define CV_BGFG_MOG_MINAREA 15.f
  1026. #define CV_BGFG_MOG_NCOLORS 3
  1027. typedef struct CvGaussBGStatModelParams
  1028. {
  1029. int win_size; /* = 1/alpha */
  1030. int n_gauss;
  1031. double bg_threshold, std_threshold, minArea;
  1032. double weight_init, variance_init;
  1033. }CvGaussBGStatModelParams;
  1034. typedef struct CvGaussBGValues
  1035. {
  1036. int match_sum;
  1037. double weight;
  1038. double variance[CV_BGFG_MOG_NCOLORS];
  1039. double mean[CV_BGFG_MOG_NCOLORS];
  1040. }
  1041. CvGaussBGValues;
  1042. typedef struct CvGaussBGPoint
  1043. {
  1044. CvGaussBGValues* g_values;
  1045. }
  1046. CvGaussBGPoint;
  1047. typedef struct CvGaussBGModel
  1048. {
  1049. CV_BG_STAT_MODEL_FIELDS();
  1050. CvGaussBGStatModelParams params;
  1051. CvGaussBGPoint* g_point;
  1052. int countFrames;
  1053. }
  1054. CvGaussBGModel;
  1055. /* Creates Gaussian mixture background model */
  1056. CVAPI(CvBGStatModel*) cvCreateGaussianBGModel( IplImage* first_frame,
  1057. CvGaussBGStatModelParams* parameters CV_DEFAULT(NULL));
  1058. #ifdef __cplusplus
  1059. }
  1060. #endif
  1061. #ifdef __cplusplus
  1062. /****************************************************************************************\
  1063. * Calibration engine *
  1064. \****************************************************************************************/
  1065. typedef enum CvCalibEtalonType
  1066. {
  1067. CV_CALIB_ETALON_USER = -1,
  1068. CV_CALIB_ETALON_CHESSBOARD = 0,
  1069. CV_CALIB_ETALON_CHECKERBOARD = CV_CALIB_ETALON_CHESSBOARD
  1070. }
  1071. CvCalibEtalonType;
  1072. class CV_EXPORTS CvCalibFilter
  1073. {
  1074. public:
  1075. /* Constructor & destructor */
  1076. CvCalibFilter();
  1077. virtual ~CvCalibFilter();
  1078. /* Sets etalon type - one for all cameras.
  1079. etalonParams is used in case of pre-defined etalons (such as chessboard).
  1080. Number of elements in etalonParams is determined by etalonType.
  1081. E.g., if etalon type is CV_ETALON_TYPE_CHESSBOARD then:
  1082. etalonParams[0] is number of squares per one side of etalon
  1083. etalonParams[1] is number of squares per another side of etalon
  1084. etalonParams[2] is linear size of squares in the board in arbitrary units.
  1085. pointCount & points are used in case of
  1086. CV_CALIB_ETALON_USER (user-defined) etalon. */
  1087. virtual bool
  1088. SetEtalon( CvCalibEtalonType etalonType, double* etalonParams,
  1089. int pointCount = 0, CvPoint2D32f* points = 0 );
  1090. /* Retrieves etalon parameters/or and points */
  1091. virtual CvCalibEtalonType
  1092. GetEtalon( int* paramCount = 0, const double** etalonParams = 0,
  1093. int* pointCount = 0, const CvPoint2D32f** etalonPoints = 0 ) const;
  1094. /* Sets number of cameras calibrated simultaneously. It is equal to 1 initially */
  1095. virtual void SetCameraCount( int cameraCount );
  1096. /* Retrieves number of cameras */
  1097. int GetCameraCount() const { return cameraCount; }
  1098. /* Starts cameras calibration */
  1099. virtual bool SetFrames( int totalFrames );
  1100. /* Stops cameras calibration */
  1101. virtual void Stop( bool calibrate = false );
  1102. /* Retrieves number of cameras */
  1103. bool IsCalibrated() const { return isCalibrated; }
  1104. /* Feeds another serie of snapshots (one per each camera) to filter.
  1105. Etalon points on these images are found automatically.
  1106. If the function can't locate points, it returns false */
  1107. virtual bool FindEtalon( IplImage** imgs );
  1108. /* The same but takes matrices */
  1109. virtual bool FindEtalon( CvMat** imgs );
  1110. /* Lower-level function for feeding filter with already found etalon points.
  1111. Array of point arrays for each camera is passed. */
  1112. virtual bool Push( const CvPoint2D32f** points = 0 );
  1113. /* Returns total number of accepted frames and, optionally,
  1114. total number of frames to collect */
  1115. virtual int GetFrameCount( int* framesTotal = 0 ) const;
  1116. /* Retrieves camera parameters for specified camera.
  1117. If camera is not calibrated the function returns 0 */
  1118. virtual const CvCamera* GetCameraParams( int idx = 0 ) const;
  1119. virtual const CvStereoCamera* GetStereoParams() const;
  1120. /* Sets camera parameters for all cameras */
  1121. virtual bool SetCameraParams( CvCamera* params );
  1122. /* Saves all camera parameters to file */
  1123. virtual bool SaveCameraParams( const char* filename );
  1124. /* Loads all camera parameters from file */
  1125. virtual bool LoadCameraParams( const char* filename );
  1126. /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
  1127. virtual bool Undistort( IplImage** src, IplImage** dst );
  1128. /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
  1129. virtual bool Undistort( CvMat** src, CvMat** dst );
  1130. /* Returns array of etalon points detected/partally detected
  1131. on the latest frame for idx-th camera */
  1132. virtual bool GetLatestPoints( int idx, CvPoint2D32f** pts,
  1133. int* count, bool* found );
  1134. /* Draw the latest detected/partially detected etalon */
  1135. virtual void DrawPoints( IplImage** dst );
  1136. /* Draw the latest detected/partially detected etalon */
  1137. virtual void DrawPoints( CvMat** dst );
  1138. virtual bool Rectify( IplImage** srcarr, IplImage** dstarr );
  1139. virtual bool Rectify( CvMat** srcarr, CvMat** dstarr );
  1140. protected:
  1141. enum { MAX_CAMERAS = 3 };
  1142. /* etalon data */
  1143. CvCalibEtalonType etalonType;
  1144. int etalonParamCount;
  1145. double* etalonParams;
  1146. int etalonPointCount;
  1147. CvPoint2D32f* etalonPoints;
  1148. CvSize imgSize;
  1149. CvMat* grayImg;
  1150. CvMat* tempImg;
  1151. CvMemStorage* storage;
  1152. /* camera data */
  1153. int cameraCount;
  1154. CvCamera cameraParams[MAX_CAMERAS];
  1155. CvStereoCamera stereo;
  1156. CvPoint2D32f* points[MAX_CAMERAS];
  1157. CvMat* undistMap[MAX_CAMERAS][2];
  1158. CvMat* undistImg;
  1159. int latestCounts[MAX_CAMERAS];
  1160. CvPoint2D32f* latestPoints[MAX_CAMERAS];
  1161. CvMat* rectMap[MAX_CAMERAS][2];
  1162. /* Added by Valery */
  1163. //CvStereoCamera stereoParams;
  1164. int maxPoints;
  1165. int framesTotal;
  1166. int framesAccepted;
  1167. bool isCalibrated;
  1168. };
  1169. #include "cvaux.hpp"
  1170. #include "cvvidsurv.hpp"
  1171. #include "cvmat.hpp"
  1172. #endif
  1173. #endif
  1174. /* End of file. */