Move the sources to trunk
[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 param1 CV_DEFAULT(3),
84                       int param2 CV_DEFAULT(0),
85                       double param3 CV_DEFAULT(0),
86                       double param4 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
478 /* It is Lucas & Kanade method, modified to use pyramids.
479    Also it does several iterations to get optical flow for
480    every point at every pyramid level.
481    Calculates optical flow between two images for certain set of points (i.e.
482    it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
483 CVAPI(void)  cvCalcOpticalFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
484                                      CvArr*  prev_pyr, CvArr*  curr_pyr,
485                                      const CvPoint2D32f* prev_features,
486                                      CvPoint2D32f* curr_features,
487                                      int       count,
488                                      CvSize    win_size,
489                                      int       level,
490                                      char*     status,
491                                      float*    track_error,
492                                      CvTermCriteria criteria,
493                                      int       flags );
494
495
496 /* Modification of a previous sparse optical flow algorithm to calculate
497    affine flow */
498 CVAPI(void)  cvCalcAffineFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
499                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
500                                     const CvPoint2D32f* prev_features,
501                                     CvPoint2D32f* curr_features,
502                                     float* matrices, int  count,
503                                     CvSize win_size, int  level,
504                                     char* status, float* track_error,
505                                     CvTermCriteria criteria, int flags );
506
507 /* Estimate rigid transformation between 2 images or 2 point sets */
508 CVAPI(int)  cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
509                                       CvMat* M, int full_affine );
510
511 /********************************* motion templates *************************************/
512
513 /****************************************************************************************\
514 *        All the motion template functions work only with single channel images.         *
515 *        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *
516 *        Motion history image must have depth IPL_DEPTH_32F,                             *
517 *        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *
518 *        Motion orientation image - IPL_DEPTH_32F                                        *
519 *        Segmentation mask - IPL_DEPTH_32F                                               *
520 *        All the angles are in degrees, all the times are in milliseconds                *
521 \****************************************************************************************/
522
523 /* Updates motion history image given motion silhouette */
524 CVAPI(void)    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
525                                       double timestamp, double duration );
526
527 /* Calculates gradient of the motion history image and fills
528    a mask indicating where the gradient is valid */
529 CVAPI(void)    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
530                                      double delta1, double delta2,
531                                      int aperture_size CV_DEFAULT(3));
532
533 /* Calculates average motion direction within a selected motion region 
534    (region can be selected by setting ROIs and/or by composing a valid gradient mask
535    with the region mask) */
536 CVAPI(double)  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
537                                         const CvArr* mhi, double timestamp,
538                                         double duration );
539
540 /* Splits a motion history image into a few parts corresponding to separate independent motions
541    (e.g. left hand, right hand) */
542 CVAPI(CvSeq*)  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
543                                 CvMemStorage* storage,
544                                 double timestamp, double seg_thresh );
545
546 /*********************** Background statistics accumulation *****************************/
547
548 /* Adds image to accumulator */
549 CVAPI(void)  cvAcc( const CvArr* image, CvArr* sum,
550                     const CvArr* mask CV_DEFAULT(NULL) );
551
552 /* Adds squared image to accumulator */
553 CVAPI(void)  cvSquareAcc( const CvArr* image, CvArr* sqsum,
554                           const CvArr* mask CV_DEFAULT(NULL) );
555
556 /* Adds a product of two images to accumulator */
557 CVAPI(void)  cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc,
558                             const CvArr* mask CV_DEFAULT(NULL) );
559
560 /* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
561 CVAPI(void)  cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
562                            const CvArr* mask CV_DEFAULT(NULL) );
563
564
565 /****************************************************************************************\
566 *                                       Tracking                                         *
567 \****************************************************************************************/
568
569 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
570    from the object histogram back project (extension of meanshift) */
571 CVAPI(int)  cvCamShift( const CvArr* prob_image, CvRect  window,
572                        CvTermCriteria criteria, CvConnectedComp* comp,
573                        CvBox2D* box CV_DEFAULT(NULL) );
574
575 /* Implements MeanShift algorithm - determines object position
576    from the object histogram back project */
577 CVAPI(int)  cvMeanShift( const CvArr* prob_image, CvRect  window,
578                         CvTermCriteria criteria, CvConnectedComp* comp );
579
580 /* Creates ConDensation filter state */
581 CVAPI(CvConDensation*)  cvCreateConDensation( int dynam_params,
582                                              int measure_params,
583                                              int sample_count );
584
585 /* Releases ConDensation filter state */
586 CVAPI(void)  cvReleaseConDensation( CvConDensation** condens );
587
588 /* Updates ConDensation filter by time (predict future state of the system) */
589 CVAPI(void)  cvConDensUpdateByTime( CvConDensation* condens);
590
591 /* Initializes ConDensation filter samples  */
592 CVAPI(void)  cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound );
593
594 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
595 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
596                                 int control_params CV_DEFAULT(0));
597
598 /* Releases Kalman filter state */
599 CVAPI(void)  cvReleaseKalman( CvKalman** kalman);
600
601 /* Updates Kalman filter by time (predicts future state of the system) */
602 CVAPI(const CvMat*)  cvKalmanPredict( CvKalman* kalman,
603                                      const CvMat* control CV_DEFAULT(NULL));
604
605 /* Updates Kalman filter by measurement
606    (corrects state of the system and internal matrices) */
607 CVAPI(const CvMat*)  cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
608
609 /****************************************************************************************\
610 *                              Planar subdivisions                                       *
611 \****************************************************************************************/
612
613 /* Initializes Delaunay triangulation */
614 CVAPI(void)  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
615
616 /* Creates new subdivision */
617 CVAPI(CvSubdiv2D*)  cvCreateSubdiv2D( int subdiv_type, int header_size,
618                                       int vtx_size, int quadedge_size,
619                                       CvMemStorage* storage );
620
621 /************************* high-level subdivision functions ***************************/
622
623 /* Simplified Delaunay diagram creation */
624 CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage )
625 {
626     CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv),
627                          sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage );
628
629     cvInitSubdivDelaunay2D( subdiv, rect );
630     return subdiv;
631 }
632
633
634 /* Inserts new point to the Delaunay triangulation */
635 CVAPI(CvSubdiv2DPoint*)  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
636
637 /* Locates a point within the Delaunay triangulation (finds the edge
638    the point is left to or belongs to, or the triangulation point the given
639    point coinsides with */
640 CVAPI(CvSubdiv2DPointLocation)  cvSubdiv2DLocate(
641                                CvSubdiv2D* subdiv, CvPoint2D32f pt,
642                                CvSubdiv2DEdge* edge,
643                                CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) );
644
645 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */
646 CVAPI(void)  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
647
648
649 /* Removes all Voronoi points from the tesselation */
650 CVAPI(void)  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
651
652
653 /* Finds the nearest to the given point vertex in subdivision. */
654 CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
655
656
657 /************ Basic quad-edge navigation and operations ************/
658
659 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )
660 {
661     return  CV_SUBDIV2D_NEXT_EDGE(edge);
662 }
663
664
665 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )
666 {
667     return  (edge & ~3) + ((edge + rotate) & 3);
668 }
669
670 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )
671 {
672     return edge ^ 2;
673 }
674
675 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )
676 {
677     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
678     edge = e->next[(edge + (int)type) & 3];
679     return  (edge & ~3) + ((edge + ((int)type >> 4)) & 3);
680 }
681
682
683 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )
684 {
685     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
686     return (CvSubdiv2DPoint*)e->pt[edge & 3];
687 }
688
689
690 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )
691 {
692     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
693     return (CvSubdiv2DPoint*)e->pt[(edge + 2) & 3];
694 }
695
696
697 CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
698 {
699     return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
700 }
701
702
703 /****************************************************************************************\
704 *                            Contour Processing and Shape Analysis                       *
705 \****************************************************************************************/
706
707 #define CV_POLY_APPROX_DP 0
708
709 /* Approximates a single polygonal curve (contour) or
710    a tree of polygonal curves (contours) */
711 CVAPI(CvSeq*)  cvApproxPoly( const void* src_seq,
712                              int header_size, CvMemStorage* storage,
713                              int method, double parameter,
714                              int parameter2 CV_DEFAULT(0));
715
716 #define CV_DOMINANT_IPAN 1
717
718 /* Finds high-curvature points of the contour */
719 CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage,
720                                    int method CV_DEFAULT(CV_DOMINANT_IPAN),
721                                    double parameter1 CV_DEFAULT(0),
722                                    double parameter2 CV_DEFAULT(0),
723                                    double parameter3 CV_DEFAULT(0),
724                                    double parameter4 CV_DEFAULT(0));
725
726 /* Calculates perimeter of a contour or length of a part of contour */
727 CVAPI(double)  cvArcLength( const void* curve,
728                             CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
729                             int is_closed CV_DEFAULT(-1));
730 #define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )
731
732 /* Calculates contour boundning rectangle (update=1) or
733    just retrieves pre-calculated rectangle (update=0) */
734 CVAPI(CvRect)  cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) );
735
736 /* Calculates area of a contour or contour segment */
737 CVAPI(double)  cvContourArea( const CvArr* contour,
738                               CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
739
740 /* Finds minimum area rotated rectangle bounding a set of points */
741 CVAPI(CvBox2D)  cvMinAreaRect2( const CvArr* points,
742                                 CvMemStorage* storage CV_DEFAULT(NULL));
743
744 /* Finds minimum enclosing circle for a set of points */
745 CVAPI(int)  cvMinEnclosingCircle( const CvArr* points,
746                                   CvPoint2D32f* center, float* radius );
747
748 #define CV_CONTOURS_MATCH_I1  1
749 #define CV_CONTOURS_MATCH_I2  2
750 #define CV_CONTOURS_MATCH_I3  3
751
752 /* Compares two contours by matching their moments */
753 CVAPI(double)  cvMatchShapes( const void* object1, const void* object2,
754                               int method, double parameter CV_DEFAULT(0));
755
756 /* Builds hierarhical representation of a contour */
757 CVAPI(CvContourTree*)  cvCreateContourTree( const CvSeq* contour,
758                                             CvMemStorage* storage,
759                                             double threshold );
760
761 /* Reconstruct (completelly or partially) contour a from contour tree */
762 CVAPI(CvSeq*)  cvContourFromContourTree( const CvContourTree* tree,
763                                          CvMemStorage* storage,
764                                          CvTermCriteria criteria );
765
766 /* Compares two contour trees */
767 #define  CV_CONTOUR_TREES_MATCH_I1  1
768
769 CVAPI(double)  cvMatchContourTrees( const CvContourTree* tree1,
770                                     const CvContourTree* tree2,
771                                     int method, double threshold );
772
773 /* Calculates histogram of a contour */
774 CVAPI(void)  cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
775
776 #define CV_CLOCKWISE         1
777 #define CV_COUNTER_CLOCKWISE 2
778
779 /* Calculates exact convex hull of 2d point set */
780 CVAPI(CvSeq*) cvConvexHull2( const CvArr* input,
781                              void* hull_storage CV_DEFAULT(NULL),
782                              int orientation CV_DEFAULT(CV_CLOCKWISE),
783                              int return_points CV_DEFAULT(0));
784
785 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */
786 CVAPI(int)  cvCheckContourConvexity( const CvArr* contour );
787
788 /* Finds convexity defects for the contour */
789 CVAPI(CvSeq*)  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
790                                    CvMemStorage* storage CV_DEFAULT(NULL));
791
792 /* Fits ellipse into a set of 2d points */
793 CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points );
794
795 /* Finds minimum rectangle containing two given rectangles */
796 CVAPI(CvRect)  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
797
798 /* Finds coordinates of the box vertices */
799 CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
800
801 /* Initializes sequence header for a matrix (column or row vector) of points -
802    a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */
803 CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat,
804                                  CvContour* contour_header,
805                                  CvSeqBlock* block );
806
807 /* Checks whether the point is inside polygon, outside, on an edge (at a vertex).
808    Returns positive, negative or zero value, correspondingly.
809    Optionally, measures a signed distance between
810    the point and the nearest polygon edge (measure_dist=1) */
811 CVAPI(double) cvPointPolygonTest( const CvArr* contour,
812                                   CvPoint2D32f pt, int measure_dist );
813
814 /****************************************************************************************\
815 *                                  Histogram functions                                   *
816 \****************************************************************************************/
817
818 /* Creates new histogram */
819 CVAPI(CvHistogram*)  cvCreateHist( int dims, int* sizes, int type,
820                                    float** ranges CV_DEFAULT(NULL),
821                                    int uniform CV_DEFAULT(1));
822
823 /* Assignes histogram bin ranges */
824 CVAPI(void)  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
825                                 int uniform CV_DEFAULT(1));
826
827 /* Creates histogram header for array */
828 CVAPI(CvHistogram*)  cvMakeHistHeaderForArray(
829                             int  dims, int* sizes, CvHistogram* hist,
830                             float* data, float** ranges CV_DEFAULT(NULL),
831                             int uniform CV_DEFAULT(1));
832
833 /* Releases histogram */
834 CVAPI(void)  cvReleaseHist( CvHistogram** hist );
835
836 /* Clears all the histogram bins */
837 CVAPI(void)  cvClearHist( CvHistogram* hist );
838
839 /* Finds indices and values of minimum and maximum histogram bins */
840 CVAPI(void)  cvGetMinMaxHistValue( const CvHistogram* hist,
841                                    float* min_value, float* max_value,
842                                    int* min_idx CV_DEFAULT(NULL),
843                                    int* max_idx CV_DEFAULT(NULL));
844
845
846 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.
847    After that sum of histogram bins is equal to <factor> */
848 CVAPI(void)  cvNormalizeHist( CvHistogram* hist, double factor );
849
850
851 /* Clear all histogram bins that are below the threshold */
852 CVAPI(void)  cvThreshHist( CvHistogram* hist, double threshold );
853
854 #define CV_COMP_CORREL        0
855 #define CV_COMP_CHISQR        1
856 #define CV_COMP_INTERSECT     2
857 #define CV_COMP_BHATTACHARYYA 3
858
859 /* Compares two histogram */
860 CVAPI(double)  cvCompareHist( const CvHistogram* hist1,
861                               const CvHistogram* hist2,
862                               int method);
863
864 /* Copies one histogram to another. Destination histogram is created if
865    the destination pointer is NULL */
866 CVAPI(void)  cvCopyHist( const CvHistogram* src, CvHistogram** dst );
867
868
869 /* Calculates bayesian probabilistic histograms
870    (each or src and dst is an array of <number> histograms */
871 CVAPI(void)  cvCalcBayesianProb( CvHistogram** src, int number,
872                                 CvHistogram** dst);
873
874 /* Calculates array histogram */
875 CVAPI(void)  cvCalcArrHist( CvArr** arr, CvHistogram* hist,
876                             int accumulate CV_DEFAULT(0),
877                             const CvArr* mask CV_DEFAULT(NULL) );
878
879 CV_INLINE  void  cvCalcHist( IplImage** image, CvHistogram* hist,
880                              int accumulate CV_DEFAULT(0),
881                              const CvArr* mask CV_DEFAULT(NULL) )
882 {
883     cvCalcArrHist( (CvArr**)image, hist, accumulate, mask );
884 }
885
886 /* Calculates back project */
887 CVAPI(void)  cvCalcArrBackProject( CvArr** image, CvArr* dst,
888                                    const CvHistogram* hist );
889 #define  cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist)
890
891
892 /* Does some sort of template matching but compares histograms of
893    template and each window location */
894 CVAPI(void)  cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range,
895                                         CvHistogram* hist, int method,
896                                         double factor );
897 #define  cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \
898      cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor )
899
900
901 /* calculates probabilistic density (divides one histogram by another) */
902 CVAPI(void)  cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2,
903                                 CvHistogram* dst_hist, double scale CV_DEFAULT(255) );
904
905 /* equalizes histogram of 8-bit single-channel image */
906 CVAPI(void)  cvEqualizeHist( const CvArr* src, CvArr* dst );
907
908
909 #define  CV_VALUE  1
910 #define  CV_ARRAY  2
911 /* Updates active contour in order to minimize its cummulative
912    (internal and external) energy. */
913 CVAPI(void)  cvSnakeImage( const IplImage* image, CvPoint* points,
914                            int  length, float* alpha,
915                            float* beta, float* gamma,
916                            int coeff_usage, CvSize  win,
917                            CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
918
919 /* Calculates the cooficients of the homography matrix */
920 CVAPI(void)  cvCalcImageHomography( float* line, CvPoint3D32f* center,
921                                     float* intrinsic, float* homography );
922
923 #define CV_DIST_MASK_3   3
924 #define CV_DIST_MASK_5   5
925 #define CV_DIST_MASK_PRECISE 0
926
927 /* Applies distance transform to binary image */
928 CVAPI(void)  cvDistTransform( const CvArr* src, CvArr* dst,
929                               int distance_type CV_DEFAULT(CV_DIST_L2),
930                               int mask_size CV_DEFAULT(3),
931                               const float* mask CV_DEFAULT(NULL),
932                               CvArr* labels CV_DEFAULT(NULL));
933
934
935 /* Types of thresholding */
936 #define CV_THRESH_BINARY      0  /* value = value > threshold ? max_value : 0       */
937 #define CV_THRESH_BINARY_INV  1  /* value = value > threshold ? 0 : max_value       */
938 #define CV_THRESH_TRUNC       2  /* value = value > threshold ? threshold : value   */
939 #define CV_THRESH_TOZERO      3  /* value = value > threshold ? value : 0           */
940 #define CV_THRESH_TOZERO_INV  4  /* value = value > threshold ? 0 : value           */
941 #define CV_THRESH_MASK        7
942
943 #define CV_THRESH_OTSU        8  /* use Otsu algorithm to choose the optimal threshold value;
944                                     combine the flag with one of the above CV_THRESH_* values */
945
946 /* Applies fixed-level threshold to grayscale image.
947    This is a basic operation applied before retrieving contours */
948 CVAPI(double)  cvThreshold( const CvArr*  src, CvArr*  dst,
949                             double  threshold, double  max_value,
950                             int threshold_type );
951
952 #define CV_ADAPTIVE_THRESH_MEAN_C  0
953 #define CV_ADAPTIVE_THRESH_GAUSSIAN_C  1
954
955 /* Applies adaptive threshold to grayscale image.
956    The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and
957    CV_ADAPTIVE_THRESH_GAUSSIAN_C are:
958    neighborhood size (3, 5, 7 etc.),
959    and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */
960 CVAPI(void)  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
961                                   int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
962                                   int threshold_type CV_DEFAULT(CV_THRESH_BINARY),
963                                   int block_size CV_DEFAULT(3),
964                                   double param1 CV_DEFAULT(5));
965
966 #define CV_FLOODFILL_FIXED_RANGE (1 << 16)
967 #define CV_FLOODFILL_MASK_ONLY   (1 << 17)
968
969 /* Fills the connected component until the color difference gets large enough */
970 CVAPI(void)  cvFloodFill( CvArr* image, CvPoint seed_point,
971                           CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)),
972                           CvScalar up_diff CV_DEFAULT(cvScalarAll(0)),
973                           CvConnectedComp* comp CV_DEFAULT(NULL),
974                           int flags CV_DEFAULT(4),
975                           CvArr* mask CV_DEFAULT(NULL));
976
977 /****************************************************************************************\
978 *                                  Feature detection                                     *
979 \****************************************************************************************/
980
981 #define CV_CANNY_L2_GRADIENT  (1 << 31)
982
983 /* Runs canny edge detector */
984 CVAPI(void)  cvCanny( const CvArr* image, CvArr* edges, double threshold1,
985                       double threshold2, int  aperture_size CV_DEFAULT(3) );
986
987 /* Calculates constraint image for corner detection
988    Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.
989    Applying threshold to the result gives coordinates of corners */
990 CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners,
991                               int aperture_size CV_DEFAULT(3) );
992
993 /* Calculates eigen values and vectors of 2x2
994    gradient covariation matrix at every image pixel */
995 CVAPI(void)  cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,
996                                       int block_size, int aperture_size CV_DEFAULT(3) );
997
998 /* Calculates minimal eigenvalue for 2x2 gradient covariation matrix at
999    every image pixel */
1000 CVAPI(void)  cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval,
1001                                  int block_size, int aperture_size CV_DEFAULT(3) );
1002
1003 /* Harris corner detector:
1004    Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */
1005 CVAPI(void)  cvCornerHarris( const CvArr* image, CvArr* harris_responce,
1006                              int block_size, int aperture_size CV_DEFAULT(3),
1007                              double k CV_DEFAULT(0.04) );
1008
1009 /* Adjust corner position using some sort of gradient search */
1010 CVAPI(void)  cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,
1011                                  int count, CvSize win, CvSize zero_zone,
1012                                  CvTermCriteria  criteria );
1013
1014 /* Finds a sparse set of points within the selected region
1015    that seem to be easy to track */
1016 CVAPI(void)  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
1017                                    CvArr* temp_image, CvPoint2D32f* corners,
1018                                    int* corner_count, double  quality_level,
1019                                    double  min_distance,
1020                                    const CvArr* mask CV_DEFAULT(NULL),
1021                                    int block_size CV_DEFAULT(3),
1022                                    int use_harris CV_DEFAULT(0),
1023                                    double k CV_DEFAULT(0.04) );
1024
1025 #define CV_HOUGH_STANDARD 0
1026 #define CV_HOUGH_PROBABILISTIC 1
1027 #define CV_HOUGH_MULTI_SCALE 2
1028 #define CV_HOUGH_GRADIENT 3
1029
1030 /* Finds lines on binary image using one of several methods.
1031    line_storage is either memory storage or 1 x <max number of lines> CvMat, its
1032    number of columns is changed by the function.
1033    method is one of CV_HOUGH_*;
1034    rho, theta and threshold are used for each of those methods;
1035    param1 ~ line length, param2 ~ line gap - for probabilistic,
1036    param1 ~ srn, param2 ~ stn - for multi-scale */
1037 CVAPI(CvSeq*)  cvHoughLines2( CvArr* image, void* line_storage, int method, 
1038                               double rho, double theta, int threshold,
1039                               double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
1040
1041 /* Finds circles in the image */
1042 CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,
1043                               int method, double dp, double min_dist,
1044                               double param1 CV_DEFAULT(100),
1045                               double param2 CV_DEFAULT(100),
1046                               int min_radius CV_DEFAULT(0),
1047                               int max_radius CV_DEFAULT(0));
1048
1049 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */
1050 CVAPI(void)  cvFitLine( const CvArr* points, int dist_type, double param,
1051                         double reps, double aeps, float* line );
1052
1053 /****************************************************************************************\
1054 *                         Haar-like Object Detection functions                           *
1055 \****************************************************************************************/
1056
1057 /* Loads haar classifier cascade from a directory.
1058    It is obsolete: convert your cascade to xml and use cvLoad instead */
1059 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
1060                     const char* directory, CvSize orig_window_size);
1061
1062 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
1063
1064 #define CV_HAAR_DO_CANNY_PRUNING    1
1065 #define CV_HAAR_SCALE_IMAGE         2
1066 #define CV_HAAR_FIND_BIGGEST_OBJECT 4 
1067 #define CV_HAAR_DO_ROUGH_SEARCH     8
1068
1069 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
1070                      CvHaarClassifierCascade* cascade,
1071                      CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
1072                      int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
1073                      CvSize min_size CV_DEFAULT(cvSize(0,0)));
1074
1075 /* sets images for haar classifier cascade */
1076 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1077                                                 const CvArr* sum, const CvArr* sqsum,
1078                                                 const CvArr* tilted_sum, double scale );
1079
1080 /* runs the cascade on the specified window */
1081 CVAPI(int) cvRunHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1082                                       CvPoint pt, int start_stage CV_DEFAULT(0));
1083
1084 /****************************************************************************************\
1085 *                     Camera Calibration and Rectification functions                     *
1086 \****************************************************************************************/
1087
1088 /* transforms the input image to compensate lens distortion */
1089 CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
1090                           const CvMat* intrinsic_matrix,
1091                           const CvMat* distortion_coeffs );
1092
1093 /* computes transformation map from intrinsic camera parameters
1094    that can used by cvRemap */
1095 CVAPI(void) cvInitUndistortMap( const CvMat* intrinsic_matrix,
1096                                 const CvMat* distortion_coeffs,
1097                                 CvArr* mapx, CvArr* mapy );
1098
1099 /* converts rotation vector to rotation matrix or vice versa */
1100 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
1101                          CvMat* jacobian CV_DEFAULT(0) );
1102
1103 /* finds perspective transformation between the object plane and image (view) plane */
1104 CVAPI(void) cvFindHomography( const CvMat* src_points,
1105                               const CvMat* dst_points,
1106                               CvMat* homography );
1107
1108 /* projects object points to the view plane using
1109    the specified extrinsic and intrinsic camera parameters */
1110 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
1111                               const CvMat* translation_vector, const CvMat* intrinsic_matrix,
1112                               const CvMat* distortion_coeffs, CvMat* image_points,
1113                               CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
1114                               CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
1115                               CvMat* dpddist CV_DEFAULT(NULL) );
1116
1117 /* finds extrinsic camera parameters from
1118    a few known corresponding point pairs and intrinsic parameters */
1119 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
1120                                           const CvMat* image_points,
1121                                           const CvMat* intrinsic_matrix,
1122                                           const CvMat* distortion_coeffs,
1123                                           CvMat* rotation_vector,
1124                                           CvMat* translation_vector );
1125
1126 #define CV_CALIB_USE_INTRINSIC_GUESS  1
1127 #define CV_CALIB_FIX_ASPECT_RATIO     2
1128 #define CV_CALIB_FIX_PRINCIPAL_POINT  4
1129 #define CV_CALIB_ZERO_TANGENT_DIST    8
1130
1131 /* finds intrinsic and extrinsic camera parameters
1132    from a few views of known calibration pattern */
1133 CVAPI(void) cvCalibrateCamera2( const CvMat* object_points,
1134                                 const CvMat* image_points,
1135                                 const CvMat* point_counts,
1136                                 CvSize image_size,
1137                                 CvMat* intrinsic_matrix,
1138                                 CvMat* distortion_coeffs,
1139                                 CvMat* rotation_vectors CV_DEFAULT(NULL),
1140                                 CvMat* translation_vectors CV_DEFAULT(NULL),
1141                                 int flags CV_DEFAULT(0) );
1142
1143 #define CV_CALIB_CB_ADAPTIVE_THRESH  1
1144 #define CV_CALIB_CB_NORMALIZE_IMAGE  2
1145 #define CV_CALIB_CB_FILTER_QUADS     4 
1146
1147 /* Detects corners on a chessboard calibration pattern */
1148 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
1149                                     CvPoint2D32f* corners,
1150                                     int* corner_count CV_DEFAULT(NULL),
1151                                     int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH) );
1152
1153 /* Draws individual chessboard corners or the whole chessboard detected */
1154 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
1155                                      CvPoint2D32f* corners,
1156                                      int count, int pattern_was_found );
1157
1158 typedef struct CvPOSITObject CvPOSITObject;
1159
1160 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
1161 CVAPI(CvPOSITObject*)  cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
1162
1163
1164 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
1165    an object given its model and projection in a weak-perspective case */
1166 CVAPI(void)  cvPOSIT(  CvPOSITObject* posit_object, CvPoint2D32f* image_points,
1167                        double focal_length, CvTermCriteria criteria,
1168                        CvMatr32f rotation_matrix, CvVect32f translation_vector);
1169
1170 /* Releases CvPOSITObject structure */
1171 CVAPI(void)  cvReleasePOSITObject( CvPOSITObject**  posit_object );
1172
1173
1174 /****************************************************************************************\
1175 *                                 Epipolar Geometry                                      *
1176 \****************************************************************************************/
1177
1178 /* updates the number of RANSAC iterations */
1179 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
1180                                    int model_points, int max_iters );
1181
1182 CVAPI(void) cvConvertPointsHomogenious( const CvMat* src, CvMat* dst );
1183
1184 /* Calculates fundamental matrix given a set of corresponding points */
1185 #define CV_FM_7POINT 1
1186 #define CV_FM_8POINT 2
1187 #define CV_FM_LMEDS_ONLY  4
1188 #define CV_FM_RANSAC_ONLY 8
1189 #define CV_FM_LMEDS (CV_FM_LMEDS_ONLY + CV_FM_8POINT)
1190 #define CV_FM_RANSAC (CV_FM_RANSAC_ONLY + CV_FM_8POINT)
1191 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
1192                                  CvMat* fundamental_matrix,
1193                                  int method CV_DEFAULT(CV_FM_RANSAC),
1194                                  double param1 CV_DEFAULT(1.), double param2 CV_DEFAULT(0.99),
1195                                  CvMat* status CV_DEFAULT(NULL) );
1196
1197 /* For each input point on one of images
1198    computes parameters of the corresponding
1199    epipolar line on the other image */
1200 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
1201                                          int which_image,
1202                                          const CvMat* fundamental_matrix,
1203                                          CvMat* correspondent_lines );
1204
1205 #ifdef __cplusplus
1206 }
1207 #endif
1208
1209 #ifdef __cplusplus
1210 #include "cv.hpp"
1211 #endif
1212
1213 /****************************************************************************************\
1214 *                                 Backward compatibility                                 *
1215 \****************************************************************************************/
1216
1217 #ifndef CV_NO_BACKWARD_COMPATIBILITY
1218 #include "cvcompat.h"
1219 #endif
1220
1221 #endif /*_CV_H_*/