Update the trunk to the OpenCV's CVS (2008-07-14)
[opencv] / cv / include / cv.h
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
43 #ifndef _CV_H_
44 #define _CV_H_
45
46 #ifdef __IPL_H__
47 #define HAVE_IPL
48 #endif
49
50 #ifndef SKIP_INCLUDES
51   #if defined(_CH_)
52     #pragma package <chopencv>
53     #include <chdl.h>
54     LOAD_CHDL(cv)
55   #endif
56 #endif
57
58 #include "cxcore.h"
59 #include "cvtypes.h"
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 /****************************************************************************************\
66 *                                    Image Processing                                    *
67 \****************************************************************************************/
68
69 /* Copies source 2D array inside of the larger destination array and
70    makes a border of the specified type (IPL_BORDER_*) around the copied area. */
71 CVAPI(void) cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset,
72                               int bordertype, CvScalar value CV_DEFAULT(cvScalarAll(0)));
73
74 #define CV_BLUR_NO_SCALE 0
75 #define CV_BLUR  1
76 #define CV_GAUSSIAN  2
77 #define CV_MEDIAN 3
78 #define CV_BILATERAL 4
79
80 /* Smoothes array (removes noise) */
81 CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst,
82                       int smoothtype CV_DEFAULT(CV_GAUSSIAN),
83                       int size1 CV_DEFAULT(3),
84                       int size2 CV_DEFAULT(0),
85                       double sigma1 CV_DEFAULT(0),
86                       double sigma2 CV_DEFAULT(0));
87
88 /* Convolves the image with the kernel */
89 CVAPI(void) cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel,
90                         CvPoint anchor CV_DEFAULT(cvPoint(-1,-1)));
91
92 /* Finds integral image: SUM(X,Y) = sum(x<X,y<Y)I(x,y) */
93 CVAPI(void) cvIntegral( const CvArr* image, CvArr* sum,
94                        CvArr* sqsum CV_DEFAULT(NULL),
95                        CvArr* tilted_sum CV_DEFAULT(NULL));
96
97 /*
98    Smoothes the input image with gaussian kernel and then down-samples it.
99    dst_width = floor(src_width/2)[+1],
100    dst_height = floor(src_height/2)[+1]
101 */
102 CVAPI(void)  cvPyrDown( const CvArr* src, CvArr* dst,
103                         int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
104
105 /* 
106    Up-samples image and smoothes the result with gaussian kernel.
107    dst_width = src_width*2,
108    dst_height = src_height*2
109 */
110 CVAPI(void)  cvPyrUp( const CvArr* src, CvArr* dst,
111                       int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
112
113 /* Builds pyramid for an image */
114 CVAPI(CvMat**) cvCreatePyramid( const CvArr* img, int extra_layers, double rate,
115                                 const CvSize* layer_sizes CV_DEFAULT(0),
116                                 CvArr* bufarr CV_DEFAULT(0),
117                                 int calc CV_DEFAULT(1),
118                                 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
119
120 /* Releases pyramid */
121 CVAPI(void)  cvReleasePyramid( CvMat*** pyramid, int extra_layers );
122
123
124 /* Splits color or grayscale image into multiple connected components
125    of nearly the same color/brightness using modification of Burt algorithm.
126    comp with contain a pointer to sequence (CvSeq)
127    of connected components (CvConnectedComp) */
128 CVAPI(void) cvPyrSegmentation( IplImage* src, IplImage* dst,
129                               CvMemStorage* storage, CvSeq** comp,
130                               int level, double threshold1,
131                               double threshold2 );
132
133 /* Filters image using meanshift algorithm */
134 CVAPI(void) cvPyrMeanShiftFiltering( const CvArr* src, CvArr* dst, 
135     double sp, double sr, int max_level CV_DEFAULT(1),
136     CvTermCriteria termcrit CV_DEFAULT(cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,5,1)));
137
138 /* Segments image using seed "markers" */
139 CVAPI(void) cvWatershed( const CvArr* image, CvArr* markers );
140
141 #define CV_INPAINT_NS      0
142 #define CV_INPAINT_TELEA   1
143
144 /* Inpaints the selected region in the image */
145 CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask,
146                        CvArr* dst, double inpaintRange, int flags );
147
148 #define CV_SCHARR -1
149 #define CV_MAX_SOBEL_KSIZE 7
150
151 /* Calculates an image derivative using generalized Sobel
152    (aperture_size = 1,3,5,7) or Scharr (aperture_size = -1) operator.
153    Scharr can be used only for the first dx or dy derivative */
154 CVAPI(void) cvSobel( const CvArr* src, CvArr* dst,
155                     int xorder, int yorder,
156                     int aperture_size CV_DEFAULT(3));
157
158 /* Calculates the image Laplacian: (d2/dx + d2/dy)I */
159 CVAPI(void) cvLaplace( const CvArr* src, CvArr* dst,
160                       int aperture_size CV_DEFAULT(3) );
161
162 /* Constants for color conversion */
163 #define  CV_BGR2BGRA    0
164 #define  CV_RGB2RGBA    CV_BGR2BGRA
165
166 #define  CV_BGRA2BGR    1
167 #define  CV_RGBA2RGB    CV_BGRA2BGR
168
169 #define  CV_BGR2RGBA    2
170 #define  CV_RGB2BGRA    CV_BGR2RGBA
171
172 #define  CV_RGBA2BGR    3
173 #define  CV_BGRA2RGB    CV_RGBA2BGR
174
175 #define  CV_BGR2RGB     4
176 #define  CV_RGB2BGR     CV_BGR2RGB
177
178 #define  CV_BGRA2RGBA   5
179 #define  CV_RGBA2BGRA   CV_BGRA2RGBA
180
181 #define  CV_BGR2GRAY    6
182 #define  CV_RGB2GRAY    7
183 #define  CV_GRAY2BGR    8
184 #define  CV_GRAY2RGB    CV_GRAY2BGR
185 #define  CV_GRAY2BGRA   9
186 #define  CV_GRAY2RGBA   CV_GRAY2BGRA
187 #define  CV_BGRA2GRAY   10
188 #define  CV_RGBA2GRAY   11
189
190 #define  CV_BGR2BGR565  12
191 #define  CV_RGB2BGR565  13
192 #define  CV_BGR5652BGR  14
193 #define  CV_BGR5652RGB  15
194 #define  CV_BGRA2BGR565 16
195 #define  CV_RGBA2BGR565 17
196 #define  CV_BGR5652BGRA 18
197 #define  CV_BGR5652RGBA 19
198
199 #define  CV_GRAY2BGR565 20
200 #define  CV_BGR5652GRAY 21
201
202 #define  CV_BGR2BGR555  22
203 #define  CV_RGB2BGR555  23
204 #define  CV_BGR5552BGR  24
205 #define  CV_BGR5552RGB  25
206 #define  CV_BGRA2BGR555 26
207 #define  CV_RGBA2BGR555 27
208 #define  CV_BGR5552BGRA 28
209 #define  CV_BGR5552RGBA 29
210
211 #define  CV_GRAY2BGR555 30
212 #define  CV_BGR5552GRAY 31
213
214 #define  CV_BGR2XYZ     32
215 #define  CV_RGB2XYZ     33
216 #define  CV_XYZ2BGR     34
217 #define  CV_XYZ2RGB     35
218
219 #define  CV_BGR2YCrCb   36
220 #define  CV_RGB2YCrCb   37
221 #define  CV_YCrCb2BGR   38
222 #define  CV_YCrCb2RGB   39
223
224 #define  CV_BGR2HSV     40
225 #define  CV_RGB2HSV     41
226
227 #define  CV_BGR2Lab     44
228 #define  CV_RGB2Lab     45
229
230 #define  CV_BayerBG2BGR 46
231 #define  CV_BayerGB2BGR 47
232 #define  CV_BayerRG2BGR 48
233 #define  CV_BayerGR2BGR 49
234
235 #define  CV_BayerBG2RGB CV_BayerRG2BGR
236 #define  CV_BayerGB2RGB CV_BayerGR2BGR
237 #define  CV_BayerRG2RGB CV_BayerBG2BGR
238 #define  CV_BayerGR2RGB CV_BayerGB2BGR
239
240 #define  CV_BGR2Luv     50
241 #define  CV_RGB2Luv     51
242 #define  CV_BGR2HLS     52
243 #define  CV_RGB2HLS     53
244
245 #define  CV_HSV2BGR     54
246 #define  CV_HSV2RGB     55
247
248 #define  CV_Lab2BGR     56
249 #define  CV_Lab2RGB     57
250 #define  CV_Luv2BGR     58
251 #define  CV_Luv2RGB     59
252 #define  CV_HLS2BGR     60
253 #define  CV_HLS2RGB     61
254
255 #define  CV_COLORCVT_MAX  100
256
257 /* Converts input array pixels from one color space to another */
258 CVAPI(void)  cvCvtColor( const CvArr* src, CvArr* dst, int code );
259
260 #define  CV_INTER_NN        0
261 #define  CV_INTER_LINEAR    1
262 #define  CV_INTER_CUBIC     2
263 #define  CV_INTER_AREA      3
264
265 #define  CV_WARP_FILL_OUTLIERS 8
266 #define  CV_WARP_INVERSE_MAP  16
267
268 /* Resizes image (input array is resized to fit the destination array) */
269 CVAPI(void)  cvResize( const CvArr* src, CvArr* dst,
270                        int interpolation CV_DEFAULT( CV_INTER_LINEAR ));
271
272 /* Warps image with affine transform */ 
273 CVAPI(void)  cvWarpAffine( const CvArr* src, CvArr* dst, const CvMat* map_matrix,
274                            int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
275                            CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
276
277 /* Computes affine transform matrix for mapping src[i] to dst[i] (i=0,1,2) */
278 CVAPI(CvMat*) cvGetAffineTransform( const CvPoint2D32f * src, 
279                                     const CvPoint2D32f * dst, 
280                                     CvMat * map_matrix );
281
282 /* Computes rotation_matrix matrix */
283 CVAPI(CvMat*)  cv2DRotationMatrix( CvPoint2D32f center, double angle,
284                                    double scale, CvMat* map_matrix );
285
286 /* Warps image with perspective (projective) transform */
287 CVAPI(void)  cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix,
288                                 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
289                                 CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
290
291 /* Computes perspective transform matrix for mapping src[i] to dst[i] (i=0,1,2,3) */
292 CVAPI(CvMat*) cvGetPerspectiveTransform( const CvPoint2D32f* src,
293                                          const CvPoint2D32f* dst,
294                                          CvMat* map_matrix );
295
296 /* Performs generic geometric transformation using the specified coordinate maps */
297 CVAPI(void)  cvRemap( const CvArr* src, CvArr* dst,
298                       const CvArr* mapx, const CvArr* mapy,
299                       int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS),
300                       CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
301
302 /* Performs forward or inverse log-polar image transform */
303 CVAPI(void)  cvLogPolar( const CvArr* src, CvArr* dst,
304                          CvPoint2D32f center, double M,
305                          int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS));
306
307 #define  CV_SHAPE_RECT      0
308 #define  CV_SHAPE_CROSS     1
309 #define  CV_SHAPE_ELLIPSE   2
310 #define  CV_SHAPE_CUSTOM    100
311
312 /* creates structuring element used for morphological operations */
313 CVAPI(IplConvKernel*)  cvCreateStructuringElementEx(
314             int cols, int  rows, int  anchor_x, int  anchor_y,
315             int shape, int* values CV_DEFAULT(NULL) );
316
317 /* releases structuring element */
318 CVAPI(void)  cvReleaseStructuringElement( IplConvKernel** element );
319
320 /* erodes input image (applies minimum filter) one or more times.
321    If element pointer is NULL, 3x3 rectangular element is used */
322 CVAPI(void)  cvErode( const CvArr* src, CvArr* dst,
323                       IplConvKernel* element CV_DEFAULT(NULL),
324                       int iterations CV_DEFAULT(1) );
325
326 /* dilates input image (applies maximum filter) one or more times.
327    If element pointer is NULL, 3x3 rectangular element is used */
328 CVAPI(void)  cvDilate( const CvArr* src, CvArr* dst,
329                        IplConvKernel* element CV_DEFAULT(NULL),
330                        int iterations CV_DEFAULT(1) );
331
332 #define CV_MOP_OPEN         2
333 #define CV_MOP_CLOSE        3
334 #define CV_MOP_GRADIENT     4
335 #define CV_MOP_TOPHAT       5
336 #define CV_MOP_BLACKHAT     6
337
338 /* Performs complex morphological transformation */
339 CVAPI(void)  cvMorphologyEx( const CvArr* src, CvArr* dst,
340                              CvArr* temp, IplConvKernel* element,
341                              int operation, int iterations CV_DEFAULT(1) );
342
343 /* Calculates all spatial and central moments up to the 3rd order */
344 CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0));
345
346 /* Retrieve particular spatial, central or normalized central moments */
347 CVAPI(double)  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
348 CVAPI(double)  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
349 CVAPI(double)  cvGetNormalizedCentralMoment( CvMoments* moments,
350                                              int x_order, int y_order );
351
352 /* Calculates 7 Hu's invariants from precalculated spatial and central moments */
353 CVAPI(void) cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );
354
355 /*********************************** data sampling **************************************/
356
357 /* Fetches pixels that belong to the specified line segment and stores them to the buffer.
358    Returns the number of retrieved points. */
359 CVAPI(int)  cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer,
360                           int connectivity CV_DEFAULT(8));
361
362 /* Retrieves the rectangular image region with specified center from the input array.
363  dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2).
364  Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/
365 CVAPI(void)  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
366
367
368 /* Retrieves quadrangle from the input array.
369     matrixarr = ( a11  a12 | b1 )   dst(x,y) <- src(A[x y]' + b)
370                 ( a21  a22 | b2 )   (bilinear interpolation is used to retrieve pixels
371                                      with fractional coordinates)
372 */
373 CVAPI(void)  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst,
374                                     const CvMat* map_matrix );
375
376 /* Methods for comparing two array */
377 #define  CV_TM_SQDIFF        0
378 #define  CV_TM_SQDIFF_NORMED 1
379 #define  CV_TM_CCORR         2
380 #define  CV_TM_CCORR_NORMED  3
381 #define  CV_TM_CCOEFF        4
382 #define  CV_TM_CCOEFF_NORMED 5
383
384 /* Measures similarity between template and overlapped windows in the source image
385    and fills the resultant image with the measurements */
386 CVAPI(void)  cvMatchTemplate( const CvArr* image, const CvArr* templ,
387                               CvArr* result, int method );
388
389 /* Computes earth mover distance between
390    two weighted point sets (called signatures) */
391 CVAPI(float)  cvCalcEMD2( const CvArr* signature1,
392                           const CvArr* signature2,
393                           int distance_type,
394                           CvDistanceFunction distance_func CV_DEFAULT(NULL),
395                           const CvArr* cost_matrix CV_DEFAULT(NULL),
396                           CvArr* flow CV_DEFAULT(NULL),
397                           float* lower_bound CV_DEFAULT(NULL),
398                           void* userdata CV_DEFAULT(NULL));
399
400 /****************************************************************************************\
401 *                              Contours retrieving                                       *
402 \****************************************************************************************/
403
404 /* Retrieves outer and optionally inner boundaries of white (non-zero) connected
405    components in the black (zero) background */
406 CVAPI(int)  cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,
407                             int header_size CV_DEFAULT(sizeof(CvContour)),
408                             int mode CV_DEFAULT(CV_RETR_LIST),
409                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
410                             CvPoint offset CV_DEFAULT(cvPoint(0,0)));
411
412
413 /* Initalizes contour retrieving process.
414    Calls cvStartFindContours.
415    Calls cvFindNextContour until null pointer is returned
416    or some other condition becomes true.
417    Calls cvEndFindContours at the end. */
418 CVAPI(CvContourScanner)  cvStartFindContours( CvArr* image, CvMemStorage* storage,
419                             int header_size CV_DEFAULT(sizeof(CvContour)),
420                             int mode CV_DEFAULT(CV_RETR_LIST),
421                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
422                             CvPoint offset CV_DEFAULT(cvPoint(0,0)));
423
424 /* Retrieves next contour */
425 CVAPI(CvSeq*)  cvFindNextContour( CvContourScanner scanner );
426
427
428 /* Substitutes the last retrieved contour with the new one
429    (if the substitutor is null, the last retrieved contour is removed from the tree) */
430 CVAPI(void)   cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour );
431
432
433 /* Releases contour scanner and returns pointer to the first outer contour */
434 CVAPI(CvSeq*)  cvEndFindContours( CvContourScanner* scanner );
435
436 /* Approximates a single Freeman chain or a tree of chains to polygonal curves */
437 CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
438                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
439                             double parameter CV_DEFAULT(0),
440                             int  minimal_perimeter CV_DEFAULT(0),
441                             int  recursive CV_DEFAULT(0));
442
443
444 /* Initalizes Freeman chain reader.
445    The reader is used to iteratively get coordinates of all the chain points.
446    If the Freeman codes should be read as is, a simple sequence reader should be used */
447 CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
448
449 /* Retrieves the next chain point */
450 CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader );
451
452
453 /****************************************************************************************\
454 *                                  Motion Analysis                                       *
455 \****************************************************************************************/
456
457 /************************************ optical flow ***************************************/
458
459 /* Calculates optical flow for 2 images using classical Lucas & Kanade algorithm */
460 CVAPI(void)  cvCalcOpticalFlowLK( const CvArr* prev, const CvArr* curr,
461                                   CvSize win_size, CvArr* velx, CvArr* vely );
462
463 /* Calculates optical flow for 2 images using block matching algorithm */
464 CVAPI(void)  cvCalcOpticalFlowBM( const CvArr* prev, const CvArr* curr,
465                                   CvSize block_size, CvSize shift_size,
466                                   CvSize max_range, int use_previous,
467                                   CvArr* velx, CvArr* vely );
468
469 /* Calculates Optical flow for 2 images using Horn & Schunck algorithm */
470 CVAPI(void)  cvCalcOpticalFlowHS( const CvArr* prev, const CvArr* curr,
471                                   int use_previous, CvArr* velx, CvArr* vely,
472                                   double lambda, CvTermCriteria criteria );
473
474 #define  CV_LKFLOW_PYR_A_READY       1
475 #define  CV_LKFLOW_PYR_B_READY       2
476 #define  CV_LKFLOW_INITIAL_GUESSES   4
477 #define  CV_LKFLOW_GET_MIN_EIGENVALS 8
478
479 /* It is Lucas & Kanade method, modified to use pyramids.
480    Also it does several iterations to get optical flow for
481    every point at every pyramid level.
482    Calculates optical flow between two images for certain set of points (i.e.
483    it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
484 CVAPI(void)  cvCalcOpticalFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
485                                      CvArr*  prev_pyr, CvArr*  curr_pyr,
486                                      const CvPoint2D32f* prev_features,
487                                      CvPoint2D32f* curr_features,
488                                      int       count,
489                                      CvSize    win_size,
490                                      int       level,
491                                      char*     status,
492                                      float*    track_error,
493                                      CvTermCriteria criteria,
494                                      int       flags );
495
496
497 /* Modification of a previous sparse optical flow algorithm to calculate
498    affine flow */
499 CVAPI(void)  cvCalcAffineFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
500                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
501                                     const CvPoint2D32f* prev_features,
502                                     CvPoint2D32f* curr_features,
503                                     float* matrices, int  count,
504                                     CvSize win_size, int  level,
505                                     char* status, float* track_error,
506                                     CvTermCriteria criteria, int flags );
507
508 /* Estimate rigid transformation between 2 images or 2 point sets */
509 CVAPI(int)  cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
510                                       CvMat* M, int full_affine );
511
512 /********************************* motion templates *************************************/
513
514 /****************************************************************************************\
515 *        All the motion template functions work only with single channel images.         *
516 *        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *
517 *        Motion history image must have depth IPL_DEPTH_32F,                             *
518 *        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *
519 *        Motion orientation image - IPL_DEPTH_32F                                        *
520 *        Segmentation mask - IPL_DEPTH_32F                                               *
521 *        All the angles are in degrees, all the times are in milliseconds                *
522 \****************************************************************************************/
523
524 /* Updates motion history image given motion silhouette */
525 CVAPI(void)    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
526                                       double timestamp, double duration );
527
528 /* Calculates gradient of the motion history image and fills
529    a mask indicating where the gradient is valid */
530 CVAPI(void)    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
531                                      double delta1, double delta2,
532                                      int aperture_size CV_DEFAULT(3));
533
534 /* Calculates average motion direction within a selected motion region 
535    (region can be selected by setting ROIs and/or by composing a valid gradient mask
536    with the region mask) */
537 CVAPI(double)  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
538                                         const CvArr* mhi, double timestamp,
539                                         double duration );
540
541 /* Splits a motion history image into a few parts corresponding to separate independent motions
542    (e.g. left hand, right hand) */
543 CVAPI(CvSeq*)  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
544                                 CvMemStorage* storage,
545                                 double timestamp, double seg_thresh );
546
547 /*********************** Background statistics accumulation *****************************/
548
549 /* Adds image to accumulator */
550 CVAPI(void)  cvAcc( const CvArr* image, CvArr* sum,
551                     const CvArr* mask CV_DEFAULT(NULL) );
552
553 /* Adds squared image to accumulator */
554 CVAPI(void)  cvSquareAcc( const CvArr* image, CvArr* sqsum,
555                           const CvArr* mask CV_DEFAULT(NULL) );
556
557 /* Adds a product of two images to accumulator */
558 CVAPI(void)  cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc,
559                             const CvArr* mask CV_DEFAULT(NULL) );
560
561 /* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
562 CVAPI(void)  cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
563                            const CvArr* mask CV_DEFAULT(NULL) );
564
565
566 /****************************************************************************************\
567 *                                       Tracking                                         *
568 \****************************************************************************************/
569
570 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
571    from the object histogram back project (extension of meanshift) */
572 CVAPI(int)  cvCamShift( const CvArr* prob_image, CvRect  window,
573                        CvTermCriteria criteria, CvConnectedComp* comp,
574                        CvBox2D* box CV_DEFAULT(NULL) );
575
576 /* Implements MeanShift algorithm - determines object position
577    from the object histogram back project */
578 CVAPI(int)  cvMeanShift( const CvArr* prob_image, CvRect  window,
579                         CvTermCriteria criteria, CvConnectedComp* comp );
580
581 /* Creates ConDensation filter state */
582 CVAPI(CvConDensation*)  cvCreateConDensation( int dynam_params,
583                                              int measure_params,
584                                              int sample_count );
585
586 /* Releases ConDensation filter state */
587 CVAPI(void)  cvReleaseConDensation( CvConDensation** condens );
588
589 /* Updates ConDensation filter by time (predict future state of the system) */
590 CVAPI(void)  cvConDensUpdateByTime( CvConDensation* condens);
591
592 /* Initializes ConDensation filter samples  */
593 CVAPI(void)  cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound );
594
595 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
596 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
597                                 int control_params CV_DEFAULT(0));
598
599 /* Releases Kalman filter state */
600 CVAPI(void)  cvReleaseKalman( CvKalman** kalman);
601
602 /* Updates Kalman filter by time (predicts future state of the system) */
603 CVAPI(const CvMat*)  cvKalmanPredict( CvKalman* kalman,
604                                      const CvMat* control CV_DEFAULT(NULL));
605
606 /* Updates Kalman filter by measurement
607    (corrects state of the system and internal matrices) */
608 CVAPI(const CvMat*)  cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
609
610 /****************************************************************************************\
611 *                              Planar subdivisions                                       *
612 \****************************************************************************************/
613
614 /* Initializes Delaunay triangulation */
615 CVAPI(void)  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
616
617 /* Creates new subdivision */
618 CVAPI(CvSubdiv2D*)  cvCreateSubdiv2D( int subdiv_type, int header_size,
619                                       int vtx_size, int quadedge_size,
620                                       CvMemStorage* storage );
621
622 /************************* high-level subdivision functions ***************************/
623
624 /* Simplified Delaunay diagram creation */
625 CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage )
626 {
627     CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv),
628                          sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage );
629
630     cvInitSubdivDelaunay2D( subdiv, rect );
631     return subdiv;
632 }
633
634
635 /* Inserts new point to the Delaunay triangulation */
636 CVAPI(CvSubdiv2DPoint*)  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
637
638 /* Locates a point within the Delaunay triangulation (finds the edge
639    the point is left to or belongs to, or the triangulation point the given
640    point coinsides with */
641 CVAPI(CvSubdiv2DPointLocation)  cvSubdiv2DLocate(
642                                CvSubdiv2D* subdiv, CvPoint2D32f pt,
643                                CvSubdiv2DEdge* edge,
644                                CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) );
645
646 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */
647 CVAPI(void)  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
648
649
650 /* Removes all Voronoi points from the tesselation */
651 CVAPI(void)  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
652
653
654 /* Finds the nearest to the given point vertex in subdivision. */
655 CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
656
657
658 /************ Basic quad-edge navigation and operations ************/
659
660 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )
661 {
662     return  CV_SUBDIV2D_NEXT_EDGE(edge);
663 }
664
665
666 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )
667 {
668     return  (edge & ~3) + ((edge + rotate) & 3);
669 }
670
671 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )
672 {
673     return edge ^ 2;
674 }
675
676 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )
677 {
678     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
679     edge = e->next[(edge + (int)type) & 3];
680     return  (edge & ~3) + ((edge + ((int)type >> 4)) & 3);
681 }
682
683
684 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )
685 {
686     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
687     return (CvSubdiv2DPoint*)e->pt[edge & 3];
688 }
689
690
691 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )
692 {
693     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
694     return (CvSubdiv2DPoint*)e->pt[(edge + 2) & 3];
695 }
696
697
698 CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
699 {
700     return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
701 }
702
703
704 /****************************************************************************************\
705 *                            Contour Processing and Shape Analysis                       *
706 \****************************************************************************************/
707
708 #define CV_POLY_APPROX_DP 0
709
710 /* Approximates a single polygonal curve (contour) or
711    a tree of polygonal curves (contours) */
712 CVAPI(CvSeq*)  cvApproxPoly( const void* src_seq,
713                              int header_size, CvMemStorage* storage,
714                              int method, double parameter,
715                              int parameter2 CV_DEFAULT(0));
716
717 #define CV_DOMINANT_IPAN 1
718
719 /* Finds high-curvature points of the contour */
720 CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage,
721                                    int method CV_DEFAULT(CV_DOMINANT_IPAN),
722                                    double parameter1 CV_DEFAULT(0),
723                                    double parameter2 CV_DEFAULT(0),
724                                    double parameter3 CV_DEFAULT(0),
725                                    double parameter4 CV_DEFAULT(0));
726
727 /* Calculates perimeter of a contour or length of a part of contour */
728 CVAPI(double)  cvArcLength( const void* curve,
729                             CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
730                             int is_closed CV_DEFAULT(-1));
731 #define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )
732
733 /* Calculates contour boundning rectangle (update=1) or
734    just retrieves pre-calculated rectangle (update=0) */
735 CVAPI(CvRect)  cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) );
736
737 /* Calculates area of a contour or contour segment */
738 CVAPI(double)  cvContourArea( const CvArr* contour,
739                               CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
740
741 /* Finds minimum area rotated rectangle bounding a set of points */
742 CVAPI(CvBox2D)  cvMinAreaRect2( const CvArr* points,
743                                 CvMemStorage* storage CV_DEFAULT(NULL));
744
745 /* Finds minimum enclosing circle for a set of points */
746 CVAPI(int)  cvMinEnclosingCircle( const CvArr* points,
747                                   CvPoint2D32f* center, float* radius );
748
749 #define CV_CONTOURS_MATCH_I1  1
750 #define CV_CONTOURS_MATCH_I2  2
751 #define CV_CONTOURS_MATCH_I3  3
752
753 /* Compares two contours by matching their moments */
754 CVAPI(double)  cvMatchShapes( const void* object1, const void* object2,
755                               int method, double parameter CV_DEFAULT(0));
756
757 /* Builds hierarhical representation of a contour */
758 CVAPI(CvContourTree*)  cvCreateContourTree( const CvSeq* contour,
759                                             CvMemStorage* storage,
760                                             double threshold );
761
762 /* Reconstruct (completelly or partially) contour a from contour tree */
763 CVAPI(CvSeq*)  cvContourFromContourTree( const CvContourTree* tree,
764                                          CvMemStorage* storage,
765                                          CvTermCriteria criteria );
766
767 /* Compares two contour trees */
768 #define  CV_CONTOUR_TREES_MATCH_I1  1
769
770 CVAPI(double)  cvMatchContourTrees( const CvContourTree* tree1,
771                                     const CvContourTree* tree2,
772                                     int method, double threshold );
773
774 /* Calculates histogram of a contour */
775 CVAPI(void)  cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
776
777 #define CV_CLOCKWISE         1
778 #define CV_COUNTER_CLOCKWISE 2
779
780 /* Calculates exact convex hull of 2d point set */
781 CVAPI(CvSeq*) cvConvexHull2( const CvArr* input,
782                              void* hull_storage CV_DEFAULT(NULL),
783                              int orientation CV_DEFAULT(CV_CLOCKWISE),
784                              int return_points CV_DEFAULT(0));
785
786 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */
787 CVAPI(int)  cvCheckContourConvexity( const CvArr* contour );
788
789 /* Finds convexity defects for the contour */
790 CVAPI(CvSeq*)  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
791                                    CvMemStorage* storage CV_DEFAULT(NULL));
792
793 /* Fits ellipse into a set of 2d points */
794 CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points );
795
796 /* Finds minimum rectangle containing two given rectangles */
797 CVAPI(CvRect)  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
798
799 /* Finds coordinates of the box vertices */
800 CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
801
802 /* Initializes sequence header for a matrix (column or row vector) of points -
803    a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */
804 CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat,
805                                  CvContour* contour_header,
806                                  CvSeqBlock* block );
807
808 /* Checks whether the point is inside polygon, outside, on an edge (at a vertex).
809    Returns positive, negative or zero value, correspondingly.
810    Optionally, measures a signed distance between
811    the point and the nearest polygon edge (measure_dist=1) */
812 CVAPI(double) cvPointPolygonTest( const CvArr* contour,
813                                   CvPoint2D32f pt, int measure_dist );
814
815 /****************************************************************************************\
816 *                                  Histogram functions                                   *
817 \****************************************************************************************/
818
819 /* Creates new histogram */
820 CVAPI(CvHistogram*)  cvCreateHist( int dims, int* sizes, int type,
821                                    float** ranges CV_DEFAULT(NULL),
822                                    int uniform CV_DEFAULT(1));
823
824 /* Assignes histogram bin ranges */
825 CVAPI(void)  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
826                                 int uniform CV_DEFAULT(1));
827
828 /* Creates histogram header for array */
829 CVAPI(CvHistogram*)  cvMakeHistHeaderForArray(
830                             int  dims, int* sizes, CvHistogram* hist,
831                             float* data, float** ranges CV_DEFAULT(NULL),
832                             int uniform CV_DEFAULT(1));
833
834 /* Releases histogram */
835 CVAPI(void)  cvReleaseHist( CvHistogram** hist );
836
837 /* Clears all the histogram bins */
838 CVAPI(void)  cvClearHist( CvHistogram* hist );
839
840 /* Finds indices and values of minimum and maximum histogram bins */
841 CVAPI(void)  cvGetMinMaxHistValue( const CvHistogram* hist,
842                                    float* min_value, float* max_value,
843                                    int* min_idx CV_DEFAULT(NULL),
844                                    int* max_idx CV_DEFAULT(NULL));
845
846
847 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.
848    After that sum of histogram bins is equal to <factor> */
849 CVAPI(void)  cvNormalizeHist( CvHistogram* hist, double factor );
850
851
852 /* Clear all histogram bins that are below the threshold */
853 CVAPI(void)  cvThreshHist( CvHistogram* hist, double threshold );
854
855 #define CV_COMP_CORREL        0
856 #define CV_COMP_CHISQR        1
857 #define CV_COMP_INTERSECT     2
858 #define CV_COMP_BHATTACHARYYA 3
859
860 /* Compares two histogram */
861 CVAPI(double)  cvCompareHist( const CvHistogram* hist1,
862                               const CvHistogram* hist2,
863                               int method);
864
865 /* Copies one histogram to another. Destination histogram is created if
866    the destination pointer is NULL */
867 CVAPI(void)  cvCopyHist( const CvHistogram* src, CvHistogram** dst );
868
869
870 /* Calculates bayesian probabilistic histograms
871    (each or src and dst is an array of <number> histograms */
872 CVAPI(void)  cvCalcBayesianProb( CvHistogram** src, int number,
873                                 CvHistogram** dst);
874
875 /* Calculates array histogram */
876 CVAPI(void)  cvCalcArrHist( CvArr** arr, CvHistogram* hist,
877                             int accumulate CV_DEFAULT(0),
878                             const CvArr* mask CV_DEFAULT(NULL) );
879
880 CV_INLINE  void  cvCalcHist( IplImage** image, CvHistogram* hist,
881                              int accumulate CV_DEFAULT(0),
882                              const CvArr* mask CV_DEFAULT(NULL) )
883 {
884     cvCalcArrHist( (CvArr**)image, hist, accumulate, mask );
885 }
886
887 /* Calculates back project */
888 CVAPI(void)  cvCalcArrBackProject( CvArr** image, CvArr* dst,
889                                    const CvHistogram* hist );
890 #define  cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist)
891
892
893 /* Does some sort of template matching but compares histograms of
894    template and each window location */
895 CVAPI(void)  cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range,
896                                         CvHistogram* hist, int method,
897                                         double factor );
898 #define  cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \
899      cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor )
900
901
902 /* calculates probabilistic density (divides one histogram by another) */
903 CVAPI(void)  cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2,
904                                 CvHistogram* dst_hist, double scale CV_DEFAULT(255) );
905
906 /* equalizes histogram of 8-bit single-channel image */
907 CVAPI(void)  cvEqualizeHist( const CvArr* src, CvArr* dst );
908
909
910 #define  CV_VALUE  1
911 #define  CV_ARRAY  2
912 /* Updates active contour in order to minimize its cummulative
913    (internal and external) energy. */
914 CVAPI(void)  cvSnakeImage( const IplImage* image, CvPoint* points,
915                            int  length, float* alpha,
916                            float* beta, float* gamma,
917                            int coeff_usage, CvSize  win,
918                            CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
919
920 /* Calculates the cooficients of the homography matrix */
921 CVAPI(void)  cvCalcImageHomography( float* line, CvPoint3D32f* center,
922                                     float* intrinsic, float* homography );
923
924 #define CV_DIST_MASK_3   3
925 #define CV_DIST_MASK_5   5
926 #define CV_DIST_MASK_PRECISE 0
927
928 /* Applies distance transform to binary image */
929 CVAPI(void)  cvDistTransform( const CvArr* src, CvArr* dst,
930                               int distance_type CV_DEFAULT(CV_DIST_L2),
931                               int mask_size CV_DEFAULT(3),
932                               const float* mask CV_DEFAULT(NULL),
933                               CvArr* labels CV_DEFAULT(NULL));
934
935
936 /* Types of thresholding */
937 #define CV_THRESH_BINARY      0  /* value = value > threshold ? max_value : 0       */
938 #define CV_THRESH_BINARY_INV  1  /* value = value > threshold ? 0 : max_value       */
939 #define CV_THRESH_TRUNC       2  /* value = value > threshold ? threshold : value   */
940 #define CV_THRESH_TOZERO      3  /* value = value > threshold ? value : 0           */
941 #define CV_THRESH_TOZERO_INV  4  /* value = value > threshold ? 0 : value           */
942 #define CV_THRESH_MASK        7
943
944 #define CV_THRESH_OTSU        8  /* use Otsu algorithm to choose the optimal threshold value;
945                                     combine the flag with one of the above CV_THRESH_* values */
946
947 /* Applies fixed-level threshold to grayscale image.
948    This is a basic operation applied before retrieving contours */
949 CVAPI(double)  cvThreshold( const CvArr*  src, CvArr*  dst,
950                             double  threshold, double  max_value,
951                             int threshold_type );
952
953 #define CV_ADAPTIVE_THRESH_MEAN_C  0
954 #define CV_ADAPTIVE_THRESH_GAUSSIAN_C  1
955
956 /* Applies adaptive threshold to grayscale image.
957    The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and
958    CV_ADAPTIVE_THRESH_GAUSSIAN_C are:
959    neighborhood size (3, 5, 7 etc.),
960    and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */
961 CVAPI(void)  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
962                                   int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
963                                   int threshold_type CV_DEFAULT(CV_THRESH_BINARY),
964                                   int block_size CV_DEFAULT(3),
965                                   double param1 CV_DEFAULT(5));
966
967 #define CV_FLOODFILL_FIXED_RANGE (1 << 16)
968 #define CV_FLOODFILL_MASK_ONLY   (1 << 17)
969
970 /* Fills the connected component until the color difference gets large enough */
971 CVAPI(void)  cvFloodFill( CvArr* image, CvPoint seed_point,
972                           CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)),
973                           CvScalar up_diff CV_DEFAULT(cvScalarAll(0)),
974                           CvConnectedComp* comp CV_DEFAULT(NULL),
975                           int flags CV_DEFAULT(4),
976                           CvArr* mask CV_DEFAULT(NULL));
977
978 /****************************************************************************************\
979 *                                  Feature detection                                     *
980 \****************************************************************************************/
981
982 #define CV_CANNY_L2_GRADIENT  (1 << 31)
983
984 /* Runs canny edge detector */
985 CVAPI(void)  cvCanny( const CvArr* image, CvArr* edges, double threshold1,
986                       double threshold2, int  aperture_size CV_DEFAULT(3) );
987
988 /* Calculates constraint image for corner detection
989    Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.
990    Applying threshold to the result gives coordinates of corners */
991 CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners,
992                               int aperture_size CV_DEFAULT(3) );
993
994 /* Calculates eigen values and vectors of 2x2
995    gradient covariation matrix at every image pixel */
996 CVAPI(void)  cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,
997                                       int block_size, int aperture_size CV_DEFAULT(3) );
998
999 /* Calculates minimal eigenvalue for 2x2 gradient covariation matrix at
1000    every image pixel */
1001 CVAPI(void)  cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval,
1002                                  int block_size, int aperture_size CV_DEFAULT(3) );
1003
1004 /* Harris corner detector:
1005    Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */
1006 CVAPI(void)  cvCornerHarris( const CvArr* image, CvArr* harris_responce,
1007                              int block_size, int aperture_size CV_DEFAULT(3),
1008                              double k CV_DEFAULT(0.04) );
1009
1010 /* Adjust corner position using some sort of gradient search */
1011 CVAPI(void)  cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,
1012                                  int count, CvSize win, CvSize zero_zone,
1013                                  CvTermCriteria  criteria );
1014
1015 /* Finds a sparse set of points within the selected region
1016    that seem to be easy to track */
1017 CVAPI(void)  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
1018                                    CvArr* temp_image, CvPoint2D32f* corners,
1019                                    int* corner_count, double  quality_level,
1020                                    double  min_distance,
1021                                    const CvArr* mask CV_DEFAULT(NULL),
1022                                    int block_size CV_DEFAULT(3),
1023                                    int use_harris CV_DEFAULT(0),
1024                                    double k CV_DEFAULT(0.04) );
1025
1026 #define CV_HOUGH_STANDARD 0
1027 #define CV_HOUGH_PROBABILISTIC 1
1028 #define CV_HOUGH_MULTI_SCALE 2
1029 #define CV_HOUGH_GRADIENT 3
1030
1031 /* Finds lines on binary image using one of several methods.
1032    line_storage is either memory storage or 1 x <max number of lines> CvMat, its
1033    number of columns is changed by the function.
1034    method is one of CV_HOUGH_*;
1035    rho, theta and threshold are used for each of those methods;
1036    param1 ~ line length, param2 ~ line gap - for probabilistic,
1037    param1 ~ srn, param2 ~ stn - for multi-scale */
1038 CVAPI(CvSeq*)  cvHoughLines2( CvArr* image, void* line_storage, int method, 
1039                               double rho, double theta, int threshold,
1040                               double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
1041
1042 /* Finds circles in the image */
1043 CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,
1044                               int method, double dp, double min_dist,
1045                               double param1 CV_DEFAULT(100),
1046                               double param2 CV_DEFAULT(100),
1047                               int min_radius CV_DEFAULT(0),
1048                               int max_radius CV_DEFAULT(0));
1049
1050 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */
1051 CVAPI(void)  cvFitLine( const CvArr* points, int dist_type, double param,
1052                         double reps, double aeps, float* line );
1053
1054
1055
1056 struct CvFeatureTree;
1057
1058 /* Constructs kd-tree from set of feature descriptors */
1059 CVAPI(CvFeatureTree*) cvCreateFeatureTree(CvMat* desc);
1060
1061 /* Release kd-tree */
1062 CVAPI(void) cvReleaseFeatureTree(CvFeatureTree* tr);
1063
1064 /* Searches kd-tree for k nearest neighbors of given reference points,
1065    searching at most emax leaves. */
1066 CVAPI(void) cvFindFeatures(CvFeatureTree* tr, CvMat* desc,
1067                     CvMat* results, CvMat* dist, int k = 2, int emax = 20);
1068
1069 /* Search kd-tree for all points that are inlier to given rect region. */
1070 CVAPI(int) cvFindFeaturesBoxed(CvFeatureTree* tr,
1071                     CvMat* bounds_min, CvMat* bounds_max,
1072                     CvMat* results);
1073
1074
1075 /****************************************************************************************\
1076 *                         Haar-like Object Detection functions                           *
1077 \****************************************************************************************/
1078
1079 /* Loads haar classifier cascade from a directory.
1080    It is obsolete: convert your cascade to xml and use cvLoad instead */
1081 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
1082                     const char* directory, CvSize orig_window_size);
1083
1084 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
1085
1086 #define CV_HAAR_DO_CANNY_PRUNING    1
1087 #define CV_HAAR_SCALE_IMAGE         2
1088 #define CV_HAAR_FIND_BIGGEST_OBJECT 4 
1089 #define CV_HAAR_DO_ROUGH_SEARCH     8
1090
1091 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
1092                      CvHaarClassifierCascade* cascade,
1093                      CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
1094                      int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
1095                      CvSize min_size CV_DEFAULT(cvSize(0,0)));
1096
1097 /* sets images for haar classifier cascade */
1098 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1099                                                 const CvArr* sum, const CvArr* sqsum,
1100                                                 const CvArr* tilted_sum, double scale );
1101
1102 /* runs the cascade on the specified window */
1103 CVAPI(int) cvRunHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1104                                       CvPoint pt, int start_stage CV_DEFAULT(0));
1105
1106 /****************************************************************************************\
1107 *                     Camera Calibration and Rectification functions                     *
1108 \****************************************************************************************/
1109
1110 /* transforms the input image to compensate lens distortion */
1111 CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
1112                           const CvMat* intrinsic_matrix,
1113                           const CvMat* distortion_coeffs );
1114
1115 /* computes transformation map from intrinsic camera parameters
1116    that can used by cvRemap */
1117 CVAPI(void) cvInitUndistortMap( const CvMat* intrinsic_matrix,
1118                                 const CvMat* distortion_coeffs,
1119                                 CvArr* mapx, CvArr* mapy );
1120
1121 /* converts rotation vector to rotation matrix or vice versa */
1122 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
1123                          CvMat* jacobian CV_DEFAULT(0) );
1124
1125 /* finds perspective transformation between the object plane and image (view) plane */
1126 CVAPI(void) cvFindHomography( const CvMat* src_points,
1127                               const CvMat* dst_points,
1128                               CvMat* homography );
1129
1130 /* Computes RQ decomposition for 3x3 matrices */
1131 CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
1132                            CvMat *matrixQx CV_DEFAULT(NULL),
1133                            CvMat *matrixQy CV_DEFAULT(NULL),
1134                            CvMat *matrixQz CV_DEFAULT(NULL),
1135                            CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1136
1137 /* Computes projection matrix decomposition */
1138 CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
1139                                          CvMat *rotMatr, CvMat *posVect,
1140                                          CvMat *rotMatrX CV_DEFAULT(NULL),
1141                                          CvMat *rotMatrY CV_DEFAULT(NULL),
1142                                          CvMat *rotMatrZ CV_DEFAULT(NULL),
1143                                          CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1144
1145 /* projects object points to the view plane using
1146    the specified extrinsic and intrinsic camera parameters */
1147 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
1148                               const CvMat* translation_vector, const CvMat* intrinsic_matrix,
1149                               const CvMat* distortion_coeffs, CvMat* image_points,
1150                               CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
1151                               CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
1152                               CvMat* dpddist CV_DEFAULT(NULL) );
1153
1154 /* finds extrinsic camera parameters from
1155    a few known corresponding point pairs and intrinsic parameters */
1156 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
1157                                           const CvMat* image_points,
1158                                           const CvMat* intrinsic_matrix,
1159                                           const CvMat* distortion_coeffs,
1160                                           CvMat* rotation_vector,
1161                                           CvMat* translation_vector );
1162
1163 #define CV_CALIB_USE_INTRINSIC_GUESS  1
1164 #define CV_CALIB_FIX_ASPECT_RATIO     2
1165 #define CV_CALIB_FIX_PRINCIPAL_POINT  4
1166 #define CV_CALIB_ZERO_TANGENT_DIST    8
1167
1168 /* finds intrinsic and extrinsic camera parameters
1169    from a few views of known calibration pattern */
1170 CVAPI(void) cvCalibrateCamera2( const CvMat* object_points,
1171                                 const CvMat* image_points,
1172                                 const CvMat* point_counts,
1173                                 CvSize image_size,
1174                                 CvMat* intrinsic_matrix,
1175                                 CvMat* distortion_coeffs,
1176                                 CvMat* rotation_vectors CV_DEFAULT(NULL),
1177                                 CvMat* translation_vectors CV_DEFAULT(NULL),
1178                                 int flags CV_DEFAULT(0) );
1179
1180 CVAPI(void) cvCalibrationMatrixValues( const CvMat *calibMatr,
1181                                 int imgWidth, int imgHeight,
1182                                 double apertureWidth CV_DEFAULT(0),
1183                                 double apertureHeight CV_DEFAULT(0),
1184                                 double *fovx CV_DEFAULT(NULL),
1185                                 double *fovy CV_DEFAULT(NULL),
1186                                 double *focalLength CV_DEFAULT(NULL),
1187                                 CvPoint2D64f *principalPoint CV_DEFAULT(NULL),
1188                                 double *pixelAspectRatio CV_DEFAULT(NULL));
1189
1190 #define CV_CALIB_CB_ADAPTIVE_THRESH  1
1191 #define CV_CALIB_CB_NORMALIZE_IMAGE  2
1192 #define CV_CALIB_CB_FILTER_QUADS     4 
1193
1194 /* Detects corners on a chessboard calibration pattern */
1195 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
1196                                     CvPoint2D32f* corners,
1197                                     int* corner_count CV_DEFAULT(NULL),
1198                                     int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH) );
1199
1200 /* Draws individual chessboard corners or the whole chessboard detected */
1201 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
1202                                      CvPoint2D32f* corners,
1203                                      int count, int pattern_was_found );
1204
1205 typedef struct CvPOSITObject CvPOSITObject;
1206
1207 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
1208 CVAPI(CvPOSITObject*)  cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
1209
1210
1211 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
1212    an object given its model and projection in a weak-perspective case */
1213 CVAPI(void)  cvPOSIT(  CvPOSITObject* posit_object, CvPoint2D32f* image_points,
1214                        double focal_length, CvTermCriteria criteria,
1215                        CvMatr32f rotation_matrix, CvVect32f translation_vector);
1216
1217 /* Releases CvPOSITObject structure */
1218 CVAPI(void)  cvReleasePOSITObject( CvPOSITObject**  posit_object );
1219
1220
1221 /****************************************************************************************\
1222 *                                 Epipolar Geometry                                      *
1223 \****************************************************************************************/
1224
1225 /* updates the number of RANSAC iterations */
1226 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
1227                                    int model_points, int max_iters );
1228
1229 CVAPI(void) cvConvertPointsHomogenious( const CvMat* src, CvMat* dst );
1230
1231 /* Calculates fundamental matrix given a set of corresponding points */
1232 #define CV_FM_7POINT 1
1233 #define CV_FM_8POINT 2
1234 #define CV_FM_LMEDS_ONLY  4
1235 #define CV_FM_RANSAC_ONLY 8
1236 #define CV_FM_LMEDS (CV_FM_LMEDS_ONLY + CV_FM_8POINT)
1237 #define CV_FM_RANSAC (CV_FM_RANSAC_ONLY + CV_FM_8POINT)
1238 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
1239                                  CvMat* fundamental_matrix,
1240                                  int method CV_DEFAULT(CV_FM_RANSAC),
1241                                  double param1 CV_DEFAULT(1.), double param2 CV_DEFAULT(0.99),
1242                                  CvMat* status CV_DEFAULT(NULL) );
1243
1244 /* For each input point on one of images
1245    computes parameters of the corresponding
1246    epipolar line on the other image */
1247 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
1248                                          int which_image,
1249                                          const CvMat* fundamental_matrix,
1250                                          CvMat* correspondent_lines );
1251
1252 #ifdef __cplusplus
1253 }
1254 #endif
1255
1256 #ifdef __cplusplus
1257 #include "cv.hpp"
1258 #endif
1259
1260 /****************************************************************************************\
1261 *                                 Backward compatibility                                 *
1262 \****************************************************************************************/
1263
1264 #ifndef CV_NO_BACKWARD_COMPATIBILITY
1265 #include "cvcompat.h"
1266 #endif
1267
1268 #endif /*_CV_H_*/