]> rtime.felk.cvut.cz Git - opencv.git/blob - opencv/include/opencv/cv.h
8baf9f672a2bb3814419ee9fa3bd3aa40f49acb1
[opencv.git] / opencv / include / opencv / 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 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #ifndef __OPENCV_CV_H__
44 #define __OPENCV_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 /* Converts mapx & mapy from floating-point to integer formats for cvRemap */
303 CVAPI(void)  cvConvertMaps( const CvArr* mapx, const CvArr* mapy,
304                             CvArr* mapxy, CvArr* mapalpha );
305
306 /* Performs forward or inverse log-polar image transform */
307 CVAPI(void)  cvLogPolar( const CvArr* src, CvArr* dst,
308                          CvPoint2D32f center, double M,
309                          int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS));
310
311 /* Performs forward or inverse linear-polar image transform */
312 CVAPI(void)  cvLinearPolar( const CvArr* src, CvArr* dst,
313                          CvPoint2D32f center, double maxRadius,
314                          int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS));
315
316 #define  CV_SHAPE_RECT      0
317 #define  CV_SHAPE_CROSS     1
318 #define  CV_SHAPE_ELLIPSE   2
319 #define  CV_SHAPE_CUSTOM    100
320
321 /* creates structuring element used for morphological operations */
322 CVAPI(IplConvKernel*)  cvCreateStructuringElementEx(
323             int cols, int  rows, int  anchor_x, int  anchor_y,
324             int shape, int* values CV_DEFAULT(NULL) );
325
326 /* releases structuring element */
327 CVAPI(void)  cvReleaseStructuringElement( IplConvKernel** element );
328
329 /* erodes input image (applies minimum filter) one or more times.
330    If element pointer is NULL, 3x3 rectangular element is used */
331 CVAPI(void)  cvErode( const CvArr* src, CvArr* dst,
332                       IplConvKernel* element CV_DEFAULT(NULL),
333                       int iterations CV_DEFAULT(1) );
334
335 /* dilates input image (applies maximum filter) one or more times.
336    If element pointer is NULL, 3x3 rectangular element is used */
337 CVAPI(void)  cvDilate( const CvArr* src, CvArr* dst,
338                        IplConvKernel* element CV_DEFAULT(NULL),
339                        int iterations CV_DEFAULT(1) );
340
341 #define CV_MOP_ERODE        0
342 #define CV_MOP_DILATE       1
343 #define CV_MOP_OPEN         2
344 #define CV_MOP_CLOSE        3
345 #define CV_MOP_GRADIENT     4
346 #define CV_MOP_TOPHAT       5
347 #define CV_MOP_BLACKHAT     6
348
349 /* Performs complex morphological transformation */
350 CVAPI(void)  cvMorphologyEx( const CvArr* src, CvArr* dst,
351                              CvArr* temp, IplConvKernel* element,
352                              int operation, int iterations CV_DEFAULT(1) );
353
354 /* Calculates all spatial and central moments up to the 3rd order */
355 CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0));
356
357 /* Retrieve particular spatial, central or normalized central moments */
358 CVAPI(double)  cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
359 CVAPI(double)  cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
360 CVAPI(double)  cvGetNormalizedCentralMoment( CvMoments* moments,
361                                              int x_order, int y_order );
362
363 /* Calculates 7 Hu's invariants from precalculated spatial and central moments */
364 CVAPI(void) cvGetHuMoments( CvMoments*  moments, CvHuMoments*  hu_moments );
365
366 /*********************************** data sampling **************************************/
367
368 /* Fetches pixels that belong to the specified line segment and stores them to the buffer.
369    Returns the number of retrieved points. */
370 CVAPI(int)  cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer,
371                           int connectivity CV_DEFAULT(8));
372
373 /* Retrieves the rectangular image region with specified center from the input array.
374  dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2).
375  Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/
376 CVAPI(void)  cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
377
378
379 /* Retrieves quadrangle from the input array.
380     matrixarr = ( a11  a12 | b1 )   dst(x,y) <- src(A[x y]' + b)
381                 ( a21  a22 | b2 )   (bilinear interpolation is used to retrieve pixels
382                                      with fractional coordinates)
383 */
384 CVAPI(void)  cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst,
385                                     const CvMat* map_matrix );
386
387 /* Methods for comparing two array */
388 #define  CV_TM_SQDIFF        0
389 #define  CV_TM_SQDIFF_NORMED 1
390 #define  CV_TM_CCORR         2
391 #define  CV_TM_CCORR_NORMED  3
392 #define  CV_TM_CCOEFF        4
393 #define  CV_TM_CCOEFF_NORMED 5
394
395 /* Measures similarity between template and overlapped windows in the source image
396    and fills the resultant image with the measurements */
397 CVAPI(void)  cvMatchTemplate( const CvArr* image, const CvArr* templ,
398                               CvArr* result, int method );
399
400 /* Computes earth mover distance between
401    two weighted point sets (called signatures) */
402 CVAPI(float)  cvCalcEMD2( const CvArr* signature1,
403                           const CvArr* signature2,
404                           int distance_type,
405                           CvDistanceFunction distance_func CV_DEFAULT(NULL),
406                           const CvArr* cost_matrix CV_DEFAULT(NULL),
407                           CvArr* flow CV_DEFAULT(NULL),
408                           float* lower_bound CV_DEFAULT(NULL),
409                           void* userdata CV_DEFAULT(NULL));
410
411 /****************************************************************************************\
412 *                              Contours retrieving                                       *
413 \****************************************************************************************/
414
415 /* Retrieves outer and optionally inner boundaries of white (non-zero) connected
416    components in the black (zero) background */
417 CVAPI(int)  cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,
418                             int header_size CV_DEFAULT(sizeof(CvContour)),
419                             int mode CV_DEFAULT(CV_RETR_LIST),
420                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
421                             CvPoint offset CV_DEFAULT(cvPoint(0,0)));
422
423
424 /* Initalizes contour retrieving process.
425    Calls cvStartFindContours.
426    Calls cvFindNextContour until null pointer is returned
427    or some other condition becomes true.
428    Calls cvEndFindContours at the end. */
429 CVAPI(CvContourScanner)  cvStartFindContours( CvArr* image, CvMemStorage* storage,
430                             int header_size CV_DEFAULT(sizeof(CvContour)),
431                             int mode CV_DEFAULT(CV_RETR_LIST),
432                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
433                             CvPoint offset CV_DEFAULT(cvPoint(0,0)));
434
435 /* Retrieves next contour */
436 CVAPI(CvSeq*)  cvFindNextContour( CvContourScanner scanner );
437
438
439 /* Substitutes the last retrieved contour with the new one
440    (if the substitutor is null, the last retrieved contour is removed from the tree) */
441 CVAPI(void)   cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour );
442
443
444 /* Releases contour scanner and returns pointer to the first outer contour */
445 CVAPI(CvSeq*)  cvEndFindContours( CvContourScanner* scanner );
446
447 /* Approximates a single Freeman chain or a tree of chains to polygonal curves */
448 CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
449                             int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
450                             double parameter CV_DEFAULT(0),
451                             int  minimal_perimeter CV_DEFAULT(0),
452                             int  recursive CV_DEFAULT(0));
453
454
455 /* Initalizes Freeman chain reader.
456    The reader is used to iteratively get coordinates of all the chain points.
457    If the Freeman codes should be read as is, a simple sequence reader should be used */
458 CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
459
460 /* Retrieves the next chain point */
461 CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader );
462
463
464 /****************************************************************************************\
465 *                                  Motion Analysis                                       *
466 \****************************************************************************************/
467
468 /************************************ optical flow ***************************************/
469
470 /* Calculates optical flow for 2 images using classical Lucas & Kanade algorithm */
471 CVAPI(void)  cvCalcOpticalFlowLK( const CvArr* prev, const CvArr* curr,
472                                   CvSize win_size, CvArr* velx, CvArr* vely );
473
474 /* Calculates optical flow for 2 images using block matching algorithm */
475 CVAPI(void)  cvCalcOpticalFlowBM( const CvArr* prev, const CvArr* curr,
476                                   CvSize block_size, CvSize shift_size,
477                                   CvSize max_range, int use_previous,
478                                   CvArr* velx, CvArr* vely );
479
480 /* Calculates Optical flow for 2 images using Horn & Schunck algorithm */
481 CVAPI(void)  cvCalcOpticalFlowHS( const CvArr* prev, const CvArr* curr,
482                                   int use_previous, CvArr* velx, CvArr* vely,
483                                   double lambda, CvTermCriteria criteria );
484
485 #define  CV_LKFLOW_PYR_A_READY       1
486 #define  CV_LKFLOW_PYR_B_READY       2
487 #define  CV_LKFLOW_INITIAL_GUESSES   4
488 #define  CV_LKFLOW_GET_MIN_EIGENVALS 8
489
490 /* It is Lucas & Kanade method, modified to use pyramids.
491    Also it does several iterations to get optical flow for
492    every point at every pyramid level.
493    Calculates optical flow between two images for certain set of points (i.e.
494    it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
495 CVAPI(void)  cvCalcOpticalFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
496                                      CvArr*  prev_pyr, CvArr*  curr_pyr,
497                                      const CvPoint2D32f* prev_features,
498                                      CvPoint2D32f* curr_features,
499                                      int       count,
500                                      CvSize    win_size,
501                                      int       level,
502                                      char*     status,
503                                      float*    track_error,
504                                      CvTermCriteria criteria,
505                                      int       flags );
506
507
508 /* Modification of a previous sparse optical flow algorithm to calculate
509    affine flow */
510 CVAPI(void)  cvCalcAffineFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
511                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
512                                     const CvPoint2D32f* prev_features,
513                                     CvPoint2D32f* curr_features,
514                                     float* matrices, int  count,
515                                     CvSize win_size, int  level,
516                                     char* status, float* track_error,
517                                     CvTermCriteria criteria, int flags );
518
519 /* Estimate rigid transformation between 2 images or 2 point sets */
520 CVAPI(int)  cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
521                                       CvMat* M, int full_affine );
522
523 /* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */
524 CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next,
525                                         CvArr* flow, double pyr_scale, int levels,
526                                         int winsize, int iterations, int poly_n,
527                                         double poly_sigma, int flags );
528
529 /********************************* motion templates *************************************/
530
531 /****************************************************************************************\
532 *        All the motion template functions work only with single channel images.         *
533 *        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *
534 *        Motion history image must have depth IPL_DEPTH_32F,                             *
535 *        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *
536 *        Motion orientation image - IPL_DEPTH_32F                                        *
537 *        Segmentation mask - IPL_DEPTH_32F                                               *
538 *        All the angles are in degrees, all the times are in milliseconds                *
539 \****************************************************************************************/
540
541 /* Updates motion history image given motion silhouette */
542 CVAPI(void)    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
543                                       double timestamp, double duration );
544
545 /* Calculates gradient of the motion history image and fills
546    a mask indicating where the gradient is valid */
547 CVAPI(void)    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
548                                      double delta1, double delta2,
549                                      int aperture_size CV_DEFAULT(3));
550
551 /* Calculates average motion direction within a selected motion region
552    (region can be selected by setting ROIs and/or by composing a valid gradient mask
553    with the region mask) */
554 CVAPI(double)  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
555                                         const CvArr* mhi, double timestamp,
556                                         double duration );
557
558 /* Splits a motion history image into a few parts corresponding to separate independent motions
559    (e.g. left hand, right hand) */
560 CVAPI(CvSeq*)  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
561                                 CvMemStorage* storage,
562                                 double timestamp, double seg_thresh );
563
564 /*********************** Background statistics accumulation *****************************/
565
566 /* Adds image to accumulator */
567 CVAPI(void)  cvAcc( const CvArr* image, CvArr* sum,
568                     const CvArr* mask CV_DEFAULT(NULL) );
569
570 /* Adds squared image to accumulator */
571 CVAPI(void)  cvSquareAcc( const CvArr* image, CvArr* sqsum,
572                           const CvArr* mask CV_DEFAULT(NULL) );
573
574 /* Adds a product of two images to accumulator */
575 CVAPI(void)  cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc,
576                             const CvArr* mask CV_DEFAULT(NULL) );
577
578 /* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
579 CVAPI(void)  cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
580                            const CvArr* mask CV_DEFAULT(NULL) );
581
582
583 /****************************************************************************************\
584 *                                       Tracking                                         *
585 \****************************************************************************************/
586
587 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
588    from the object histogram back project (extension of meanshift) */
589 CVAPI(int)  cvCamShift( const CvArr* prob_image, CvRect  window,
590                        CvTermCriteria criteria, CvConnectedComp* comp,
591                        CvBox2D* box CV_DEFAULT(NULL) );
592
593 /* Implements MeanShift algorithm - determines object position
594    from the object histogram back project */
595 CVAPI(int)  cvMeanShift( const CvArr* prob_image, CvRect  window,
596                         CvTermCriteria criteria, CvConnectedComp* comp );
597
598 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
599 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
600                                 int control_params CV_DEFAULT(0));
601
602 /* Releases Kalman filter state */
603 CVAPI(void)  cvReleaseKalman( CvKalman** kalman);
604
605 /* Updates Kalman filter by time (predicts future state of the system) */
606 CVAPI(const CvMat*)  cvKalmanPredict( CvKalman* kalman,
607                                      const CvMat* control CV_DEFAULT(NULL));
608
609 /* Updates Kalman filter by measurement
610    (corrects state of the system and internal matrices) */
611 CVAPI(const CvMat*)  cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
612
613 /****************************************************************************************\
614 *                              Planar subdivisions                                       *
615 \****************************************************************************************/
616
617 /* Initializes Delaunay triangulation */
618 CVAPI(void)  cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
619
620 /* Creates new subdivision */
621 CVAPI(CvSubdiv2D*)  cvCreateSubdiv2D( int subdiv_type, int header_size,
622                                       int vtx_size, int quadedge_size,
623                                       CvMemStorage* storage );
624
625 /************************* high-level subdivision functions ***************************/
626
627 /* Simplified Delaunay diagram creation */
628 CV_INLINE  CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage )
629 {
630     CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv),
631                          sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage );
632
633     cvInitSubdivDelaunay2D( subdiv, rect );
634     return subdiv;
635 }
636
637
638 /* Inserts new point to the Delaunay triangulation */
639 CVAPI(CvSubdiv2DPoint*)  cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
640
641 /* Locates a point within the Delaunay triangulation (finds the edge
642    the point is left to or belongs to, or the triangulation point the given
643    point coinsides with */
644 CVAPI(CvSubdiv2DPointLocation)  cvSubdiv2DLocate(
645                                CvSubdiv2D* subdiv, CvPoint2D32f pt,
646                                CvSubdiv2DEdge* edge,
647                                CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) );
648
649 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */
650 CVAPI(void)  cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
651
652
653 /* Removes all Voronoi points from the tesselation */
654 CVAPI(void)  cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
655
656
657 /* Finds the nearest to the given point vertex in subdivision. */
658 CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
659
660
661 /************ Basic quad-edge navigation and operations ************/
662
663 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )
664 {
665     return  CV_SUBDIV2D_NEXT_EDGE(edge);
666 }
667
668
669 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )
670 {
671     return  (edge & ~3) + ((edge + rotate) & 3);
672 }
673
674 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )
675 {
676     return edge ^ 2;
677 }
678
679 CV_INLINE  CvSubdiv2DEdge  cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )
680 {
681     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
682     edge = e->next[(edge + (int)type) & 3];
683     return  (edge & ~3) + ((edge + ((int)type >> 4)) & 3);
684 }
685
686
687 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )
688 {
689     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
690     return (CvSubdiv2DPoint*)e->pt[edge & 3];
691 }
692
693
694 CV_INLINE  CvSubdiv2DPoint*  cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )
695 {
696     CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
697     return (CvSubdiv2DPoint*)e->pt[(edge + 2) & 3];
698 }
699
700
701 CV_INLINE  double  cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
702 {
703     return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
704 }
705
706
707 /****************************************************************************************\
708 *                            Contour Processing and Shape Analysis                       *
709 \****************************************************************************************/
710
711 #define CV_POLY_APPROX_DP 0
712
713 /* Approximates a single polygonal curve (contour) or
714    a tree of polygonal curves (contours) */
715 CVAPI(CvSeq*)  cvApproxPoly( const void* src_seq,
716                              int header_size, CvMemStorage* storage,
717                              int method, double parameter,
718                              int parameter2 CV_DEFAULT(0));
719
720 /* Calculates perimeter of a contour or length of a part of contour */
721 CVAPI(double)  cvArcLength( const void* curve,
722                             CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
723                             int is_closed CV_DEFAULT(-1));
724 #define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )
725
726 /* Calculates contour boundning rectangle (update=1) or
727    just retrieves pre-calculated rectangle (update=0) */
728 CVAPI(CvRect)  cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) );
729
730 /* Calculates area of a contour or contour segment */
731 CVAPI(double)  cvContourArea( const CvArr* contour,
732                               CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
733
734 /* Finds minimum area rotated rectangle bounding a set of points */
735 CVAPI(CvBox2D)  cvMinAreaRect2( const CvArr* points,
736                                 CvMemStorage* storage CV_DEFAULT(NULL));
737
738 /* Finds minimum enclosing circle for a set of points */
739 CVAPI(int)  cvMinEnclosingCircle( const CvArr* points,
740                                   CvPoint2D32f* center, float* radius );
741
742 #define CV_CONTOURS_MATCH_I1  1
743 #define CV_CONTOURS_MATCH_I2  2
744 #define CV_CONTOURS_MATCH_I3  3
745
746 /* Compares two contours by matching their moments */
747 CVAPI(double)  cvMatchShapes( const void* object1, const void* object2,
748                               int method, double parameter CV_DEFAULT(0));
749
750 /* Builds hierarhical representation of a contour */
751 CVAPI(CvContourTree*)  cvCreateContourTree( const CvSeq* contour,
752                                             CvMemStorage* storage,
753                                             double threshold );
754
755 /* Reconstruct (completelly or partially) contour a from contour tree */
756 CVAPI(CvSeq*)  cvContourFromContourTree( const CvContourTree* tree,
757                                          CvMemStorage* storage,
758                                          CvTermCriteria criteria );
759
760 /* Compares two contour trees */
761 #define  CV_CONTOUR_TREES_MATCH_I1  1
762
763 CVAPI(double)  cvMatchContourTrees( const CvContourTree* tree1,
764                                     const CvContourTree* tree2,
765                                     int method, double threshold );
766
767 #define CV_CLOCKWISE         1
768 #define CV_COUNTER_CLOCKWISE 2
769
770 /* Calculates exact convex hull of 2d point set */
771 CVAPI(CvSeq*) cvConvexHull2( const CvArr* input,
772                              void* hull_storage CV_DEFAULT(NULL),
773                              int orientation CV_DEFAULT(CV_CLOCKWISE),
774                              int return_points CV_DEFAULT(0));
775
776 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */
777 CVAPI(int)  cvCheckContourConvexity( const CvArr* contour );
778
779 /* Finds convexity defects for the contour */
780 CVAPI(CvSeq*)  cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
781                                    CvMemStorage* storage CV_DEFAULT(NULL));
782
783 /* Fits ellipse into a set of 2d points */
784 CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points );
785
786 /* Finds minimum rectangle containing two given rectangles */
787 CVAPI(CvRect)  cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
788
789 /* Finds coordinates of the box vertices */
790 CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
791
792 /* Initializes sequence header for a matrix (column or row vector) of points -
793    a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */
794 CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat,
795                                  CvContour* contour_header,
796                                  CvSeqBlock* block );
797
798 /* Checks whether the point is inside polygon, outside, on an edge (at a vertex).
799    Returns positive, negative or zero value, correspondingly.
800    Optionally, measures a signed distance between
801    the point and the nearest polygon edge (measure_dist=1) */
802 CVAPI(double) cvPointPolygonTest( const CvArr* contour,
803                                   CvPoint2D32f pt, int measure_dist );
804
805 /****************************************************************************************\
806 *                                  Histogram functions                                   *
807 \****************************************************************************************/
808
809 /* Creates new histogram */
810 CVAPI(CvHistogram*)  cvCreateHist( int dims, int* sizes, int type,
811                                    float** ranges CV_DEFAULT(NULL),
812                                    int uniform CV_DEFAULT(1));
813
814 /* Assignes histogram bin ranges */
815 CVAPI(void)  cvSetHistBinRanges( CvHistogram* hist, float** ranges,
816                                 int uniform CV_DEFAULT(1));
817
818 /* Creates histogram header for array */
819 CVAPI(CvHistogram*)  cvMakeHistHeaderForArray(
820                             int  dims, int* sizes, CvHistogram* hist,
821                             float* data, float** ranges CV_DEFAULT(NULL),
822                             int uniform CV_DEFAULT(1));
823
824 /* Releases histogram */
825 CVAPI(void)  cvReleaseHist( CvHistogram** hist );
826
827 /* Clears all the histogram bins */
828 CVAPI(void)  cvClearHist( CvHistogram* hist );
829
830 /* Finds indices and values of minimum and maximum histogram bins */
831 CVAPI(void)  cvGetMinMaxHistValue( const CvHistogram* hist,
832                                    float* min_value, float* max_value,
833                                    int* min_idx CV_DEFAULT(NULL),
834                                    int* max_idx CV_DEFAULT(NULL));
835
836
837 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.
838    After that sum of histogram bins is equal to <factor> */
839 CVAPI(void)  cvNormalizeHist( CvHistogram* hist, double factor );
840
841
842 /* Clear all histogram bins that are below the threshold */
843 CVAPI(void)  cvThreshHist( CvHistogram* hist, double threshold );
844
845 #define CV_COMP_CORREL        0
846 #define CV_COMP_CHISQR        1
847 #define CV_COMP_INTERSECT     2
848 #define CV_COMP_BHATTACHARYYA 3
849
850 /* Compares two histogram */
851 CVAPI(double)  cvCompareHist( const CvHistogram* hist1,
852                               const CvHistogram* hist2,
853                               int method);
854
855 /* Copies one histogram to another. Destination histogram is created if
856    the destination pointer is NULL */
857 CVAPI(void)  cvCopyHist( const CvHistogram* src, CvHistogram** dst );
858
859
860 /* Calculates bayesian probabilistic histograms
861    (each or src and dst is an array of <number> histograms */
862 CVAPI(void)  cvCalcBayesianProb( CvHistogram** src, int number,
863                                 CvHistogram** dst);
864
865 /* Calculates array histogram */
866 CVAPI(void)  cvCalcArrHist( CvArr** arr, CvHistogram* hist,
867                             int accumulate CV_DEFAULT(0),
868                             const CvArr* mask CV_DEFAULT(NULL) );
869
870 CV_INLINE  void  cvCalcHist( IplImage** image, CvHistogram* hist,
871                              int accumulate CV_DEFAULT(0),
872                              const CvArr* mask CV_DEFAULT(NULL) )
873 {
874     cvCalcArrHist( (CvArr**)image, hist, accumulate, mask );
875 }
876
877 /* Calculates back project */
878 CVAPI(void)  cvCalcArrBackProject( CvArr** image, CvArr* dst,
879                                    const CvHistogram* hist );
880 #define  cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist)
881
882
883 /* Does some sort of template matching but compares histograms of
884    template and each window location */
885 CVAPI(void)  cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range,
886                                         CvHistogram* hist, int method,
887                                         double factor );
888 #define  cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \
889      cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor )
890
891
892 /* calculates probabilistic density (divides one histogram by another) */
893 CVAPI(void)  cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2,
894                                 CvHistogram* dst_hist, double scale CV_DEFAULT(255) );
895
896 /* equalizes histogram of 8-bit single-channel image */
897 CVAPI(void)  cvEqualizeHist( const CvArr* src, CvArr* dst );
898
899
900 #define  CV_VALUE  1
901 #define  CV_ARRAY  2
902 /* Updates active contour in order to minimize its cummulative
903    (internal and external) energy. */
904 CVAPI(void)  cvSnakeImage( const IplImage* image, CvPoint* points,
905                            int  length, float* alpha,
906                            float* beta, float* gamma,
907                            int coeff_usage, CvSize  win,
908                            CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
909
910 #define CV_DIST_MASK_3   3
911 #define CV_DIST_MASK_5   5
912 #define CV_DIST_MASK_PRECISE 0
913
914 /* Applies distance transform to binary image */
915 CVAPI(void)  cvDistTransform( const CvArr* src, CvArr* dst,
916                               int distance_type CV_DEFAULT(CV_DIST_L2),
917                               int mask_size CV_DEFAULT(3),
918                               const float* mask CV_DEFAULT(NULL),
919                               CvArr* labels CV_DEFAULT(NULL));
920
921
922 /* Types of thresholding */
923 #define CV_THRESH_BINARY      0  /* value = value > threshold ? max_value : 0       */
924 #define CV_THRESH_BINARY_INV  1  /* value = value > threshold ? 0 : max_value       */
925 #define CV_THRESH_TRUNC       2  /* value = value > threshold ? threshold : value   */
926 #define CV_THRESH_TOZERO      3  /* value = value > threshold ? value : 0           */
927 #define CV_THRESH_TOZERO_INV  4  /* value = value > threshold ? 0 : value           */
928 #define CV_THRESH_MASK        7
929
930 #define CV_THRESH_OTSU        8  /* use Otsu algorithm to choose the optimal threshold value;
931                                     combine the flag with one of the above CV_THRESH_* values */
932
933 /* Applies fixed-level threshold to grayscale image.
934    This is a basic operation applied before retrieving contours */
935 CVAPI(double)  cvThreshold( const CvArr*  src, CvArr*  dst,
936                             double  threshold, double  max_value,
937                             int threshold_type );
938
939 #define CV_ADAPTIVE_THRESH_MEAN_C  0
940 #define CV_ADAPTIVE_THRESH_GAUSSIAN_C  1
941
942 /* Applies adaptive threshold to grayscale image.
943    The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and
944    CV_ADAPTIVE_THRESH_GAUSSIAN_C are:
945    neighborhood size (3, 5, 7 etc.),
946    and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */
947 CVAPI(void)  cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
948                                   int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
949                                   int threshold_type CV_DEFAULT(CV_THRESH_BINARY),
950                                   int block_size CV_DEFAULT(3),
951                                   double param1 CV_DEFAULT(5));
952
953 #define CV_FLOODFILL_FIXED_RANGE (1 << 16)
954 #define CV_FLOODFILL_MASK_ONLY   (1 << 17)
955
956 /* Fills the connected component until the color difference gets large enough */
957 CVAPI(void)  cvFloodFill( CvArr* image, CvPoint seed_point,
958                           CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)),
959                           CvScalar up_diff CV_DEFAULT(cvScalarAll(0)),
960                           CvConnectedComp* comp CV_DEFAULT(NULL),
961                           int flags CV_DEFAULT(4),
962                           CvArr* mask CV_DEFAULT(NULL));
963
964 /****************************************************************************************\
965 *                                  Feature detection                                     *
966 \****************************************************************************************/
967
968 #define CV_CANNY_L2_GRADIENT  (1 << 31)
969
970 /* Runs canny edge detector */
971 CVAPI(void)  cvCanny( const CvArr* image, CvArr* edges, double threshold1,
972                       double threshold2, int  aperture_size CV_DEFAULT(3) );
973
974 /* Calculates constraint image for corner detection
975    Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.
976    Applying threshold to the result gives coordinates of corners */
977 CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners,
978                               int aperture_size CV_DEFAULT(3) );
979
980 /* Calculates eigen values and vectors of 2x2
981    gradient covariation matrix at every image pixel */
982 CVAPI(void)  cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,
983                                       int block_size, int aperture_size CV_DEFAULT(3) );
984
985 /* Calculates minimal eigenvalue for 2x2 gradient covariation matrix at
986    every image pixel */
987 CVAPI(void)  cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval,
988                                  int block_size, int aperture_size CV_DEFAULT(3) );
989
990 /* Harris corner detector:
991    Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */
992 CVAPI(void)  cvCornerHarris( const CvArr* image, CvArr* harris_responce,
993                              int block_size, int aperture_size CV_DEFAULT(3),
994                              double k CV_DEFAULT(0.04) );
995
996 /* Adjust corner position using some sort of gradient search */
997 CVAPI(void)  cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,
998                                  int count, CvSize win, CvSize zero_zone,
999                                  CvTermCriteria  criteria );
1000
1001 /* Finds a sparse set of points within the selected region
1002    that seem to be easy to track */
1003 CVAPI(void)  cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
1004                                    CvArr* temp_image, CvPoint2D32f* corners,
1005                                    int* corner_count, double  quality_level,
1006                                    double  min_distance,
1007                                    const CvArr* mask CV_DEFAULT(NULL),
1008                                    int block_size CV_DEFAULT(3),
1009                                    int use_harris CV_DEFAULT(0),
1010                                    double k CV_DEFAULT(0.04) );
1011
1012 #define CV_HOUGH_STANDARD 0
1013 #define CV_HOUGH_PROBABILISTIC 1
1014 #define CV_HOUGH_MULTI_SCALE 2
1015 #define CV_HOUGH_GRADIENT 3
1016
1017 /* Finds lines on binary image using one of several methods.
1018    line_storage is either memory storage or 1 x <max number of lines> CvMat, its
1019    number of columns is changed by the function.
1020    method is one of CV_HOUGH_*;
1021    rho, theta and threshold are used for each of those methods;
1022    param1 ~ line length, param2 ~ line gap - for probabilistic,
1023    param1 ~ srn, param2 ~ stn - for multi-scale */
1024 CVAPI(CvSeq*)  cvHoughLines2( CvArr* image, void* line_storage, int method,
1025                               double rho, double theta, int threshold,
1026                               double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
1027
1028 /* Finds circles in the image */
1029 CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,
1030                               int method, double dp, double min_dist,
1031                               double param1 CV_DEFAULT(100),
1032                               double param2 CV_DEFAULT(100),
1033                               int min_radius CV_DEFAULT(0),
1034                               int max_radius CV_DEFAULT(0));
1035
1036 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */
1037 CVAPI(void)  cvFitLine( const CvArr* points, int dist_type, double param,
1038                         double reps, double aeps, float* line );
1039
1040
1041
1042 struct CvFeatureTree;
1043
1044 /* Constructs kd-tree from set of feature descriptors */
1045 CVAPI(struct CvFeatureTree*) cvCreateKDTree(CvMat* desc);
1046
1047 /* Constructs spill-tree from set of feature descriptors */
1048 CVAPI(struct CvFeatureTree*) cvCreateSpillTree( const CvMat* raw_data,
1049                                     const int naive CV_DEFAULT(50),
1050                                     const double rho CV_DEFAULT(.7),
1051                                     const double tau CV_DEFAULT(.1) );
1052
1053 /* Release feature tree */
1054 CVAPI(void) cvReleaseFeatureTree(struct CvFeatureTree* tr);
1055
1056 /* Searches feature tree for k nearest neighbors of given reference points,
1057    searching (in case of kd-tree/bbf) at most emax leaves. */
1058 CVAPI(void) cvFindFeatures(struct CvFeatureTree* tr, const CvMat* query_points,
1059                            CvMat* indices, CvMat* dist, int k, int emax CV_DEFAULT(20));
1060
1061 /* Search feature tree for all points that are inlier to given rect region.
1062    Only implemented for kd trees */
1063 CVAPI(int) cvFindFeaturesBoxed(struct CvFeatureTree* tr,
1064                                CvMat* bounds_min, CvMat* bounds_max,
1065                                CvMat* out_indices);
1066
1067
1068 struct CvLSH;
1069 struct CvLSHOperations;
1070
1071 /* Construct a Locality Sensitive Hash (LSH) table, for indexing d-dimensional vectors of
1072    given type. Vectors will be hashed L times with k-dimensional p-stable (p=2) functions. */
1073 CVAPI(struct CvLSH*) cvCreateLSH(struct CvLSHOperations* ops, int d,
1074                                  int L CV_DEFAULT(10), int k CV_DEFAULT(10),
1075                                  int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4),
1076                                  int64 seed CV_DEFAULT(-1));
1077
1078 /* Construct in-memory LSH table, with n bins. */
1079 CVAPI(struct CvLSH*) cvCreateMemoryLSH(int d, int n, int L CV_DEFAULT(10), int k CV_DEFAULT(10),
1080                                        int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4),
1081                                        int64 seed CV_DEFAULT(-1));
1082
1083 /* Free the given LSH structure. */
1084 CVAPI(void) cvReleaseLSH(struct CvLSH** lsh);
1085
1086 /* Return the number of vectors in the LSH. */
1087 CVAPI(unsigned int) LSHSize(struct CvLSH* lsh);
1088
1089 /* Add vectors to the LSH structure, optionally returning indices. */
1090 CVAPI(void) cvLSHAdd(struct CvLSH* lsh, const CvMat* data, CvMat* indices CV_DEFAULT(0));
1091
1092 /* Remove vectors from LSH, as addressed by given indices. */
1093 CVAPI(void) cvLSHRemove(struct CvLSH* lsh, const CvMat* indices);
1094
1095 /* Query the LSH n times for at most k nearest points; data is n x d,
1096    indices and dist are n x k. At most emax stored points will be accessed. */
1097 CVAPI(void) cvLSHQuery(struct CvLSH* lsh, const CvMat* query_points,
1098                        CvMat* indices, CvMat* dist, int k, int emax);
1099
1100
1101 typedef struct CvSURFPoint
1102 {
1103     CvPoint2D32f pt;
1104     int laplacian;
1105     int size;
1106     float dir;
1107     float hessian;
1108 } CvSURFPoint;
1109
1110 CV_INLINE CvSURFPoint cvSURFPoint( CvPoint2D32f pt, int laplacian,
1111                                    int size, float dir CV_DEFAULT(0),
1112                                    float hessian CV_DEFAULT(0))
1113 {
1114     CvSURFPoint kp;
1115     kp.pt = pt;
1116     kp.laplacian = laplacian;
1117     kp.size = size;
1118     kp.dir = dir;
1119     kp.hessian = hessian;
1120     return kp;
1121 }
1122
1123 typedef struct CvSURFParams
1124 {
1125     int extended;
1126     double hessianThreshold;
1127
1128     int nOctaves;
1129     int nOctaveLayers;
1130 }
1131 CvSURFParams;
1132
1133 CVAPI(CvSURFParams) cvSURFParams( double hessianThreshold, int extended CV_DEFAULT(0) );
1134
1135 // If useProvidedKeyPts!=0, keypoints are not detected, but descriptors are computed
1136 //  at the locations provided in keypoints (a CvSeq of CvSURFPoint).
1137 CVAPI(void) cvExtractSURF( const CvArr* img, const CvArr* mask,
1138                            CvSeq** keypoints, CvSeq** descriptors,
1139                            CvMemStorage* storage, CvSURFParams params, int useProvidedKeyPts CV_DEFAULT(0)  );
1140
1141 typedef struct CvMSERParams
1142 {
1143     // delta, in the code, it compares (size_{i}-size_{i-delta})/size_{i-delta}
1144     int delta;
1145     // prune the area which bigger/smaller than max_area/min_area
1146     int maxArea;
1147     int minArea;
1148     // prune the area have simliar size to its children
1149     float maxVariation;
1150     // trace back to cut off mser with diversity < min_diversity
1151     float minDiversity;
1152     /* the next few params for MSER of color image */
1153     // for color image, the evolution steps
1154     int maxEvolution;
1155     // the area threshold to cause re-initialize
1156     double areaThreshold;
1157     // ignore too small margin
1158     double minMargin;
1159     // the aperture size for edge blur
1160     int edgeBlurSize;
1161 }
1162 CvMSERParams;
1163
1164 CVAPI(CvMSERParams) cvMSERParams( int delta CV_DEFAULT(5), int min_area CV_DEFAULT(60),
1165                            int max_area CV_DEFAULT(14400), float max_variation CV_DEFAULT(.25f),
1166                            float min_diversity CV_DEFAULT(.2f), int max_evolution CV_DEFAULT(200),
1167                            double area_threshold CV_DEFAULT(1.01),
1168                            double min_margin CV_DEFAULT(.003),
1169                            int edge_blur_size CV_DEFAULT(5) );
1170
1171 // Extracts the contours of Maximally Stable Extremal Regions
1172 CVAPI(void) cvExtractMSER( CvArr* _img, CvArr* _mask, CvSeq** contours, CvMemStorage* storage, CvMSERParams params );
1173
1174
1175 typedef struct CvStarKeypoint
1176 {
1177     CvPoint pt;
1178     int size;
1179     float response;
1180 }
1181 CvStarKeypoint;
1182
1183 CV_INLINE CvStarKeypoint cvStarKeypoint(CvPoint pt, int size, float response)
1184 {
1185     CvStarKeypoint kpt;
1186     kpt.pt = pt;
1187     kpt.size = size;
1188     kpt.response = response;
1189     return kpt;
1190 }
1191
1192 typedef struct CvStarDetectorParams
1193 {
1194     int maxSize;
1195     int responseThreshold;
1196     int lineThresholdProjected;
1197     int lineThresholdBinarized;
1198     int suppressNonmaxSize;
1199 }
1200 CvStarDetectorParams;
1201
1202 CV_INLINE CvStarDetectorParams cvStarDetectorParams(
1203     int maxSize CV_DEFAULT(45),
1204     int responseThreshold CV_DEFAULT(30),
1205     int lineThresholdProjected CV_DEFAULT(10),
1206     int lineThresholdBinarized CV_DEFAULT(8),
1207     int suppressNonmaxSize CV_DEFAULT(5))
1208 {
1209     CvStarDetectorParams params;
1210     params.maxSize = maxSize;
1211     params.responseThreshold = responseThreshold;
1212     params.lineThresholdProjected = lineThresholdProjected;
1213     params.lineThresholdBinarized = lineThresholdBinarized;
1214     params.suppressNonmaxSize = suppressNonmaxSize;
1215
1216     return params;
1217 }
1218
1219 CVAPI(CvSeq*) cvGetStarKeypoints( const CvArr* img, CvMemStorage* storage,
1220         CvStarDetectorParams params CV_DEFAULT(cvStarDetectorParams()));
1221
1222 /****************************************************************************************\
1223 *                         Haar-like Object Detection functions                           *
1224 \****************************************************************************************/
1225
1226 /* Loads haar classifier cascade from a directory.
1227    It is obsolete: convert your cascade to xml and use cvLoad instead */
1228 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
1229                     const char* directory, CvSize orig_window_size);
1230
1231 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
1232
1233 #define CV_HAAR_DO_CANNY_PRUNING    1
1234 #define CV_HAAR_SCALE_IMAGE         2
1235 #define CV_HAAR_FIND_BIGGEST_OBJECT 4
1236 #define CV_HAAR_DO_ROUGH_SEARCH     8
1237
1238 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
1239                      CvHaarClassifierCascade* cascade,
1240                      CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
1241                      int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
1242                      CvSize min_size CV_DEFAULT(cvSize(0,0)));
1243
1244 /* sets images for haar classifier cascade */
1245 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1246                                                 const CvArr* sum, const CvArr* sqsum,
1247                                                 const CvArr* tilted_sum, double scale );
1248
1249 /* runs the cascade on the specified window */
1250 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
1251                                        CvPoint pt, int start_stage CV_DEFAULT(0));
1252
1253 /****************************************************************************************\
1254 *                      Camera Calibration, Pose Estimation and Stereo                    *
1255 \****************************************************************************************/
1256
1257 /* Transforms the input image to compensate lens distortion */
1258 CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
1259                           const CvMat* camera_matrix,
1260                           const CvMat* distortion_coeffs,
1261                           const CvMat* new_camera_matrix CV_DEFAULT(0) );
1262
1263 /* Computes transformation map from intrinsic camera parameters
1264    that can used by cvRemap */
1265 CVAPI(void) cvInitUndistortMap( const CvMat* camera_matrix,
1266                                 const CvMat* distortion_coeffs,
1267                                 CvArr* mapx, CvArr* mapy );
1268
1269 /* Computes undistortion+rectification map for a head of stereo camera */
1270 CVAPI(void) cvInitUndistortRectifyMap( const CvMat* camera_matrix,
1271                                        const CvMat* dist_coeffs,
1272                                        const CvMat *R, const CvMat* new_camera_matrix,
1273                                        CvArr* mapx, CvArr* mapy );
1274
1275 /* Computes the original (undistorted) feature coordinates
1276    from the observed (distorted) coordinates */
1277 CVAPI(void) cvUndistortPoints( const CvMat* src, CvMat* dst,
1278                                const CvMat* camera_matrix,
1279                                const CvMat* dist_coeffs,
1280                                const CvMat* R CV_DEFAULT(0),
1281                                const CvMat* P CV_DEFAULT(0));
1282     
1283 /* Computes the optimal new camera matrix according to the free scaling parameter alpha:
1284    alpha=0 - only valid pixels will be retained in the undistorted image
1285    alpha=1 - all the source image pixels will be retained in the undistorted image
1286 */
1287 CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
1288                                          const CvMat* dist_coeffs,
1289                                          CvSize image_size, double alpha,
1290                                          CvMat* new_camera_matrix,
1291                                          CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
1292                                          CvRect* valid_pixel_ROI CV_DEFAULT(0) );
1293
1294 /* Converts rotation vector to rotation matrix or vice versa */
1295 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
1296                          CvMat* jacobian CV_DEFAULT(0) );
1297
1298 #define CV_LMEDS 4
1299 #define CV_RANSAC 8
1300
1301 /* Finds perspective transformation between the object plane and image (view) plane */
1302 CVAPI(int) cvFindHomography( const CvMat* src_points,
1303                              const CvMat* dst_points,
1304                              CvMat* homography,
1305                              int method CV_DEFAULT(0),
1306                              double ransacReprojThreshold CV_DEFAULT(0),
1307                              CvMat* mask CV_DEFAULT(0));
1308
1309 /* Computes RQ decomposition for 3x3 matrices */
1310 CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
1311                            CvMat *matrixQx CV_DEFAULT(NULL),
1312                            CvMat *matrixQy CV_DEFAULT(NULL),
1313                            CvMat *matrixQz CV_DEFAULT(NULL),
1314                            CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1315
1316 /* Computes projection matrix decomposition */
1317 CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
1318                                          CvMat *rotMatr, CvMat *posVect,
1319                                          CvMat *rotMatrX CV_DEFAULT(NULL),
1320                                          CvMat *rotMatrY CV_DEFAULT(NULL),
1321                                          CvMat *rotMatrZ CV_DEFAULT(NULL),
1322                                          CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1323
1324 /* Computes d(AB)/dA and d(AB)/dB */
1325 CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
1326
1327 /* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
1328    t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
1329 CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
1330                          const CvMat* _rvec2, const CvMat* _tvec2,
1331                          CvMat* _rvec3, CvMat* _tvec3,
1332                          CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
1333                          CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
1334                          CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
1335                          CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
1336
1337 /* Projects object points to the view plane using
1338    the specified extrinsic and intrinsic camera parameters */
1339 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
1340                               const CvMat* translation_vector, const CvMat* camera_matrix,
1341                               const CvMat* distortion_coeffs, CvMat* image_points,
1342                               CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
1343                               CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
1344                               CvMat* dpddist CV_DEFAULT(NULL),
1345                               double aspect_ratio CV_DEFAULT(0));
1346
1347 /* Finds extrinsic camera parameters from
1348    a few known corresponding point pairs and intrinsic parameters */
1349 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
1350                                           const CvMat* image_points,
1351                                           const CvMat* camera_matrix,
1352                                           const CvMat* distortion_coeffs,
1353                                           CvMat* rotation_vector,
1354                                           CvMat* translation_vector,
1355                                           int use_extrinsic_guess CV_DEFAULT(0) );
1356
1357 /* Computes initial estimate of the intrinsic camera parameters
1358    in case of planar calibration target (e.g. chessboard) */
1359 CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
1360                                      const CvMat* image_points,
1361                                      const CvMat* npoints, CvSize image_size,
1362                                      CvMat* camera_matrix,
1363                                      double aspect_ratio CV_DEFAULT(1.) );
1364
1365 #define CV_CALIB_CB_ADAPTIVE_THRESH  1
1366 #define CV_CALIB_CB_NORMALIZE_IMAGE  2
1367 #define CV_CALIB_CB_FILTER_QUADS     4
1368 #define CV_CALIB_CB_FAST_CHECK       8
1369
1370 // Performs a fast check if a chessboard is in the input image. This is a workaround to 
1371 // a problem of cvFindChessboardCorners being slow on images with no chessboard
1372 // - src: input image
1373 // - size: chessboard size
1374 // Returns 1 if a chessboard can be in this image and findChessboardCorners should be called, 
1375 // 0 if there is no chessboard, -1 in case of error
1376 CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
1377     
1378     /* Detects corners on a chessboard calibration pattern */
1379 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
1380                                     CvPoint2D32f* corners,
1381                                     int* corner_count CV_DEFAULT(NULL),
1382                                     int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+
1383                                         CV_CALIB_CB_NORMALIZE_IMAGE) );
1384
1385 /* Draws individual chessboard corners or the whole chessboard detected */
1386 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
1387                                      CvPoint2D32f* corners,
1388                                      int count, int pattern_was_found );
1389
1390 #define CV_CALIB_USE_INTRINSIC_GUESS  1
1391 #define CV_CALIB_FIX_ASPECT_RATIO     2
1392 #define CV_CALIB_FIX_PRINCIPAL_POINT  4
1393 #define CV_CALIB_ZERO_TANGENT_DIST    8
1394 #define CV_CALIB_FIX_FOCAL_LENGTH 16
1395 #define CV_CALIB_FIX_K1  32
1396 #define CV_CALIB_FIX_K2  64
1397 #define CV_CALIB_FIX_K3  128
1398
1399 /* Finds intrinsic and extrinsic camera parameters
1400    from a few views of known calibration pattern */
1401 CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
1402                                 const CvMat* image_points,
1403                                 const CvMat* point_counts,
1404                                 CvSize image_size,
1405                                 CvMat* camera_matrix,
1406                                 CvMat* distortion_coeffs,
1407                                 CvMat* rotation_vectors CV_DEFAULT(NULL),
1408                                 CvMat* translation_vectors CV_DEFAULT(NULL),
1409                                 int flags CV_DEFAULT(0) );
1410
1411 /* Computes various useful characteristics of the camera from the data computed by
1412    cvCalibrateCamera2 */
1413 CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
1414                                 CvSize image_size,
1415                                 double aperture_width CV_DEFAULT(0),
1416                                 double aperture_height CV_DEFAULT(0),
1417                                 double *fovx CV_DEFAULT(NULL),
1418                                 double *fovy CV_DEFAULT(NULL),
1419                                 double *focal_length CV_DEFAULT(NULL),
1420                                 CvPoint2D64f *principal_point CV_DEFAULT(NULL),
1421                                 double *pixel_aspect_ratio CV_DEFAULT(NULL));
1422
1423 #define CV_CALIB_FIX_INTRINSIC  256
1424 #define CV_CALIB_SAME_FOCAL_LENGTH 512
1425
1426 /* Computes the transformation from one camera coordinate system to another one
1427    from a few correspondent views of the same calibration target. Optionally, calibrates
1428    both cameras */
1429 CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
1430                                const CvMat* image_points2, const CvMat* npoints,
1431                                CvMat* camera_matrix1, CvMat* dist_coeffs1,
1432                                CvMat* camera_matrix2, CvMat* dist_coeffs2,
1433                                CvSize image_size, CvMat* R, CvMat* T,
1434                                CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
1435                                CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
1436                                    CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
1437                                int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
1438
1439 #define CV_CALIB_ZERO_DISPARITY 1024
1440
1441 /* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
1442    views parallel (=> to make all the epipolar lines horizontal or vertical) */
1443 CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
1444                              const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
1445                              CvSize image_size, const CvMat* R, const CvMat* T,
1446                              CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
1447                              CvMat* Q CV_DEFAULT(0),
1448                              int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
1449                              double alpha CV_DEFAULT(-1),
1450                              CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
1451                              CvRect* valid_pix_ROI1 CV_DEFAULT(0),
1452                              CvRect* valid_pix_ROI2 CV_DEFAULT(0));
1453
1454 /* Computes rectification transformations for uncalibrated pair of images using a set
1455    of point correspondences */
1456 CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
1457                                         const CvMat* F, CvSize img_size,
1458                                         CvMat* H1, CvMat* H2,
1459                                         double threshold CV_DEFAULT(5));
1460
1461 typedef struct CvPOSITObject CvPOSITObject;
1462
1463 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
1464 CVAPI(CvPOSITObject*)  cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
1465
1466
1467 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
1468    an object given its model and projection in a weak-perspective case */
1469 CVAPI(void)  cvPOSIT(  CvPOSITObject* posit_object, CvPoint2D32f* image_points,
1470                        double focal_length, CvTermCriteria criteria,
1471                        CvMatr32f rotation_matrix, CvVect32f translation_vector);
1472
1473 /* Releases CvPOSITObject structure */
1474 CVAPI(void)  cvReleasePOSITObject( CvPOSITObject**  posit_object );
1475
1476 /* updates the number of RANSAC iterations */
1477 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
1478                                    int model_points, int max_iters );
1479
1480 CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
1481
1482 /* Calculates fundamental matrix given a set of corresponding points */
1483 #define CV_FM_7POINT 1
1484 #define CV_FM_8POINT 2
1485 #define CV_FM_LMEDS_ONLY  CV_LMEDS
1486 #define CV_FM_RANSAC_ONLY CV_RANSAC
1487 #define CV_FM_LMEDS CV_LMEDS
1488 #define CV_FM_RANSAC CV_RANSAC
1489 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
1490                                  CvMat* fundamental_matrix,
1491                                  int method CV_DEFAULT(CV_FM_RANSAC),
1492                                  double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
1493                                  CvMat* status CV_DEFAULT(NULL) );
1494
1495 /* For each input point on one of images
1496    computes parameters of the corresponding
1497    epipolar line on the other image */
1498 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
1499                                          int which_image,
1500                                          const CvMat* fundamental_matrix,
1501                                          CvMat* correspondent_lines );
1502
1503 /* Triangulation functions */
1504
1505 CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
1506                                 CvMat* projPoints1, CvMat* projPoints2,
1507                                 CvMat* points4D);
1508
1509 CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
1510                              CvMat* new_points1, CvMat* new_points2);
1511
1512 /* stereo correspondence parameters and functions */
1513
1514 #define CV_STEREO_BM_NORMALIZED_RESPONSE  0
1515 #define CV_STEREO_BM_XSOBEL               1
1516
1517 /* Block matching algorithm structure */
1518 typedef struct CvStereoBMState
1519 {
1520     // pre-filtering (normalization of input images)
1521     int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
1522     int preFilterSize; // averaging window size: ~5x5..21x21
1523     int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
1524
1525     // correspondence using Sum of Absolute Difference (SAD)
1526     int SADWindowSize; // ~5x5..21x21
1527     int minDisparity;  // minimum disparity (can be negative)
1528     int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
1529
1530     // post-filtering
1531     int textureThreshold;  // the disparity is only computed for pixels
1532                            // with textured enough neighborhood
1533     int uniquenessRatio;   // accept the computed disparity d* only if
1534                            // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
1535                            // for any d != d*+/-1 within the search range.
1536     int speckleWindowSize; // disparity variation window
1537     int speckleRange; // acceptable range of variation in window
1538
1539     int trySmallerWindows; // if 1, the results may be more accurate,
1540                            // at the expense of slower processing 
1541     CvRect roi1, roi2;
1542     int disp12MaxDiff;
1543
1544     // temporary buffers
1545     CvMat* preFilteredImg0;
1546     CvMat* preFilteredImg1;
1547     CvMat* slidingSumBuf;
1548     CvMat* cost;
1549     CvMat* disp;
1550 }
1551 CvStereoBMState;
1552
1553 #define CV_STEREO_BM_BASIC 0
1554 #define CV_STEREO_BM_FISH_EYE 1
1555 #define CV_STEREO_BM_NARROW 2
1556
1557 CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
1558                                               int numberOfDisparities CV_DEFAULT(0));
1559
1560 CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
1561
1562 CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
1563                                           CvArr* disparity, CvStereoBMState* state );
1564     
1565 CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
1566                                       int numberOfDisparities, int SADWindowSize );
1567     
1568 CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
1569                                  int minDisparity, int numberOfDisparities,
1570                                  int disp12MaxDiff CV_DEFAULT(1) );  
1571
1572 /* Kolmogorov-Zabin stereo-correspondence algorithm (a.k.a. KZ1) */
1573 #define CV_STEREO_GC_OCCLUDED  SHRT_MAX
1574
1575 typedef struct CvStereoGCState
1576 {
1577     int Ithreshold;
1578     int interactionRadius;
1579     float K, lambda, lambda1, lambda2;
1580     int occlusionCost;
1581     int minDisparity;
1582     int numberOfDisparities;
1583     int maxIters;
1584
1585     CvMat* left;
1586     CvMat* right;
1587     CvMat* dispLeft;
1588     CvMat* dispRight;
1589     CvMat* ptrLeft;
1590     CvMat* ptrRight;
1591     CvMat* vtxBuf;
1592     CvMat* edgeBuf;
1593 }
1594 CvStereoGCState;
1595
1596 CVAPI(CvStereoGCState*) cvCreateStereoGCState( int numberOfDisparities, int maxIters );
1597 CVAPI(void) cvReleaseStereoGCState( CvStereoGCState** state );
1598
1599 CVAPI(void) cvFindStereoCorrespondenceGC( const CvArr* left, const CvArr* right,
1600                                           CvArr* disparityLeft, CvArr* disparityRight,
1601                                           CvStereoGCState* state,
1602                                           int useDisparityGuess CV_DEFAULT(0) );
1603
1604 /* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
1605 CVAPI(void)  cvReprojectImageTo3D( const CvArr* disparityImage,
1606                                    CvArr* _3dImage, const CvMat* Q,
1607                                    int handleMissingValues CV_DEFAULT(0) );
1608
1609 #ifdef __cplusplus
1610 }
1611 #endif
1612
1613 #ifdef __cplusplus
1614 #ifndef SKIP_INCLUDES // for now only expose old interface to swig
1615 #include "cv.hpp"
1616 #endif // SKIP_INCLUDES
1617 #endif
1618
1619 /****************************************************************************************\
1620 *                                 Backward compatibility                                 *
1621 \****************************************************************************************/
1622
1623 #ifndef CV_NO_BACKWARD_COMPATIBILITY
1624 #include "cvcompat.h"
1625 #endif
1626
1627 #endif