opencv 2.2.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
legacy.hpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef __OPENCV_LEGACY_HPP__
43 #define __OPENCV_LEGACY_HPP__
44
45 #include "opencv2/imgproc/imgproc.hpp"
46 #include "opencv2/imgproc/imgproc_c.h"
47 #include "opencv2/features2d/features2d.hpp"
48 #include "opencv2/calib3d/calib3d.hpp"
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 CVAPI(CvSeq*) cvSegmentImage( const CvArr* srcarr, CvArr* dstarr,
55 double canny_threshold,
56 double ffill_threshold,
57 CvMemStorage* storage );
58
59 /****************************************************************************************\
60 * Eigen objects *
61 \****************************************************************************************/
62
63 typedef int (CV_CDECL * CvCallback)(int index, void* buffer, void* user_data);
64 typedef union
65 {
66 CvCallback callback;
67 void* data;
68 }
69 CvInput;
70
71 #define CV_EIGOBJ_NO_CALLBACK 0
72 #define CV_EIGOBJ_INPUT_CALLBACK 1
73 #define CV_EIGOBJ_OUTPUT_CALLBACK 2
74 #define CV_EIGOBJ_BOTH_CALLBACK 3
75
76 /* Calculates covariation matrix of a set of arrays */
77 CVAPI(void) cvCalcCovarMatrixEx( int nObjects, void* input, int ioFlags,
78 int ioBufSize, uchar* buffer, void* userData,
79 IplImage* avg, float* covarMatrix );
80
81 /* Calculates eigen values and vectors of covariation matrix of a set of
82 arrays */
83 CVAPI(void) cvCalcEigenObjects( int nObjects, void* input, void* output,
84 int ioFlags, int ioBufSize, void* userData,
85 CvTermCriteria* calcLimit, IplImage* avg,
86 float* eigVals );
87
88 /* Calculates dot product (obj - avg) * eigObj (i.e. projects image to eigen vector) */
89 CVAPI(double) cvCalcDecompCoeff( IplImage* obj, IplImage* eigObj, IplImage* avg );
90
91 /* Projects image to eigen space (finds all decomposion coefficients */
92 CVAPI(void) cvEigenDecomposite( IplImage* obj, int nEigObjs, void* eigInput,
93 int ioFlags, void* userData, IplImage* avg,
94 float* coeffs );
95
96 /* Projects original objects used to calculate eigen space basis to that space */
97 CVAPI(void) cvEigenProjection( void* eigInput, int nEigObjs, int ioFlags,
98 void* userData, float* coeffs, IplImage* avg,
99 IplImage* proj );
100
101 /****************************************************************************************\
102 * 1D/2D HMM *
103 \****************************************************************************************/
104
105 typedef struct CvImgObsInfo
106 {
107 int obs_x;
108 int obs_y;
109 int obs_size;
110 float* obs;//consequtive observations
111
112 int* state;/* arr of pairs superstate/state to which observation belong */
113 int* mix; /* number of mixture to which observation belong */
114
115 } CvImgObsInfo;/*struct for 1 image*/
116
117 typedef CvImgObsInfo Cv1DObsInfo;
118
119 typedef struct CvEHMMState
120 {
121 int num_mix; /*number of mixtures in this state*/
122 float* mu; /*mean vectors corresponding to each mixture*/
123 float* inv_var; /* square root of inversed variances corresp. to each mixture*/
124 float* log_var_val; /* sum of 0.5 (LN2PI + ln(variance[i]) ) for i=1,n */
125 float* weight; /*array of mixture weights. Summ of all weights in state is 1. */
126
127 } CvEHMMState;
128
129 typedef struct CvEHMM
130 {
131 int level; /* 0 - lowest(i.e its states are real states), ..... */
132 int num_states; /* number of HMM states */
133 float* transP;/*transition probab. matrices for states */
134 float** obsProb; /* if level == 0 - array of brob matrices corresponding to hmm
135 if level == 1 - martix of matrices */
136 union
137 {
138 CvEHMMState* state; /* if level == 0 points to real states array,
139 if not - points to embedded hmms */
140 struct CvEHMM* ehmm; /* pointer to an embedded model or NULL, if it is a leaf */
141 } u;
142
143 } CvEHMM;
144
145 /*CVAPI(int) icvCreate1DHMM( CvEHMM** this_hmm,
146 int state_number, int* num_mix, int obs_size );
147
148 CVAPI(int) icvRelease1DHMM( CvEHMM** phmm );
149
150 CVAPI(int) icvUniform1DSegm( Cv1DObsInfo* obs_info, CvEHMM* hmm );
151
152 CVAPI(int) icvInit1DMixSegm( Cv1DObsInfo** obs_info_array, int num_img, CvEHMM* hmm);
153
154 CVAPI(int) icvEstimate1DHMMStateParams( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm);
155
156 CVAPI(int) icvEstimate1DObsProb( CvImgObsInfo* obs_info, CvEHMM* hmm );
157
158 CVAPI(int) icvEstimate1DTransProb( Cv1DObsInfo** obs_info_array,
159 int num_seq,
160 CvEHMM* hmm );
161
162 CVAPI(float) icvViterbi( Cv1DObsInfo* obs_info, CvEHMM* hmm);
163
164 CVAPI(int) icv1DMixSegmL2( CvImgObsInfo** obs_info_array, int num_img, CvEHMM* hmm );*/
165
166 /*********************************** Embedded HMMs *************************************/
167
168 /* Creates 2D HMM */
169 CVAPI(CvEHMM*) cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );
170
171 /* Releases HMM */
172 CVAPI(void) cvRelease2DHMM( CvEHMM** hmm );
173
174 #define CV_COUNT_OBS(roi, win, delta, numObs ) \
175 { \
176 (numObs)->width =((roi)->width -(win)->width +(delta)->width)/(delta)->width; \
177 (numObs)->height =((roi)->height -(win)->height +(delta)->height)/(delta)->height;\
178 }
179
180 /* Creates storage for observation vectors */
181 CVAPI(CvImgObsInfo*) cvCreateObsInfo( CvSize numObs, int obsSize );
182
183 /* Releases storage for observation vectors */
184 CVAPI(void) cvReleaseObsInfo( CvImgObsInfo** obs_info );
185
186
187 /* The function takes an image on input and and returns the sequnce of observations
188 to be used with an embedded HMM; Each observation is top-left block of DCT
189 coefficient matrix */
190 CVAPI(void) cvImgToObs_DCT( const CvArr* arr, float* obs, CvSize dctSize,
191 CvSize obsSize, CvSize delta );
192
193
194 /* Uniformly segments all observation vectors extracted from image */
195 CVAPI(void) cvUniformImgSegm( CvImgObsInfo* obs_info, CvEHMM* ehmm );
196
197 /* Does mixture segmentation of the states of embedded HMM */
198 CVAPI(void) cvInitMixSegm( CvImgObsInfo** obs_info_array,
199 int num_img, CvEHMM* hmm );
200
201 /* Function calculates means, variances, weights of every Gaussian mixture
202 of every low-level state of embedded HMM */
203 CVAPI(void) cvEstimateHMMStateParams( CvImgObsInfo** obs_info_array,
204 int num_img, CvEHMM* hmm );
205
206 /* Function computes transition probability matrices of embedded HMM
207 given observations segmentation */
208 CVAPI(void) cvEstimateTransProb( CvImgObsInfo** obs_info_array,
209 int num_img, CvEHMM* hmm );
210
211 /* Function computes probabilities of appearing observations at any state
212 (i.e. computes P(obs|state) for every pair(obs,state)) */
213 CVAPI(void) cvEstimateObsProb( CvImgObsInfo* obs_info,
214 CvEHMM* hmm );
215
216 /* Runs Viterbi algorithm for embedded HMM */
217 CVAPI(float) cvEViterbi( CvImgObsInfo* obs_info, CvEHMM* hmm );
218
219
220 /* Function clusters observation vectors from several images
221 given observations segmentation.
222 Euclidean distance used for clustering vectors.
223 Centers of clusters are given means of every mixture */
224 CVAPI(void) cvMixSegmL2( CvImgObsInfo** obs_info_array,
225 int num_img, CvEHMM* hmm );
226
227 /****************************************************************************************\
228 * A few functions from old stereo gesture recognition demosions *
229 \****************************************************************************************/
230
231 /* Creates hand mask image given several points on the hand */
232 CVAPI(void) cvCreateHandMask( CvSeq* hand_points,
233 IplImage *img_mask, CvRect *roi);
234
235 /* Finds hand region in range image data */
236 CVAPI(void) cvFindHandRegion (CvPoint3D32f* points, int count,
237 CvSeq* indexs,
238 float* line, CvSize2D32f size, int flag,
239 CvPoint3D32f* center,
240 CvMemStorage* storage, CvSeq **numbers);
241
242 /* Finds hand region in range image data (advanced version) */
243 CVAPI(void) cvFindHandRegionA( CvPoint3D32f* points, int count,
244 CvSeq* indexs,
245 float* line, CvSize2D32f size, int jc,
246 CvPoint3D32f* center,
247 CvMemStorage* storage, CvSeq **numbers);
248
249 /* Calculates the cooficients of the homography matrix */
250 CVAPI(void) cvCalcImageHomography( float* line, CvPoint3D32f* center,
251 float* intrinsic, float* homography );
252
253 /****************************************************************************************\
254 * Additional operations on Subdivisions *
255 \****************************************************************************************/
256
257 // paints voronoi diagram: just demo function
258 CVAPI(void) icvDrawMosaic( CvSubdiv2D* subdiv, IplImage* src, IplImage* dst );
259
260 // checks planar subdivision for correctness. It is not an absolute check,
261 // but it verifies some relations between quad-edges
262 CVAPI(int) icvSubdiv2DCheck( CvSubdiv2D* subdiv );
263
264 // returns squared distance between two 2D points with floating-point coordinates.
265 CV_INLINE double icvSqDist2D32f( CvPoint2D32f pt1, CvPoint2D32f pt2 )
266 {
267 double dx = pt1.x - pt2.x;
268 double dy = pt1.y - pt2.y;
269
270 return dx*dx + dy*dy;
271 }
272
273
274 /****************************************************************************************\
275 * More operations on sequences *
276 \****************************************************************************************/
277
278 /*****************************************************************************************/
279
280 #define CV_CURRENT_INT( reader ) (*((int *)(reader).ptr))
281 #define CV_PREV_INT( reader ) (*((int *)(reader).prev_elem))
282
283 #define CV_GRAPH_WEIGHTED_VERTEX_FIELDS() CV_GRAPH_VERTEX_FIELDS()\
284 float weight;
285
286 #define CV_GRAPH_WEIGHTED_EDGE_FIELDS() CV_GRAPH_EDGE_FIELDS()
287
288 typedef struct CvGraphWeightedVtx
289 {
290 CV_GRAPH_WEIGHTED_VERTEX_FIELDS()
291 } CvGraphWeightedVtx;
292
293 typedef struct CvGraphWeightedEdge
294 {
295 CV_GRAPH_WEIGHTED_EDGE_FIELDS()
296 } CvGraphWeightedEdge;
297
298 typedef enum CvGraphWeightType
299 {
300 CV_NOT_WEIGHTED,
301 CV_WEIGHTED_VTX,
302 CV_WEIGHTED_EDGE,
303 CV_WEIGHTED_ALL
304 } CvGraphWeightType;
305
306
307 /* Calculates histogram of a contour */
308 CVAPI(void) cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
309
310 #define CV_DOMINANT_IPAN 1
311
312 /* Finds high-curvature points of the contour */
313 CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage,
314 int method CV_DEFAULT(CV_DOMINANT_IPAN),
315 double parameter1 CV_DEFAULT(0),
316 double parameter2 CV_DEFAULT(0),
317 double parameter3 CV_DEFAULT(0),
318 double parameter4 CV_DEFAULT(0));
319
320 /*****************************************************************************************/
321
322
323 /*******************************Stereo correspondence*************************************/
324
325 typedef struct CvCliqueFinder
326 {
327 CvGraph* graph;
328 int** adj_matr;
329 int N; //graph size
330
331 // stacks, counters etc/
332 int k; //stack size
333 int* current_comp;
334 int** All;
335
336 int* ne;
337 int* ce;
338 int* fixp; //node with minimal disconnections
339 int* nod;
340 int* s; //for selected candidate
341 int status;
342 int best_score;
343 int weighted;
344 int weighted_edges;
345 float best_weight;
346 float* edge_weights;
347 float* vertex_weights;
348 float* cur_weight;
349 float* cand_weight;
350
351 } CvCliqueFinder;
352
353 #define CLIQUE_TIME_OFF 2
354 #define CLIQUE_FOUND 1
355 #define CLIQUE_END 0
356
357 /*CVAPI(void) cvStartFindCliques( CvGraph* graph, CvCliqueFinder* finder, int reverse,
358 int weighted CV_DEFAULT(0), int weighted_edges CV_DEFAULT(0));
359 CVAPI(int) cvFindNextMaximalClique( CvCliqueFinder* finder, int* clock_rest CV_DEFAULT(0) );
360 CVAPI(void) cvEndFindCliques( CvCliqueFinder* finder );
361
362 CVAPI(void) cvBronKerbosch( CvGraph* graph );*/
363
364
365 /*F///////////////////////////////////////////////////////////////////////////////////////
366 //
367 // Name: cvSubgraphWeight
368 // Purpose: finds weight of subgraph in a graph
369 // Context:
370 // Parameters:
371 // graph - input graph.
372 // subgraph - sequence of pairwise different ints. These are indices of vertices of subgraph.
373 // weight_type - describes the way we measure weight.
374 // one of the following:
375 // CV_NOT_WEIGHTED - weight of a clique is simply its size
376 // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
377 // CV_WEIGHTED_EDGE - the same but edges
378 // CV_WEIGHTED_ALL - the same but both edges and vertices
379 // weight_vtx - optional vector of floats, with size = graph->total.
380 // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
381 // weights of vertices must be provided. If weight_vtx not zero
382 // these weights considered to be here, otherwise function assumes
383 // that vertices of graph are inherited from CvGraphWeightedVtx.
384 // weight_edge - optional matrix of floats, of width and height = graph->total.
385 // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
386 // weights of edges ought to be supplied. If weight_edge is not zero
387 // function finds them here, otherwise function expects
388 // edges of graph to be inherited from CvGraphWeightedEdge.
389 // If this parameter is not zero structure of the graph is determined from matrix
390 // rather than from CvGraphEdge's. In particular, elements corresponding to
391 // absent edges should be zero.
392 // Returns:
393 // weight of subgraph.
394 // Notes:
395 //F*/
396 /*CVAPI(float) cvSubgraphWeight( CvGraph *graph, CvSeq *subgraph,
397 CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
398 CvVect32f weight_vtx CV_DEFAULT(0),
399 CvMatr32f weight_edge CV_DEFAULT(0) );*/
400
401
402 /*F///////////////////////////////////////////////////////////////////////////////////////
403 //
404 // Name: cvFindCliqueEx
405 // Purpose: tries to find clique with maximum possible weight in a graph
406 // Context:
407 // Parameters:
408 // graph - input graph.
409 // storage - memory storage to be used by the result.
410 // is_complementary - optional flag showing whether function should seek for clique
411 // in complementary graph.
412 // weight_type - describes our notion about weight.
413 // one of the following:
414 // CV_NOT_WEIGHTED - weight of a clique is simply its size
415 // CV_WEIGHTED_VTX - weight of a clique is the sum of weights of its vertices
416 // CV_WEIGHTED_EDGE - the same but edges
417 // CV_WEIGHTED_ALL - the same but both edges and vertices
418 // weight_vtx - optional vector of floats, with size = graph->total.
419 // If weight_type is either CV_WEIGHTED_VTX or CV_WEIGHTED_ALL
420 // weights of vertices must be provided. If weight_vtx not zero
421 // these weights considered to be here, otherwise function assumes
422 // that vertices of graph are inherited from CvGraphWeightedVtx.
423 // weight_edge - optional matrix of floats, of width and height = graph->total.
424 // If weight_type is either CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
425 // weights of edges ought to be supplied. If weight_edge is not zero
426 // function finds them here, otherwise function expects
427 // edges of graph to be inherited from CvGraphWeightedEdge.
428 // Note that in case of CV_WEIGHTED_EDGE or CV_WEIGHTED_ALL
429 // nonzero is_complementary implies nonzero weight_edge.
430 // start_clique - optional sequence of pairwise different ints. They are indices of
431 // vertices that shall be present in the output clique.
432 // subgraph_of_ban - optional sequence of (maybe equal) ints. They are indices of
433 // vertices that shall not be present in the output clique.
434 // clique_weight_ptr - optional output parameter. Weight of found clique stored here.
435 // num_generations - optional number of generations in evolutionary part of algorithm,
436 // zero forces to return first found clique.
437 // quality - optional parameter determining degree of required quality/speed tradeoff.
438 // Must be in the range from 0 to 9.
439 // 0 is fast and dirty, 9 is slow but hopefully yields good clique.
440 // Returns:
441 // sequence of pairwise different ints.
442 // These are indices of vertices that form found clique.
443 // Notes:
444 // in cases of CV_WEIGHTED_EDGE and CV_WEIGHTED_ALL weights should be nonnegative.
445 // start_clique has a priority over subgraph_of_ban.
446 //F*/
447 /*CVAPI(CvSeq*) cvFindCliqueEx( CvGraph *graph, CvMemStorage *storage,
448 int is_complementary CV_DEFAULT(0),
449 CvGraphWeightType weight_type CV_DEFAULT(CV_NOT_WEIGHTED),
450 CvVect32f weight_vtx CV_DEFAULT(0),
451 CvMatr32f weight_edge CV_DEFAULT(0),
452 CvSeq *start_clique CV_DEFAULT(0),
453 CvSeq *subgraph_of_ban CV_DEFAULT(0),
454 float *clique_weight_ptr CV_DEFAULT(0),
455 int num_generations CV_DEFAULT(3),
456 int quality CV_DEFAULT(2) );*/
457
458
459 #define CV_UNDEF_SC_PARAM 12345 //default value of parameters
460
461 #define CV_IDP_BIRCHFIELD_PARAM1 25
462 #define CV_IDP_BIRCHFIELD_PARAM2 5
463 #define CV_IDP_BIRCHFIELD_PARAM3 12
464 #define CV_IDP_BIRCHFIELD_PARAM4 15
465 #define CV_IDP_BIRCHFIELD_PARAM5 25
466
467
468 #define CV_DISPARITY_BIRCHFIELD 0
469
470
471 /*F///////////////////////////////////////////////////////////////////////////
472 //
473 // Name: cvFindStereoCorrespondence
474 // Purpose: find stereo correspondence on stereo-pair
475 // Context:
476 // Parameters:
477 // leftImage - left image of stereo-pair (format 8uC1).
478 // rightImage - right image of stereo-pair (format 8uC1).
479 // mode - mode of correspondence retrieval (now CV_DISPARITY_BIRCHFIELD only)
480 // dispImage - destination disparity image
481 // maxDisparity - maximal disparity
482 // param1, param2, param3, param4, param5 - parameters of algorithm
483 // Returns:
484 // Notes:
485 // Images must be rectified.
486 // All images must have format 8uC1.
487 //F*/
488 CVAPI(void)
489 cvFindStereoCorrespondence(
490 const CvArr* leftImage, const CvArr* rightImage,
491 int mode,
492 CvArr* dispImage,
493 int maxDisparity,
494 double param1 CV_DEFAULT(CV_UNDEF_SC_PARAM),
495 double param2 CV_DEFAULT(CV_UNDEF_SC_PARAM),
496 double param3 CV_DEFAULT(CV_UNDEF_SC_PARAM),
497 double param4 CV_DEFAULT(CV_UNDEF_SC_PARAM),
498 double param5 CV_DEFAULT(CV_UNDEF_SC_PARAM) );
499
500 /*****************************************************************************************/
501 /************ Epiline functions *******************/
502
503
504
505 typedef struct CvStereoLineCoeff
506 {
507 double Xcoef;
508 double XcoefA;
509 double XcoefB;
510 double XcoefAB;
511
512 double Ycoef;
513 double YcoefA;
514 double YcoefB;
515 double YcoefAB;
516
517 double Zcoef;
518 double ZcoefA;
519 double ZcoefB;
520 double ZcoefAB;
521 }CvStereoLineCoeff;
522
523
524 typedef struct CvCamera
525 {
526 float imgSize[2]; /* size of the camera view, used during calibration */
527 float matrix[9]; /* intinsic camera parameters: [ fx 0 cx; 0 fy cy; 0 0 1 ] */
528 float distortion[4]; /* distortion coefficients - two coefficients for radial distortion
529 and another two for tangential: [ k1 k2 p1 p2 ] */
530 float rotMatr[9];
531 float transVect[3]; /* rotation matrix and transition vector relatively
532 to some reference point in the space. */
533 } CvCamera;
534
535 typedef struct CvStereoCamera
536 {
537 CvCamera* camera[2]; /* two individual camera parameters */
538 float fundMatr[9]; /* fundamental matrix */
539
540 /* New part for stereo */
541 CvPoint3D32f epipole[2];
542 CvPoint2D32f quad[2][4]; /* coordinates of destination quadrangle after
543 epipolar geometry rectification */
544 double coeffs[2][3][3];/* coefficients for transformation */
545 CvPoint2D32f border[2][4];
546 CvSize warpSize;
547 CvStereoLineCoeff* lineCoeffs;
548 int needSwapCameras;/* flag set to 1 if need to swap cameras for good reconstruction */
549 float rotMatrix[9];
550 float transVector[3];
551 } CvStereoCamera;
552
553
554 typedef struct CvContourOrientation
555 {
556 float egvals[2];
557 float egvects[4];
558
559 float max, min; // minimum and maximum projections
560 int imax, imin;
561 } CvContourOrientation;
562
563 #define CV_CAMERA_TO_WARP 1
564 #define CV_WARP_TO_CAMERA 2
565
566 CVAPI(int) icvConvertWarpCoordinates(double coeffs[3][3],
567 CvPoint2D32f* cameraPoint,
568 CvPoint2D32f* warpPoint,
569 int direction);
570
571 CVAPI(int) icvGetSymPoint3D( CvPoint3D64f pointCorner,
572 CvPoint3D64f point1,
573 CvPoint3D64f point2,
574 CvPoint3D64f *pointSym2);
575
576 CVAPI(void) icvGetPieceLength3D(CvPoint3D64f point1,CvPoint3D64f point2,double* dist);
577
578 CVAPI(int) icvCompute3DPoint( double alpha,double betta,
579 CvStereoLineCoeff* coeffs,
580 CvPoint3D64f* point);
581
582 CVAPI(int) icvCreateConvertMatrVect( double* rotMatr1,
583 double* transVect1,
584 double* rotMatr2,
585 double* transVect2,
586 double* convRotMatr,
587 double* convTransVect);
588
589 CVAPI(int) icvConvertPointSystem(CvPoint3D64f M2,
590 CvPoint3D64f* M1,
591 double* rotMatr,
592 double* transVect
593 );
594
595 CVAPI(int) icvComputeCoeffForStereo( CvStereoCamera* stereoCamera);
596
597 CVAPI(int) icvGetCrossPieceVector(CvPoint2D32f p1_start,CvPoint2D32f p1_end,CvPoint2D32f v2_start,CvPoint2D32f v2_end,CvPoint2D32f *cross);
598 CVAPI(int) icvGetCrossLineDirect(CvPoint2D32f p1,CvPoint2D32f p2,float a,float b,float c,CvPoint2D32f* cross);
599 CVAPI(float) icvDefinePointPosition(CvPoint2D32f point1,CvPoint2D32f point2,CvPoint2D32f point);
600 CVAPI(int) icvStereoCalibration( int numImages,
601 int* nums,
602 CvSize imageSize,
603 CvPoint2D32f* imagePoints1,
604 CvPoint2D32f* imagePoints2,
605 CvPoint3D32f* objectPoints,
606 CvStereoCamera* stereoparams
607 );
608
609
610 CVAPI(int) icvComputeRestStereoParams(CvStereoCamera *stereoparams);
611
612 CVAPI(void) cvComputePerspectiveMap( const double coeffs[3][3], CvArr* rectMapX, CvArr* rectMapY );
613
614 CVAPI(int) icvComCoeffForLine( CvPoint2D64f point1,
615 CvPoint2D64f point2,
616 CvPoint2D64f point3,
617 CvPoint2D64f point4,
618 double* camMatr1,
619 double* rotMatr1,
620 double* transVect1,
621 double* camMatr2,
622 double* rotMatr2,
623 double* transVect2,
624 CvStereoLineCoeff* coeffs,
625 int* needSwapCameras);
626
627 CVAPI(int) icvGetDirectionForPoint( CvPoint2D64f point,
628 double* camMatr,
629 CvPoint3D64f* direct);
630
631 CVAPI(int) icvGetCrossLines(CvPoint3D64f point11,CvPoint3D64f point12,
632 CvPoint3D64f point21,CvPoint3D64f point22,
633 CvPoint3D64f* midPoint);
634
635 CVAPI(int) icvComputeStereoLineCoeffs( CvPoint3D64f pointA,
636 CvPoint3D64f pointB,
637 CvPoint3D64f pointCam1,
638 double gamma,
639 CvStereoLineCoeff* coeffs);
640
641 /*CVAPI(int) icvComputeFundMatrEpipoles ( double* camMatr1,
642 double* rotMatr1,
643 double* transVect1,
644 double* camMatr2,
645 double* rotMatr2,
646 double* transVect2,
647 CvPoint2D64f* epipole1,
648 CvPoint2D64f* epipole2,
649 double* fundMatr);*/
650
651 CVAPI(int) icvGetAngleLine( CvPoint2D64f startPoint, CvSize imageSize,CvPoint2D64f *point1,CvPoint2D64f *point2);
652
653 CVAPI(void) icvGetCoefForPiece( CvPoint2D64f p_start,CvPoint2D64f p_end,
654 double *a,double *b,double *c,
655 int* result);
656
657 /*CVAPI(void) icvGetCommonArea( CvSize imageSize,
658 CvPoint2D64f epipole1,CvPoint2D64f epipole2,
659 double* fundMatr,
660 double* coeff11,double* coeff12,
661 double* coeff21,double* coeff22,
662 int* result);*/
663
664 CVAPI(void) icvComputeeInfiniteProject1(double* rotMatr,
665 double* camMatr1,
666 double* camMatr2,
667 CvPoint2D32f point1,
668 CvPoint2D32f *point2);
669
670 CVAPI(void) icvComputeeInfiniteProject2(double* rotMatr,
671 double* camMatr1,
672 double* camMatr2,
673 CvPoint2D32f* point1,
674 CvPoint2D32f point2);
675
676 CVAPI(void) icvGetCrossDirectDirect( double* direct1,double* direct2,
677 CvPoint2D64f *cross,int* result);
678
679 CVAPI(void) icvGetCrossPieceDirect( CvPoint2D64f p_start,CvPoint2D64f p_end,
680 double a,double b,double c,
681 CvPoint2D64f *cross,int* result);
682
683 CVAPI(void) icvGetCrossPiecePiece( CvPoint2D64f p1_start,CvPoint2D64f p1_end,
684 CvPoint2D64f p2_start,CvPoint2D64f p2_end,
685 CvPoint2D64f* cross,
686 int* result);
687
688 CVAPI(void) icvGetPieceLength(CvPoint2D64f point1,CvPoint2D64f point2,double* dist);
689
690 CVAPI(void) icvGetCrossRectDirect( CvSize imageSize,
691 double a,double b,double c,
692 CvPoint2D64f *start,CvPoint2D64f *end,
693 int* result);
694
695 CVAPI(void) icvProjectPointToImage( CvPoint3D64f point,
696 double* camMatr,double* rotMatr,double* transVect,
697 CvPoint2D64f* projPoint);
698
699 CVAPI(void) icvGetQuadsTransform( CvSize imageSize,
700 double* camMatr1,
701 double* rotMatr1,
702 double* transVect1,
703 double* camMatr2,
704 double* rotMatr2,
705 double* transVect2,
706 CvSize* warpSize,
707 double quad1[4][2],
708 double quad2[4][2],
709 double* fundMatr,
710 CvPoint3D64f* epipole1,
711 CvPoint3D64f* epipole2
712 );
713
714 CVAPI(void) icvGetQuadsTransformStruct( CvStereoCamera* stereoCamera);
715
716 CVAPI(void) icvComputeStereoParamsForCameras(CvStereoCamera* stereoCamera);
717
718 CVAPI(void) icvGetCutPiece( double* areaLineCoef1,double* areaLineCoef2,
719 CvPoint2D64f epipole,
720 CvSize imageSize,
721 CvPoint2D64f* point11,CvPoint2D64f* point12,
722 CvPoint2D64f* point21,CvPoint2D64f* point22,
723 int* result);
724
725 CVAPI(void) icvGetMiddleAnglePoint( CvPoint2D64f basePoint,
726 CvPoint2D64f point1,CvPoint2D64f point2,
727 CvPoint2D64f* midPoint);
728
729 CVAPI(void) icvGetNormalDirect(double* direct,CvPoint2D64f point,double* normDirect);
730
731 CVAPI(double) icvGetVect(CvPoint2D64f basePoint,CvPoint2D64f point1,CvPoint2D64f point2);
732
733 CVAPI(void) icvProjectPointToDirect( CvPoint2D64f point,double* lineCoeff,
734 CvPoint2D64f* projectPoint);
735
736 CVAPI(void) icvGetDistanceFromPointToDirect( CvPoint2D64f point,double* lineCoef,double*dist);
737
738 CVAPI(IplImage*) icvCreateIsometricImage( IplImage* src, IplImage* dst,
739 int desired_depth, int desired_num_channels );
740
741 CVAPI(void) cvDeInterlace( const CvArr* frame, CvArr* fieldEven, CvArr* fieldOdd );
742
743 /*CVAPI(int) icvSelectBestRt( int numImages,
744 int* numPoints,
745 CvSize imageSize,
746 CvPoint2D32f* imagePoints1,
747 CvPoint2D32f* imagePoints2,
748 CvPoint3D32f* objectPoints,
749
750 CvMatr32f cameraMatrix1,
751 CvVect32f distortion1,
752 CvMatr32f rotMatrs1,
753 CvVect32f transVects1,
754
755 CvMatr32f cameraMatrix2,
756 CvVect32f distortion2,
757 CvMatr32f rotMatrs2,
758 CvVect32f transVects2,
759
760 CvMatr32f bestRotMatr,
761 CvVect32f bestTransVect
762 );*/
763
764
765 /****************************************************************************************\
766 * Contour Tree *
767 \****************************************************************************************/
768
769 /* Contour tree header */
770 typedef struct CvContourTree
771 {
772 CV_SEQUENCE_FIELDS()
773 CvPoint p1; /* the first point of the binary tree root segment */
774 CvPoint p2; /* the last point of the binary tree root segment */
775 } CvContourTree;
776
777 /* Builds hierarhical representation of a contour */
778 CVAPI(CvContourTree*) cvCreateContourTree( const CvSeq* contour,
779 CvMemStorage* storage,
780 double threshold );
781
782 /* Reconstruct (completelly or partially) contour a from contour tree */
783 CVAPI(CvSeq*) cvContourFromContourTree( const CvContourTree* tree,
784 CvMemStorage* storage,
785 CvTermCriteria criteria );
786
787 /* Compares two contour trees */
788 enum { CV_CONTOUR_TREES_MATCH_I1 = 1 };
789
790 CVAPI(double) cvMatchContourTrees( const CvContourTree* tree1,
791 const CvContourTree* tree2,
792 int method, double threshold );
793
794 /****************************************************************************************\
795 * Contour Morphing *
796 \****************************************************************************************/
797
798 /* finds correspondence between two contours */
799 CvSeq* cvCalcContoursCorrespondence( const CvSeq* contour1,
800 const CvSeq* contour2,
801 CvMemStorage* storage);
802
803 /* morphs contours using the pre-calculated correspondence:
804 alpha=0 ~ contour1, alpha=1 ~ contour2 */
805 CvSeq* cvMorphContours( const CvSeq* contour1, const CvSeq* contour2,
806 CvSeq* corr, double alpha,
807 CvMemStorage* storage );
808
809
810 /****************************************************************************************\
811 * Active Contours *
812 \****************************************************************************************/
813
814 #define CV_VALUE 1
815 #define CV_ARRAY 2
816 /* Updates active contour in order to minimize its cummulative
817 (internal and external) energy. */
818 CVAPI(void) cvSnakeImage( const IplImage* image, CvPoint* points,
819 int length, float* alpha,
820 float* beta, float* gamma,
821 int coeff_usage, CvSize win,
822 CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
823
824 /****************************************************************************************\
825 * Texture Descriptors *
826 \****************************************************************************************/
827
828 #define CV_GLCM_OPTIMIZATION_NONE -2
829 #define CV_GLCM_OPTIMIZATION_LUT -1
830 #define CV_GLCM_OPTIMIZATION_HISTOGRAM 0
831
832 #define CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST 10
833 #define CV_GLCMDESC_OPTIMIZATION_ALLOWTRIPLENEST 11
834 #define CV_GLCMDESC_OPTIMIZATION_HISTOGRAM 4
835
836 #define CV_GLCMDESC_ENTROPY 0
837 #define CV_GLCMDESC_ENERGY 1
838 #define CV_GLCMDESC_HOMOGENITY 2
839 #define CV_GLCMDESC_CONTRAST 3
840 #define CV_GLCMDESC_CLUSTERTENDENCY 4
841 #define CV_GLCMDESC_CLUSTERSHADE 5
842 #define CV_GLCMDESC_CORRELATION 6
843 #define CV_GLCMDESC_CORRELATIONINFO1 7
844 #define CV_GLCMDESC_CORRELATIONINFO2 8
845 #define CV_GLCMDESC_MAXIMUMPROBABILITY 9
846
847 #define CV_GLCM_ALL 0
848 #define CV_GLCM_GLCM 1
849 #define CV_GLCM_DESC 2
850
851 typedef struct CvGLCM CvGLCM;
852
853 CVAPI(CvGLCM*) cvCreateGLCM( const IplImage* srcImage,
854 int stepMagnitude,
855 const int* stepDirections CV_DEFAULT(0),
856 int numStepDirections CV_DEFAULT(0),
857 int optimizationType CV_DEFAULT(CV_GLCM_OPTIMIZATION_NONE));
858
859 CVAPI(void) cvReleaseGLCM( CvGLCM** GLCM, int flag CV_DEFAULT(CV_GLCM_ALL));
860
861 CVAPI(void) cvCreateGLCMDescriptors( CvGLCM* destGLCM,
862 int descriptorOptimizationType
863 CV_DEFAULT(CV_GLCMDESC_OPTIMIZATION_ALLOWDOUBLENEST));
864
865 CVAPI(double) cvGetGLCMDescriptor( CvGLCM* GLCM, int step, int descriptor );
866
867 CVAPI(void) cvGetGLCMDescriptorStatistics( CvGLCM* GLCM, int descriptor,
868 double* average, double* standardDeviation );
869
870 CVAPI(IplImage*) cvCreateGLCMImage( CvGLCM* GLCM, int step );
871
872 /****************************************************************************************\
873 * Face eyes&mouth tracking *
874 \****************************************************************************************/
875
876
877 typedef struct CvFaceTracker CvFaceTracker;
878
879 #define CV_NUM_FACE_ELEMENTS 3
880 enum CV_FACE_ELEMENTS
881 {
882 CV_FACE_MOUTH = 0,
883 CV_FACE_LEFT_EYE = 1,
884 CV_FACE_RIGHT_EYE = 2
885 };
886
887 CVAPI(CvFaceTracker*) cvInitFaceTracker(CvFaceTracker* pFaceTracking, const IplImage* imgGray,
888 CvRect* pRects, int nRects);
889 CVAPI(int) cvTrackFace( CvFaceTracker* pFaceTracker, IplImage* imgGray,
890 CvRect* pRects, int nRects,
891 CvPoint* ptRotate, double* dbAngleRotate);
892 CVAPI(void) cvReleaseFaceTracker(CvFaceTracker** ppFaceTracker);
893
894
895 typedef struct CvFace
896 {
897 CvRect MouthRect;
898 CvRect LeftEyeRect;
899 CvRect RightEyeRect;
900 } CvFaceData;
901
902 CvSeq * cvFindFace(IplImage * Image,CvMemStorage* storage);
903 CvSeq * cvPostBoostingFindFace(IplImage * Image,CvMemStorage* storage);
904
905
906 /****************************************************************************************\
907 * 3D Tracker *
908 \****************************************************************************************/
909
910 typedef unsigned char CvBool;
911
912 typedef struct
913 {
914 int id;
915 CvPoint2D32f p; // pgruebele: So we do not loose precision, this needs to be float
916 } Cv3dTracker2dTrackedObject;
917
918 CV_INLINE Cv3dTracker2dTrackedObject cv3dTracker2dTrackedObject(int id, CvPoint2D32f p)
919 {
920 Cv3dTracker2dTrackedObject r;
921 r.id = id;
922 r.p = p;
923 return r;
924 }
925
926 typedef struct
927 {
928 int id;
929 CvPoint3D32f p; // location of the tracked object
930 } Cv3dTrackerTrackedObject;
931
932 CV_INLINE Cv3dTrackerTrackedObject cv3dTrackerTrackedObject(int id, CvPoint3D32f p)
933 {
934 Cv3dTrackerTrackedObject r;
935 r.id = id;
936 r.p = p;
937 return r;
938 }
939
940 typedef struct
941 {
942 CvBool valid;
943 float mat[4][4]; /* maps camera coordinates to world coordinates */
944 CvPoint2D32f principal_point; /* copied from intrinsics so this structure */
945 /* has all the info we need */
946 } Cv3dTrackerCameraInfo;
947
948 typedef struct
949 {
950 CvPoint2D32f principal_point;
951 float focal_length[2];
952 float distortion[4];
953 } Cv3dTrackerCameraIntrinsics;
954
955 CVAPI(CvBool) cv3dTrackerCalibrateCameras(int num_cameras,
956 const Cv3dTrackerCameraIntrinsics camera_intrinsics[], /* size is num_cameras */
957 CvSize etalon_size,
958 float square_size,
959 IplImage *samples[], /* size is num_cameras */
960 Cv3dTrackerCameraInfo camera_info[]); /* size is num_cameras */
961
962 CVAPI(int) cv3dTrackerLocateObjects(int num_cameras, int num_objects,
963 const Cv3dTrackerCameraInfo camera_info[], /* size is num_cameras */
964 const Cv3dTracker2dTrackedObject tracking_info[], /* size is num_objects*num_cameras */
965 Cv3dTrackerTrackedObject tracked_objects[]); /* size is num_objects */
966 /****************************************************************************************
967 tracking_info is a rectangular array; one row per camera, num_objects elements per row.
968 The id field of any unused slots must be -1. Ids need not be ordered or consecutive. On
969 completion, the return value is the number of objects located; i.e., the number of objects
970 visible by more than one camera. The id field of any unused slots in tracked objects is
971 set to -1.
972 ****************************************************************************************/
973
974
975 /****************************************************************************************\
976 * Skeletons and Linear-Contour Models *
977 \****************************************************************************************/
978
979 typedef enum CvLeeParameters
980 {
981 CV_LEE_INT = 0,
982 CV_LEE_FLOAT = 1,
983 CV_LEE_DOUBLE = 2,
984 CV_LEE_AUTO = -1,
985 CV_LEE_ERODE = 0,
986 CV_LEE_ZOOM = 1,
987 CV_LEE_NON = 2
988 } CvLeeParameters;
989
990 #define CV_NEXT_VORONOISITE2D( SITE ) ((SITE)->edge[0]->site[((SITE)->edge[0]->site[0] == (SITE))])
991 #define CV_PREV_VORONOISITE2D( SITE ) ((SITE)->edge[1]->site[((SITE)->edge[1]->site[0] == (SITE))])
992 #define CV_FIRST_VORONOIEDGE2D( SITE ) ((SITE)->edge[0])
993 #define CV_LAST_VORONOIEDGE2D( SITE ) ((SITE)->edge[1])
994 #define CV_NEXT_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[(EDGE)->site[0] != (SITE)])
995 #define CV_PREV_VORONOIEDGE2D( EDGE, SITE ) ((EDGE)->next[2 + ((EDGE)->site[0] != (SITE))])
996 #define CV_VORONOIEDGE2D_BEGINNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] != (SITE))])
997 #define CV_VORONOIEDGE2D_ENDNODE( EDGE, SITE ) ((EDGE)->node[((EDGE)->site[0] == (SITE))])
998 #define CV_TWIN_VORONOISITE2D( SITE, EDGE ) ( (EDGE)->site[((EDGE)->site[0] == (SITE))])
999
1000 #define CV_VORONOISITE2D_FIELDS() \
1001 struct CvVoronoiNode2D *node[2]; \
1002 struct CvVoronoiEdge2D *edge[2];
1003
1004 typedef struct CvVoronoiSite2D
1005 {
1006 CV_VORONOISITE2D_FIELDS()
1007 struct CvVoronoiSite2D *next[2];
1008 } CvVoronoiSite2D;
1009
1010 #define CV_VORONOIEDGE2D_FIELDS() \
1011 struct CvVoronoiNode2D *node[2]; \
1012 struct CvVoronoiSite2D *site[2]; \
1013 struct CvVoronoiEdge2D *next[4];
1014
1015 typedef struct CvVoronoiEdge2D
1016 {
1017 CV_VORONOIEDGE2D_FIELDS()
1018 } CvVoronoiEdge2D;
1019
1020 #define CV_VORONOINODE2D_FIELDS() \
1021 CV_SET_ELEM_FIELDS(CvVoronoiNode2D) \
1022 CvPoint2D32f pt; \
1023 float radius;
1024
1025 typedef struct CvVoronoiNode2D
1026 {
1027 CV_VORONOINODE2D_FIELDS()
1028 } CvVoronoiNode2D;
1029
1030 #define CV_VORONOIDIAGRAM2D_FIELDS() \
1031 CV_GRAPH_FIELDS() \
1032 CvSet *sites;
1033
1034 typedef struct CvVoronoiDiagram2D
1035 {
1036 CV_VORONOIDIAGRAM2D_FIELDS()
1037 } CvVoronoiDiagram2D;
1038
1039 /* Computes Voronoi Diagram for given polygons with holes */
1040 CVAPI(int) cvVoronoiDiagramFromContour(CvSeq* ContourSeq,
1041 CvVoronoiDiagram2D** VoronoiDiagram,
1042 CvMemStorage* VoronoiStorage,
1043 CvLeeParameters contour_type CV_DEFAULT(CV_LEE_INT),
1044 int contour_orientation CV_DEFAULT(-1),
1045 int attempt_number CV_DEFAULT(10));
1046
1047 /* Computes Voronoi Diagram for domains in given image */
1048 CVAPI(int) cvVoronoiDiagramFromImage(IplImage* pImage,
1049 CvSeq** ContourSeq,
1050 CvVoronoiDiagram2D** VoronoiDiagram,
1051 CvMemStorage* VoronoiStorage,
1052 CvLeeParameters regularization_method CV_DEFAULT(CV_LEE_NON),
1053 float approx_precision CV_DEFAULT(CV_LEE_AUTO));
1054
1055 /* Deallocates the storage */
1056 CVAPI(void) cvReleaseVoronoiStorage(CvVoronoiDiagram2D* VoronoiDiagram,
1057 CvMemStorage** pVoronoiStorage);
1058
1059 /*********************** Linear-Contour Model ****************************/
1060
1061 struct CvLCMEdge;
1062 struct CvLCMNode;
1063
1064 typedef struct CvLCMEdge
1065 {
1066 CV_GRAPH_EDGE_FIELDS()
1067 CvSeq* chain;
1068 float width;
1069 int index1;
1070 int index2;
1071 } CvLCMEdge;
1072
1073 typedef struct CvLCMNode
1074 {
1075 CV_GRAPH_VERTEX_FIELDS()
1076 CvContour* contour;
1077 } CvLCMNode;
1078
1079
1080 /* Computes hybrid model from Voronoi Diagram */
1081 CVAPI(CvGraph*) cvLinearContorModelFromVoronoiDiagram(CvVoronoiDiagram2D* VoronoiDiagram,
1082 float maxWidth);
1083
1084 /* Releases hybrid model storage */
1085 CVAPI(int) cvReleaseLinearContorModelStorage(CvGraph** Graph);
1086
1087
1088 /* two stereo-related functions */
1089
1090 CVAPI(void) cvInitPerspectiveTransform( CvSize size, const CvPoint2D32f vertex[4], double matrix[3][3],
1091 CvArr* rectMap );
1092
1093 /*CVAPI(void) cvInitStereoRectification( CvStereoCamera* params,
1094 CvArr* rectMap1, CvArr* rectMap2,
1095 int do_undistortion );*/
1096
1097 /*************************** View Morphing Functions ************************/
1098
1099 typedef struct CvMatrix3
1100 {
1101 float m[3][3];
1102 } CvMatrix3;
1103
1104 /* The order of the function corresponds to the order they should appear in
1105 the view morphing pipeline */
1106
1107 /* Finds ending points of scanlines on left and right images of stereo-pair */
1108 CVAPI(void) cvMakeScanlines( const CvMatrix3* matrix, CvSize img_size,
1109 int* scanlines1, int* scanlines2,
1110 int* lengths1, int* lengths2,
1111 int* line_count );
1112
1113 /* Grab pixel values from scanlines and stores them sequentially
1114 (some sort of perspective image transform) */
1115 CVAPI(void) cvPreWarpImage( int line_count,
1116 IplImage* img,
1117 uchar* dst,
1118 int* dst_nums,
1119 int* scanlines);
1120
1121 /* Approximate each grabbed scanline by a sequence of runs
1122 (lossy run-length compression) */
1123 CVAPI(void) cvFindRuns( int line_count,
1124 uchar* prewarp1,
1125 uchar* prewarp2,
1126 int* line_lengths1,
1127 int* line_lengths2,
1128 int* runs1,
1129 int* runs2,
1130 int* num_runs1,
1131 int* num_runs2);
1132
1133 /* Compares two sets of compressed scanlines */
1134 CVAPI(void) cvDynamicCorrespondMulti( int line_count,
1135 int* first,
1136 int* first_runs,
1137 int* second,
1138 int* second_runs,
1139 int* first_corr,
1140 int* second_corr);
1141
1142 /* Finds scanline ending coordinates for some intermediate "virtual" camera position */
1143 CVAPI(void) cvMakeAlphaScanlines( int* scanlines1,
1144 int* scanlines2,
1145 int* scanlinesA,
1146 int* lengths,
1147 int line_count,
1148 float alpha);
1149
1150 /* Blends data of the left and right image scanlines to get
1151 pixel values of "virtual" image scanlines */
1152 CVAPI(void) cvMorphEpilinesMulti( int line_count,
1153 uchar* first_pix,
1154 int* first_num,
1155 uchar* second_pix,
1156 int* second_num,
1157 uchar* dst_pix,
1158 int* dst_num,
1159 float alpha,
1160 int* first,
1161 int* first_runs,
1162 int* second,
1163 int* second_runs,
1164 int* first_corr,
1165 int* second_corr);
1166
1167 /* Does reverse warping of the morphing result to make
1168 it fill the destination image rectangle */
1169 CVAPI(void) cvPostWarpImage( int line_count,
1170 uchar* src,
1171 int* src_nums,
1172 IplImage* img,
1173 int* scanlines);
1174
1175 /* Deletes Moire (missed pixels that appear due to discretization) */
1176 CVAPI(void) cvDeleteMoire( IplImage* img );
1177
1178
1179 typedef struct CvConDensation
1180 {
1181 int MP;
1182 int DP;
1183 float* DynamMatr; /* Matrix of the linear Dynamics system */
1184 float* State; /* Vector of State */
1185 int SamplesNum; /* Number of the Samples */
1186 float** flSamples; /* arr of the Sample Vectors */
1187 float** flNewSamples; /* temporary array of the Sample Vectors */
1188 float* flConfidence; /* Confidence for each Sample */
1189 float* flCumulative; /* Cumulative confidence */
1190 float* Temp; /* Temporary vector */
1191 float* RandomSample; /* RandomVector to update sample set */
1192 struct CvRandState* RandS; /* Array of structures to generate random vectors */
1193 } CvConDensation;
1194
1195 /* Creates ConDensation filter state */
1196 CVAPI(CvConDensation*) cvCreateConDensation( int dynam_params,
1197 int measure_params,
1198 int sample_count );
1199
1200 /* Releases ConDensation filter state */
1201 CVAPI(void) cvReleaseConDensation( CvConDensation** condens );
1202
1203 /* Updates ConDensation filter by time (predict future state of the system) */
1204 CVAPI(void) cvConDensUpdateByTime( CvConDensation* condens);
1205
1206 /* Initializes ConDensation filter samples */
1207 CVAPI(void) cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound );
1208
1209 CV_INLINE int iplWidth( const IplImage* img )
1210 {
1211 return !img ? 0 : !img->roi ? img->width : img->roi->width;
1212 }
1213
1214 CV_INLINE int iplHeight( const IplImage* img )
1215 {
1216 return !img ? 0 : !img->roi ? img->height : img->roi->height;
1217 }
1218
1219 #ifdef __cplusplus
1220 }
1221 #endif
1222
1223 #ifdef __cplusplus
1224
1225 /****************************************************************************************\
1226 * Calibration engine *
1227 \****************************************************************************************/
1228
1229 typedef enum CvCalibEtalonType
1230 {
1231 CV_CALIB_ETALON_USER = -1,
1232 CV_CALIB_ETALON_CHESSBOARD = 0,
1233 CV_CALIB_ETALON_CHECKERBOARD = CV_CALIB_ETALON_CHESSBOARD
1234 }
1235 CvCalibEtalonType;
1236
1237 class CV_EXPORTS CvCalibFilter
1238 {
1239 public:
1240 /* Constructor & destructor */
1241 CvCalibFilter();
1242 virtual ~CvCalibFilter();
1243
1244 /* Sets etalon type - one for all cameras.
1245 etalonParams is used in case of pre-defined etalons (such as chessboard).
1246 Number of elements in etalonParams is determined by etalonType.
1247 E.g., if etalon type is CV_ETALON_TYPE_CHESSBOARD then:
1248 etalonParams[0] is number of squares per one side of etalon
1249 etalonParams[1] is number of squares per another side of etalon
1250 etalonParams[2] is linear size of squares in the board in arbitrary units.
1251 pointCount & points are used in case of
1252 CV_CALIB_ETALON_USER (user-defined) etalon. */
1253 virtual bool
1254 SetEtalon( CvCalibEtalonType etalonType, double* etalonParams,
1255 int pointCount = 0, CvPoint2D32f* points = 0 );
1256
1257 /* Retrieves etalon parameters/or and points */
1258 virtual CvCalibEtalonType
1259 GetEtalon( int* paramCount = 0, const double** etalonParams = 0,
1260 int* pointCount = 0, const CvPoint2D32f** etalonPoints = 0 ) const;
1261
1262 /* Sets number of cameras calibrated simultaneously. It is equal to 1 initially */
1263 virtual void SetCameraCount( int cameraCount );
1264
1265 /* Retrieves number of cameras */
1266 int GetCameraCount() const { return cameraCount; }
1267
1268 /* Starts cameras calibration */
1269 virtual bool SetFrames( int totalFrames );
1270
1271 /* Stops cameras calibration */
1272 virtual void Stop( bool calibrate = false );
1273
1274 /* Retrieves number of cameras */
1275 bool IsCalibrated() const { return isCalibrated; }
1276
1277 /* Feeds another serie of snapshots (one per each camera) to filter.
1278 Etalon points on these images are found automatically.
1279 If the function can't locate points, it returns false */
1280 virtual bool FindEtalon( IplImage** imgs );
1281
1282 /* The same but takes matrices */
1283 virtual bool FindEtalon( CvMat** imgs );
1284
1285 /* Lower-level function for feeding filter with already found etalon points.
1286 Array of point arrays for each camera is passed. */
1287 virtual bool Push( const CvPoint2D32f** points = 0 );
1288
1289 /* Returns total number of accepted frames and, optionally,
1290 total number of frames to collect */
1291 virtual int GetFrameCount( int* framesTotal = 0 ) const;
1292
1293 /* Retrieves camera parameters for specified camera.
1294 If camera is not calibrated the function returns 0 */
1295 virtual const CvCamera* GetCameraParams( int idx = 0 ) const;
1296
1297 virtual const CvStereoCamera* GetStereoParams() const;
1298
1299 /* Sets camera parameters for all cameras */
1300 virtual bool SetCameraParams( CvCamera* params );
1301
1302 /* Saves all camera parameters to file */
1303 virtual bool SaveCameraParams( const char* filename );
1304
1305 /* Loads all camera parameters from file */
1306 virtual bool LoadCameraParams( const char* filename );
1307
1308 /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
1309 virtual bool Undistort( IplImage** src, IplImage** dst );
1310
1311 /* Undistorts images using camera parameters. Some of src pointers can be NULL. */
1312 virtual bool Undistort( CvMat** src, CvMat** dst );
1313
1314 /* Returns array of etalon points detected/partally detected
1315 on the latest frame for idx-th camera */
1316 virtual bool GetLatestPoints( int idx, CvPoint2D32f** pts,
1317 int* count, bool* found );
1318
1319 /* Draw the latest detected/partially detected etalon */
1320 virtual void DrawPoints( IplImage** dst );
1321
1322 /* Draw the latest detected/partially detected etalon */
1323 virtual void DrawPoints( CvMat** dst );
1324
1325 virtual bool Rectify( IplImage** srcarr, IplImage** dstarr );
1326 virtual bool Rectify( CvMat** srcarr, CvMat** dstarr );
1327
1328 protected:
1329
1330 enum { MAX_CAMERAS = 3 };
1331
1332 /* etalon data */
1333 CvCalibEtalonType etalonType;
1334 int etalonParamCount;
1335 double* etalonParams;
1336 int etalonPointCount;
1337 CvPoint2D32f* etalonPoints;
1338 CvSize imgSize;
1339 CvMat* grayImg;
1340 CvMat* tempImg;
1341 CvMemStorage* storage;
1342
1343 /* camera data */
1344 int cameraCount;
1345 CvCamera cameraParams[MAX_CAMERAS];
1346 CvStereoCamera stereo;
1347 CvPoint2D32f* points[MAX_CAMERAS];
1348 CvMat* undistMap[MAX_CAMERAS][2];
1349 CvMat* undistImg;
1350 int latestCounts[MAX_CAMERAS];
1351 CvPoint2D32f* latestPoints[MAX_CAMERAS];
1352 CvMat* rectMap[MAX_CAMERAS][2];
1353
1354 /* Added by Valery */
1355 //CvStereoCamera stereoParams;
1356
1357 int maxPoints;
1358 int framesTotal;
1359 int framesAccepted;
1360 bool isCalibrated;
1361 };
1362
1363 #include <iosfwd>
1364 #include <limits>
1365
1366 class CV_EXPORTS CvImage
1367 {
1368 public:
1369 CvImage() : image(0), refcount(0) {}
1370 CvImage( CvSize size, int depth, int channels )
1371 {
1372 image = cvCreateImage( size, depth, channels );
1373 refcount = image ? new int(1) : 0;
1374 }
1375
1376 CvImage( IplImage* img ) : image(img)
1377 {
1378 refcount = image ? new int(1) : 0;
1379 }
1380
1381 CvImage( const CvImage& img ) : image(img.image), refcount(img.refcount)
1382 {
1383 if( refcount ) ++(*refcount);
1384 }
1385
1386 CvImage( const char* filename, const char* imgname=0, int color=-1 ) : image(0), refcount(0)
1387 { load( filename, imgname, color ); }
1388
1389 CvImage( CvFileStorage* fs, const char* mapname, const char* imgname ) : image(0), refcount(0)
1390 { read( fs, mapname, imgname ); }
1391
1392 CvImage( CvFileStorage* fs, const char* seqname, int idx ) : image(0), refcount(0)
1393 { read( fs, seqname, idx ); }
1394
1395 ~CvImage()
1396 {
1397 if( refcount && !(--*refcount) )
1398 {
1399 cvReleaseImage( &image );
1400 delete refcount;
1401 }
1402 }
1403
1404 CvImage clone() { return CvImage(image ? cvCloneImage(image) : 0); }
1405
1406 void create( CvSize size, int depth, int channels )
1407 {
1408 if( !image || !refcount ||
1409 image->width != size.width || image->height != size.height ||
1410 image->depth != depth || image->nChannels != channels )
1411 attach( cvCreateImage( size, depth, channels ));
1412 }
1413
1414 void release() { detach(); }
1415 void clear() { detach(); }
1416
1417 void attach( IplImage* img, bool use_refcount=true )
1418 {
1419 if( refcount && --*refcount == 0 )
1420 {
1421 cvReleaseImage( &image );
1422 delete refcount;
1423 }
1424 image = img;
1425 refcount = use_refcount && image ? new int(1) : 0;
1426 }
1427
1428 void detach()
1429 {
1430 if( refcount && --*refcount == 0 )
1431 {
1432 cvReleaseImage( &image );
1433 delete refcount;
1434 }
1435 image = 0;
1436 refcount = 0;
1437 }
1438
1439 bool load( const char* filename, const char* imgname=0, int color=-1 );
1440 bool read( CvFileStorage* fs, const char* mapname, const char* imgname );
1441 bool read( CvFileStorage* fs, const char* seqname, int idx );
1442 void save( const char* filename, const char* imgname, const int* params=0 );
1443 void write( CvFileStorage* fs, const char* imgname );
1444
1445 void show( const char* window_name );
1446 bool is_valid() { return image != 0; }
1447
1448 int width() const { return image ? image->width : 0; }
1449 int height() const { return image ? image->height : 0; }
1450
1451 CvSize size() const { return image ? cvSize(image->width, image->height) : cvSize(0,0); }
1452
1453 CvSize roi_size() const
1454 {
1455 return !image ? cvSize(0,0) :
1456 !image->roi ? cvSize(image->width,image->height) :
1457 cvSize(image->roi->width, image->roi->height);
1458 }
1459
1460 CvRect roi() const
1461 {
1462 return !image ? cvRect(0,0,0,0) :
1463 !image->roi ? cvRect(0,0,image->width,image->height) :
1464 cvRect(image->roi->xOffset,image->roi->yOffset,
1465 image->roi->width,image->roi->height);
1466 }
1467
1468 int coi() const { return !image || !image->roi ? 0 : image->roi->coi; }
1469
1470 void set_roi(CvRect roi) { cvSetImageROI(image,roi); }
1471 void reset_roi() { cvResetImageROI(image); }
1472 void set_coi(int coi) { cvSetImageCOI(image,coi); }
1473 int depth() const { return image ? image->depth : 0; }
1474 int channels() const { return image ? image->nChannels : 0; }
1475 int pix_size() const { return image ? ((image->depth & 255)>>3)*image->nChannels : 0; }
1476
1477 uchar* data() { return image ? (uchar*)image->imageData : 0; }
1478 const uchar* data() const { return image ? (const uchar*)image->imageData : 0; }
1479 int step() const { return image ? image->widthStep : 0; }
1480 int origin() const { return image ? image->origin : 0; }
1481
1482 uchar* roi_row(int y)
1483 {
1484 assert(0<=y);
1485 assert(!image ?
1486 1 : image->roi ?
1487 y<image->roi->height : y<image->height);
1488
1489 return !image ? 0 :
1490 !image->roi ?
1491 (uchar*)(image->imageData + y*image->widthStep) :
1492 (uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
1493 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
1494 }
1495
1496 const uchar* roi_row(int y) const
1497 {
1498 assert(0<=y);
1499 assert(!image ?
1500 1 : image->roi ?
1501 y<image->roi->height : y<image->height);
1502
1503 return !image ? 0 :
1504 !image->roi ?
1505 (const uchar*)(image->imageData + y*image->widthStep) :
1506 (const uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
1507 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
1508 }
1509
1510 operator const IplImage* () const { return image; }
1511 operator IplImage* () { return image; }
1512
1513 CvImage& operator = (const CvImage& img)
1514 {
1515 if( img.refcount )
1516 ++*img.refcount;
1517 if( refcount && !(--*refcount) )
1518 cvReleaseImage( &image );
1519 image=img.image;
1520 refcount=img.refcount;
1521 return *this;
1522 }
1523
1524 protected:
1525 IplImage* image;
1526 int* refcount;
1527 };
1528
1529
1530 class CV_EXPORTS CvMatrix
1531 {
1532 public:
1533 CvMatrix() : matrix(0) {}
1534 CvMatrix( int rows, int cols, int type )
1535 { matrix = cvCreateMat( rows, cols, type ); }
1536
1537 CvMatrix( int rows, int cols, int type, CvMat* hdr,
1538 void* data=0, int step=CV_AUTOSTEP )
1539 { matrix = cvInitMatHeader( hdr, rows, cols, type, data, step ); }
1540
1541 CvMatrix( int rows, int cols, int type, CvMemStorage* storage, bool alloc_data=true );
1542
1543 CvMatrix( int rows, int cols, int type, void* data, int step=CV_AUTOSTEP )
1544 { matrix = cvCreateMatHeader( rows, cols, type );
1545 cvSetData( matrix, data, step ); }
1546
1547 CvMatrix( CvMat* m )
1548 { matrix = m; }
1549
1550 CvMatrix( const CvMatrix& m )
1551 {
1552 matrix = m.matrix;
1553 addref();
1554 }
1555
1556 CvMatrix( const char* filename, const char* matname=0, int color=-1 ) : matrix(0)
1557 { load( filename, matname, color ); }
1558
1559 CvMatrix( CvFileStorage* fs, const char* mapname, const char* matname ) : matrix(0)
1560 { read( fs, mapname, matname ); }
1561
1562 CvMatrix( CvFileStorage* fs, const char* seqname, int idx ) : matrix(0)
1563 { read( fs, seqname, idx ); }
1564
1565 ~CvMatrix()
1566 {
1567 release();
1568 }
1569
1570 CvMatrix clone() { return CvMatrix(matrix ? cvCloneMat(matrix) : 0); }
1571
1572 void set( CvMat* m, bool add_ref )
1573 {
1574 release();
1575 matrix = m;
1576 if( add_ref )
1577 addref();
1578 }
1579
1580 void create( int rows, int cols, int type )
1581 {
1582 if( !matrix || !matrix->refcount ||
1583 matrix->rows != rows || matrix->cols != cols ||
1584 CV_MAT_TYPE(matrix->type) != type )
1585 set( cvCreateMat( rows, cols, type ), false );
1586 }
1587
1588 void addref() const
1589 {
1590 if( matrix )
1591 {
1592 if( matrix->hdr_refcount )
1593 ++matrix->hdr_refcount;
1594 else if( matrix->refcount )
1595 ++*matrix->refcount;
1596 }
1597 }
1598
1599 void release()
1600 {
1601 if( matrix )
1602 {
1603 if( matrix->hdr_refcount )
1604 {
1605 if( --matrix->hdr_refcount == 0 )
1606 cvReleaseMat( &matrix );
1607 }
1608 else if( matrix->refcount )
1609 {
1610 if( --*matrix->refcount == 0 )
1611 cvFree( &matrix->refcount );
1612 }
1613 matrix = 0;
1614 }
1615 }
1616
1617 void clear()
1618 {
1619 release();
1620 }
1621
1622 bool load( const char* filename, const char* matname=0, int color=-1 );
1623 bool read( CvFileStorage* fs, const char* mapname, const char* matname );
1624 bool read( CvFileStorage* fs, const char* seqname, int idx );
1625 void save( const char* filename, const char* matname, const int* params=0 );
1626 void write( CvFileStorage* fs, const char* matname );
1627
1628 void show( const char* window_name );
1629
1630 bool is_valid() { return matrix != 0; }
1631
1632 int rows() const { return matrix ? matrix->rows : 0; }
1633 int cols() const { return matrix ? matrix->cols : 0; }
1634
1635 CvSize size() const
1636 {
1637 return !matrix ? cvSize(0,0) : cvSize(matrix->rows,matrix->cols);
1638 }
1639
1640 int type() const { return matrix ? CV_MAT_TYPE(matrix->type) : 0; }
1641 int depth() const { return matrix ? CV_MAT_DEPTH(matrix->type) : 0; }
1642 int channels() const { return matrix ? CV_MAT_CN(matrix->type) : 0; }
1643 int pix_size() const { return matrix ? CV_ELEM_SIZE(matrix->type) : 0; }
1644
1645 uchar* data() { return matrix ? matrix->data.ptr : 0; }
1646 const uchar* data() const { return matrix ? matrix->data.ptr : 0; }
1647 int step() const { return matrix ? matrix->step : 0; }
1648
1649 void set_data( void* data, int step=CV_AUTOSTEP )
1650 { cvSetData( matrix, data, step ); }
1651
1652 uchar* row(int i) { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
1653 const uchar* row(int i) const
1654 { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
1655
1656 operator const CvMat* () const { return matrix; }
1657 operator CvMat* () { return matrix; }
1658
1659 CvMatrix& operator = (const CvMatrix& _m)
1660 {
1661 _m.addref();
1662 release();
1663 matrix = _m.matrix;
1664 return *this;
1665 }
1666
1667 protected:
1668 CvMat* matrix;
1669 };
1670
1671 /****************************************************************************************\
1672 * CamShiftTracker *
1673 \****************************************************************************************/
1674
1675 class CV_EXPORTS CvCamShiftTracker
1676 {
1677 public:
1678
1679 CvCamShiftTracker();
1680 virtual ~CvCamShiftTracker();
1681
1682 /**** Characteristics of the object that are calculated by track_object method *****/
1683 float get_orientation() const // orientation of the object in degrees
1684 { return m_box.angle; }
1685 float get_length() const // the larger linear size of the object
1686 { return m_box.size.height; }
1687 float get_width() const // the smaller linear size of the object
1688 { return m_box.size.width; }
1689 CvPoint2D32f get_center() const // center of the object
1690 { return m_box.center; }
1691 CvRect get_window() const // bounding rectangle for the object
1692 { return m_comp.rect; }
1693
1694 /*********************** Tracking parameters ************************/
1695 int get_threshold() const // thresholding value that applied to back project
1696 { return m_threshold; }
1697
1698 int get_hist_dims( int* dims = 0 ) const // returns number of histogram dimensions and sets
1699 { return m_hist ? cvGetDims( m_hist->bins, dims ) : 0; }
1700
1701 int get_min_ch_val( int channel ) const // get the minimum allowed value of the specified channel
1702 { return m_min_ch_val[channel]; }
1703
1704 int get_max_ch_val( int channel ) const // get the maximum allowed value of the specified channel
1705 { return m_max_ch_val[channel]; }
1706
1707 // set initial object rectangle (must be called before initial calculation of the histogram)
1708 bool set_window( CvRect window)
1709 { m_comp.rect = window; return true; }
1710
1711 bool set_threshold( int threshold ) // threshold applied to the histogram bins
1712 { m_threshold = threshold; return true; }
1713
1714 bool set_hist_bin_range( int dim, int min_val, int max_val );
1715
1716 bool set_hist_dims( int c_dims, int* dims );// set the histogram parameters
1717
1718 bool set_min_ch_val( int channel, int val ) // set the minimum allowed value of the specified channel
1719 { m_min_ch_val[channel] = val; return true; }
1720 bool set_max_ch_val( int channel, int val ) // set the maximum allowed value of the specified channel
1721 { m_max_ch_val[channel] = val; return true; }
1722
1723 /************************ The processing methods *********************************/
1724 // update object position
1725 virtual bool track_object( const IplImage* cur_frame );
1726
1727 // update object histogram
1728 virtual bool update_histogram( const IplImage* cur_frame );
1729
1730 // reset histogram
1731 virtual void reset_histogram();
1732
1733 /************************ Retrieving internal data *******************************/
1734 // get back project image
1735 virtual IplImage* get_back_project()
1736 { return m_back_project; }
1737
1738 float query( int* bin ) const
1739 { return m_hist ? (float)cvGetRealND(m_hist->bins, bin) : 0.f; }
1740
1741 protected:
1742
1743 // internal method for color conversion: fills m_color_planes group
1744 virtual void color_transform( const IplImage* img );
1745
1746 CvHistogram* m_hist;
1747
1748 CvBox2D m_box;
1749 CvConnectedComp m_comp;
1750
1751 float m_hist_ranges_data[CV_MAX_DIM][2];
1752 float* m_hist_ranges[CV_MAX_DIM];
1753
1754 int m_min_ch_val[CV_MAX_DIM];
1755 int m_max_ch_val[CV_MAX_DIM];
1756 int m_threshold;
1757
1758 IplImage* m_color_planes[CV_MAX_DIM];
1759 IplImage* m_back_project;
1760 IplImage* m_temp;
1761 IplImage* m_mask;
1762 };
1763
1764 //#include "cvvidsurv.hpp"
1765 #endif
1766
1767 #endif
1768
1769 /* End of file. */