1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
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.
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.
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.
52 #pragma package <chopencv>
65 /****************************************************************************************\
67 \****************************************************************************************/
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)));
74 #define CV_BLUR_NO_SCALE 0
78 #define CV_BILATERAL 4
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));
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)));
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));
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]
102 CVAPI(void) cvPyrDown( const CvArr* src, CvArr* dst,
103 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
106 Up-samples image and smoothes the result with gaussian kernel.
107 dst_width = src_width*2,
108 dst_height = src_height*2
110 CVAPI(void) cvPyrUp( const CvArr* src, CvArr* dst,
111 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) );
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) );
120 /* Releases pyramid */
121 CVAPI(void) cvReleasePyramid( CvMat*** pyramid, int extra_layers );
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,
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)));
138 /* Segments image using seed "markers" */
139 CVAPI(void) cvWatershed( const CvArr* image, CvArr* markers );
141 #define CV_INPAINT_NS 0
142 #define CV_INPAINT_TELEA 1
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 );
149 #define CV_MAX_SOBEL_KSIZE 7
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));
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) );
162 /* Constants for color conversion */
163 #define CV_BGR2BGRA 0
164 #define CV_RGB2RGBA CV_BGR2BGRA
166 #define CV_BGRA2BGR 1
167 #define CV_RGBA2RGB CV_BGRA2BGR
169 #define CV_BGR2RGBA 2
170 #define CV_RGB2BGRA CV_BGR2RGBA
172 #define CV_RGBA2BGR 3
173 #define CV_BGRA2RGB CV_RGBA2BGR
176 #define CV_RGB2BGR CV_BGR2RGB
178 #define CV_BGRA2RGBA 5
179 #define CV_RGBA2BGRA CV_BGRA2RGBA
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
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
199 #define CV_GRAY2BGR565 20
200 #define CV_BGR5652GRAY 21
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
211 #define CV_GRAY2BGR555 30
212 #define CV_BGR5552GRAY 31
214 #define CV_BGR2XYZ 32
215 #define CV_RGB2XYZ 33
216 #define CV_XYZ2BGR 34
217 #define CV_XYZ2RGB 35
219 #define CV_BGR2YCrCb 36
220 #define CV_RGB2YCrCb 37
221 #define CV_YCrCb2BGR 38
222 #define CV_YCrCb2RGB 39
224 #define CV_BGR2HSV 40
225 #define CV_RGB2HSV 41
227 #define CV_BGR2Lab 44
228 #define CV_RGB2Lab 45
230 #define CV_BayerBG2BGR 46
231 #define CV_BayerGB2BGR 47
232 #define CV_BayerRG2BGR 48
233 #define CV_BayerGR2BGR 49
235 #define CV_BayerBG2RGB CV_BayerRG2BGR
236 #define CV_BayerGB2RGB CV_BayerGR2BGR
237 #define CV_BayerRG2RGB CV_BayerBG2BGR
238 #define CV_BayerGR2RGB CV_BayerGB2BGR
240 #define CV_BGR2Luv 50
241 #define CV_RGB2Luv 51
242 #define CV_BGR2HLS 52
243 #define CV_RGB2HLS 53
245 #define CV_HSV2BGR 54
246 #define CV_HSV2RGB 55
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
255 #define CV_COLORCVT_MAX 100
257 /* Converts input array pixels from one color space to another */
258 CVAPI(void) cvCvtColor( const CvArr* src, CvArr* dst, int code );
260 #define CV_INTER_NN 0
261 #define CV_INTER_LINEAR 1
262 #define CV_INTER_CUBIC 2
263 #define CV_INTER_AREA 3
265 #define CV_WARP_FILL_OUTLIERS 8
266 #define CV_WARP_INVERSE_MAP 16
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 ));
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)) );
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 );
282 /* Computes rotation_matrix matrix */
283 CVAPI(CvMat*) cv2DRotationMatrix( CvPoint2D32f center, double angle,
284 double scale, CvMat* map_matrix );
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)) );
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,
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)) );
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 );
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));
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));
316 #define CV_SHAPE_RECT 0
317 #define CV_SHAPE_CROSS 1
318 #define CV_SHAPE_ELLIPSE 2
319 #define CV_SHAPE_CUSTOM 100
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) );
326 /* releases structuring element */
327 CVAPI(void) cvReleaseStructuringElement( IplConvKernel** element );
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) );
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) );
341 #define CV_MOP_OPEN 2
342 #define CV_MOP_CLOSE 3
343 #define CV_MOP_GRADIENT 4
344 #define CV_MOP_TOPHAT 5
345 #define CV_MOP_BLACKHAT 6
347 /* Performs complex morphological transformation */
348 CVAPI(void) cvMorphologyEx( const CvArr* src, CvArr* dst,
349 CvArr* temp, IplConvKernel* element,
350 int operation, int iterations CV_DEFAULT(1) );
352 /* Calculates all spatial and central moments up to the 3rd order */
353 CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0));
355 /* Retrieve particular spatial, central or normalized central moments */
356 CVAPI(double) cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );
357 CVAPI(double) cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );
358 CVAPI(double) cvGetNormalizedCentralMoment( CvMoments* moments,
359 int x_order, int y_order );
361 /* Calculates 7 Hu's invariants from precalculated spatial and central moments */
362 CVAPI(void) cvGetHuMoments( CvMoments* moments, CvHuMoments* hu_moments );
364 /*********************************** data sampling **************************************/
366 /* Fetches pixels that belong to the specified line segment and stores them to the buffer.
367 Returns the number of retrieved points. */
368 CVAPI(int) cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer,
369 int connectivity CV_DEFAULT(8));
371 /* Retrieves the rectangular image region with specified center from the input array.
372 dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2).
373 Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/
374 CVAPI(void) cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center );
377 /* Retrieves quadrangle from the input array.
378 matrixarr = ( a11 a12 | b1 ) dst(x,y) <- src(A[x y]' + b)
379 ( a21 a22 | b2 ) (bilinear interpolation is used to retrieve pixels
380 with fractional coordinates)
382 CVAPI(void) cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst,
383 const CvMat* map_matrix );
385 /* Methods for comparing two array */
386 #define CV_TM_SQDIFF 0
387 #define CV_TM_SQDIFF_NORMED 1
388 #define CV_TM_CCORR 2
389 #define CV_TM_CCORR_NORMED 3
390 #define CV_TM_CCOEFF 4
391 #define CV_TM_CCOEFF_NORMED 5
393 /* Measures similarity between template and overlapped windows in the source image
394 and fills the resultant image with the measurements */
395 CVAPI(void) cvMatchTemplate( const CvArr* image, const CvArr* templ,
396 CvArr* result, int method );
398 /* Computes earth mover distance between
399 two weighted point sets (called signatures) */
400 CVAPI(float) cvCalcEMD2( const CvArr* signature1,
401 const CvArr* signature2,
403 CvDistanceFunction distance_func CV_DEFAULT(NULL),
404 const CvArr* cost_matrix CV_DEFAULT(NULL),
405 CvArr* flow CV_DEFAULT(NULL),
406 float* lower_bound CV_DEFAULT(NULL),
407 void* userdata CV_DEFAULT(NULL));
409 /****************************************************************************************\
410 * Contours retrieving *
411 \****************************************************************************************/
413 /* Retrieves outer and optionally inner boundaries of white (non-zero) connected
414 components in the black (zero) background */
415 CVAPI(int) cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour,
416 int header_size CV_DEFAULT(sizeof(CvContour)),
417 int mode CV_DEFAULT(CV_RETR_LIST),
418 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
419 CvPoint offset CV_DEFAULT(cvPoint(0,0)));
422 /* Initalizes contour retrieving process.
423 Calls cvStartFindContours.
424 Calls cvFindNextContour until null pointer is returned
425 or some other condition becomes true.
426 Calls cvEndFindContours at the end. */
427 CVAPI(CvContourScanner) cvStartFindContours( CvArr* image, CvMemStorage* storage,
428 int header_size CV_DEFAULT(sizeof(CvContour)),
429 int mode CV_DEFAULT(CV_RETR_LIST),
430 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
431 CvPoint offset CV_DEFAULT(cvPoint(0,0)));
433 /* Retrieves next contour */
434 CVAPI(CvSeq*) cvFindNextContour( CvContourScanner scanner );
437 /* Substitutes the last retrieved contour with the new one
438 (if the substitutor is null, the last retrieved contour is removed from the tree) */
439 CVAPI(void) cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour );
442 /* Releases contour scanner and returns pointer to the first outer contour */
443 CVAPI(CvSeq*) cvEndFindContours( CvContourScanner* scanner );
445 /* Approximates a single Freeman chain or a tree of chains to polygonal curves */
446 CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage,
447 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE),
448 double parameter CV_DEFAULT(0),
449 int minimal_perimeter CV_DEFAULT(0),
450 int recursive CV_DEFAULT(0));
453 /* Initalizes Freeman chain reader.
454 The reader is used to iteratively get coordinates of all the chain points.
455 If the Freeman codes should be read as is, a simple sequence reader should be used */
456 CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader );
458 /* Retrieves the next chain point */
459 CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader );
462 /****************************************************************************************\
464 \****************************************************************************************/
466 /************************************ optical flow ***************************************/
468 /* Calculates optical flow for 2 images using classical Lucas & Kanade algorithm */
469 CVAPI(void) cvCalcOpticalFlowLK( const CvArr* prev, const CvArr* curr,
470 CvSize win_size, CvArr* velx, CvArr* vely );
472 /* Calculates optical flow for 2 images using block matching algorithm */
473 CVAPI(void) cvCalcOpticalFlowBM( const CvArr* prev, const CvArr* curr,
474 CvSize block_size, CvSize shift_size,
475 CvSize max_range, int use_previous,
476 CvArr* velx, CvArr* vely );
478 /* Calculates Optical flow for 2 images using Horn & Schunck algorithm */
479 CVAPI(void) cvCalcOpticalFlowHS( const CvArr* prev, const CvArr* curr,
480 int use_previous, CvArr* velx, CvArr* vely,
481 double lambda, CvTermCriteria criteria );
483 #define CV_LKFLOW_PYR_A_READY 1
484 #define CV_LKFLOW_PYR_B_READY 2
485 #define CV_LKFLOW_INITIAL_GUESSES 4
486 #define CV_LKFLOW_GET_MIN_EIGENVALS 8
488 /* It is Lucas & Kanade method, modified to use pyramids.
489 Also it does several iterations to get optical flow for
490 every point at every pyramid level.
491 Calculates optical flow between two images for certain set of points (i.e.
492 it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
493 CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr,
494 CvArr* prev_pyr, CvArr* curr_pyr,
495 const CvPoint2D32f* prev_features,
496 CvPoint2D32f* curr_features,
502 CvTermCriteria criteria,
506 /* Modification of a previous sparse optical flow algorithm to calculate
508 CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr,
509 CvArr* prev_pyr, CvArr* curr_pyr,
510 const CvPoint2D32f* prev_features,
511 CvPoint2D32f* curr_features,
512 float* matrices, int count,
513 CvSize win_size, int level,
514 char* status, float* track_error,
515 CvTermCriteria criteria, int flags );
517 /* Estimate rigid transformation between 2 images or 2 point sets */
518 CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
519 CvMat* M, int full_affine );
521 /********************************* motion templates *************************************/
523 /****************************************************************************************\
524 * All the motion template functions work only with single channel images. *
525 * Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S *
526 * Motion history image must have depth IPL_DEPTH_32F, *
527 * Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, *
528 * Motion orientation image - IPL_DEPTH_32F *
529 * Segmentation mask - IPL_DEPTH_32F *
530 * All the angles are in degrees, all the times are in milliseconds *
531 \****************************************************************************************/
533 /* Updates motion history image given motion silhouette */
534 CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
535 double timestamp, double duration );
537 /* Calculates gradient of the motion history image and fills
538 a mask indicating where the gradient is valid */
539 CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
540 double delta1, double delta2,
541 int aperture_size CV_DEFAULT(3));
543 /* Calculates average motion direction within a selected motion region
544 (region can be selected by setting ROIs and/or by composing a valid gradient mask
545 with the region mask) */
546 CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
547 const CvArr* mhi, double timestamp,
550 /* Splits a motion history image into a few parts corresponding to separate independent motions
551 (e.g. left hand, right hand) */
552 CVAPI(CvSeq*) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
553 CvMemStorage* storage,
554 double timestamp, double seg_thresh );
556 /*********************** Background statistics accumulation *****************************/
558 /* Adds image to accumulator */
559 CVAPI(void) cvAcc( const CvArr* image, CvArr* sum,
560 const CvArr* mask CV_DEFAULT(NULL) );
562 /* Adds squared image to accumulator */
563 CVAPI(void) cvSquareAcc( const CvArr* image, CvArr* sqsum,
564 const CvArr* mask CV_DEFAULT(NULL) );
566 /* Adds a product of two images to accumulator */
567 CVAPI(void) cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc,
568 const CvArr* mask CV_DEFAULT(NULL) );
570 /* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */
571 CVAPI(void) cvRunningAvg( const CvArr* image, CvArr* acc, double alpha,
572 const CvArr* mask CV_DEFAULT(NULL) );
575 /****************************************************************************************\
577 \****************************************************************************************/
579 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
580 from the object histogram back project (extension of meanshift) */
581 CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window,
582 CvTermCriteria criteria, CvConnectedComp* comp,
583 CvBox2D* box CV_DEFAULT(NULL) );
585 /* Implements MeanShift algorithm - determines object position
586 from the object histogram back project */
587 CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window,
588 CvTermCriteria criteria, CvConnectedComp* comp );
590 /* Creates ConDensation filter state */
591 CVAPI(CvConDensation*) cvCreateConDensation( int dynam_params,
595 /* Releases ConDensation filter state */
596 CVAPI(void) cvReleaseConDensation( CvConDensation** condens );
598 /* Updates ConDensation filter by time (predict future state of the system) */
599 CVAPI(void) cvConDensUpdateByTime( CvConDensation* condens);
601 /* Initializes ConDensation filter samples */
602 CVAPI(void) cvConDensInitSampleSet( CvConDensation* condens, CvMat* lower_bound, CvMat* upper_bound );
604 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
605 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
606 int control_params CV_DEFAULT(0));
608 /* Releases Kalman filter state */
609 CVAPI(void) cvReleaseKalman( CvKalman** kalman);
611 /* Updates Kalman filter by time (predicts future state of the system) */
612 CVAPI(const CvMat*) cvKalmanPredict( CvKalman* kalman,
613 const CvMat* control CV_DEFAULT(NULL));
615 /* Updates Kalman filter by measurement
616 (corrects state of the system and internal matrices) */
617 CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
619 /****************************************************************************************\
620 * Planar subdivisions *
621 \****************************************************************************************/
623 /* Initializes Delaunay triangulation */
624 CVAPI(void) cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect );
626 /* Creates new subdivision */
627 CVAPI(CvSubdiv2D*) cvCreateSubdiv2D( int subdiv_type, int header_size,
628 int vtx_size, int quadedge_size,
629 CvMemStorage* storage );
631 /************************* high-level subdivision functions ***************************/
633 /* Simplified Delaunay diagram creation */
634 CV_INLINE CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage )
636 CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv),
637 sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage );
639 cvInitSubdivDelaunay2D( subdiv, rect );
644 /* Inserts new point to the Delaunay triangulation */
645 CVAPI(CvSubdiv2DPoint*) cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt);
647 /* Locates a point within the Delaunay triangulation (finds the edge
648 the point is left to or belongs to, or the triangulation point the given
649 point coinsides with */
650 CVAPI(CvSubdiv2DPointLocation) cvSubdiv2DLocate(
651 CvSubdiv2D* subdiv, CvPoint2D32f pt,
652 CvSubdiv2DEdge* edge,
653 CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) );
655 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */
656 CVAPI(void) cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv );
659 /* Removes all Voronoi points from the tesselation */
660 CVAPI(void) cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv );
663 /* Finds the nearest to the given point vertex in subdivision. */
664 CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt );
667 /************ Basic quad-edge navigation and operations ************/
669 CV_INLINE CvSubdiv2DEdge cvSubdiv2DNextEdge( CvSubdiv2DEdge edge )
671 return CV_SUBDIV2D_NEXT_EDGE(edge);
675 CV_INLINE CvSubdiv2DEdge cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate )
677 return (edge & ~3) + ((edge + rotate) & 3);
680 CV_INLINE CvSubdiv2DEdge cvSubdiv2DSymEdge( CvSubdiv2DEdge edge )
685 CV_INLINE CvSubdiv2DEdge cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type )
687 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
688 edge = e->next[(edge + (int)type) & 3];
689 return (edge & ~3) + ((edge + ((int)type >> 4)) & 3);
693 CV_INLINE CvSubdiv2DPoint* cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge )
695 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
696 return (CvSubdiv2DPoint*)e->pt[edge & 3];
700 CV_INLINE CvSubdiv2DPoint* cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge )
702 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3);
703 return (CvSubdiv2DPoint*)e->pt[(edge + 2) & 3];
707 CV_INLINE double cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c )
709 return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
713 /****************************************************************************************\
714 * Contour Processing and Shape Analysis *
715 \****************************************************************************************/
717 #define CV_POLY_APPROX_DP 0
719 /* Approximates a single polygonal curve (contour) or
720 a tree of polygonal curves (contours) */
721 CVAPI(CvSeq*) cvApproxPoly( const void* src_seq,
722 int header_size, CvMemStorage* storage,
723 int method, double parameter,
724 int parameter2 CV_DEFAULT(0));
726 #define CV_DOMINANT_IPAN 1
728 /* Finds high-curvature points of the contour */
729 CVAPI(CvSeq*) cvFindDominantPoints( CvSeq* contour, CvMemStorage* storage,
730 int method CV_DEFAULT(CV_DOMINANT_IPAN),
731 double parameter1 CV_DEFAULT(0),
732 double parameter2 CV_DEFAULT(0),
733 double parameter3 CV_DEFAULT(0),
734 double parameter4 CV_DEFAULT(0));
736 /* Calculates perimeter of a contour or length of a part of contour */
737 CVAPI(double) cvArcLength( const void* curve,
738 CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
739 int is_closed CV_DEFAULT(-1));
740 #define cvContourPerimeter( contour ) cvArcLength( contour, CV_WHOLE_SEQ, 1 )
742 /* Calculates contour boundning rectangle (update=1) or
743 just retrieves pre-calculated rectangle (update=0) */
744 CVAPI(CvRect) cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) );
746 /* Calculates area of a contour or contour segment */
747 CVAPI(double) cvContourArea( const CvArr* contour,
748 CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
750 /* Finds minimum area rotated rectangle bounding a set of points */
751 CVAPI(CvBox2D) cvMinAreaRect2( const CvArr* points,
752 CvMemStorage* storage CV_DEFAULT(NULL));
754 /* Finds minimum enclosing circle for a set of points */
755 CVAPI(int) cvMinEnclosingCircle( const CvArr* points,
756 CvPoint2D32f* center, float* radius );
758 #define CV_CONTOURS_MATCH_I1 1
759 #define CV_CONTOURS_MATCH_I2 2
760 #define CV_CONTOURS_MATCH_I3 3
762 /* Compares two contours by matching their moments */
763 CVAPI(double) cvMatchShapes( const void* object1, const void* object2,
764 int method, double parameter CV_DEFAULT(0));
766 /* Builds hierarhical representation of a contour */
767 CVAPI(CvContourTree*) cvCreateContourTree( const CvSeq* contour,
768 CvMemStorage* storage,
771 /* Reconstruct (completelly or partially) contour a from contour tree */
772 CVAPI(CvSeq*) cvContourFromContourTree( const CvContourTree* tree,
773 CvMemStorage* storage,
774 CvTermCriteria criteria );
776 /* Compares two contour trees */
777 #define CV_CONTOUR_TREES_MATCH_I1 1
779 CVAPI(double) cvMatchContourTrees( const CvContourTree* tree1,
780 const CvContourTree* tree2,
781 int method, double threshold );
783 /* Calculates histogram of a contour */
784 CVAPI(void) cvCalcPGH( const CvSeq* contour, CvHistogram* hist );
786 #define CV_CLOCKWISE 1
787 #define CV_COUNTER_CLOCKWISE 2
789 /* Calculates exact convex hull of 2d point set */
790 CVAPI(CvSeq*) cvConvexHull2( const CvArr* input,
791 void* hull_storage CV_DEFAULT(NULL),
792 int orientation CV_DEFAULT(CV_CLOCKWISE),
793 int return_points CV_DEFAULT(0));
795 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */
796 CVAPI(int) cvCheckContourConvexity( const CvArr* contour );
798 /* Finds convexity defects for the contour */
799 CVAPI(CvSeq*) cvConvexityDefects( const CvArr* contour, const CvArr* convexhull,
800 CvMemStorage* storage CV_DEFAULT(NULL));
802 /* Fits ellipse into a set of 2d points */
803 CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points );
805 /* Finds minimum rectangle containing two given rectangles */
806 CVAPI(CvRect) cvMaxRect( const CvRect* rect1, const CvRect* rect2 );
808 /* Finds coordinates of the box vertices */
809 CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] );
811 /* Initializes sequence header for a matrix (column or row vector) of points -
812 a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */
813 CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat,
814 CvContour* contour_header,
817 /* Checks whether the point is inside polygon, outside, on an edge (at a vertex).
818 Returns positive, negative or zero value, correspondingly.
819 Optionally, measures a signed distance between
820 the point and the nearest polygon edge (measure_dist=1) */
821 CVAPI(double) cvPointPolygonTest( const CvArr* contour,
822 CvPoint2D32f pt, int measure_dist );
824 /****************************************************************************************\
825 * Histogram functions *
826 \****************************************************************************************/
828 /* Creates new histogram */
829 CVAPI(CvHistogram*) cvCreateHist( int dims, int* sizes, int type,
830 float** ranges CV_DEFAULT(NULL),
831 int uniform CV_DEFAULT(1));
833 /* Assignes histogram bin ranges */
834 CVAPI(void) cvSetHistBinRanges( CvHistogram* hist, float** ranges,
835 int uniform CV_DEFAULT(1));
837 /* Creates histogram header for array */
838 CVAPI(CvHistogram*) cvMakeHistHeaderForArray(
839 int dims, int* sizes, CvHistogram* hist,
840 float* data, float** ranges CV_DEFAULT(NULL),
841 int uniform CV_DEFAULT(1));
843 /* Releases histogram */
844 CVAPI(void) cvReleaseHist( CvHistogram** hist );
846 /* Clears all the histogram bins */
847 CVAPI(void) cvClearHist( CvHistogram* hist );
849 /* Finds indices and values of minimum and maximum histogram bins */
850 CVAPI(void) cvGetMinMaxHistValue( const CvHistogram* hist,
851 float* min_value, float* max_value,
852 int* min_idx CV_DEFAULT(NULL),
853 int* max_idx CV_DEFAULT(NULL));
856 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>.
857 After that sum of histogram bins is equal to <factor> */
858 CVAPI(void) cvNormalizeHist( CvHistogram* hist, double factor );
861 /* Clear all histogram bins that are below the threshold */
862 CVAPI(void) cvThreshHist( CvHistogram* hist, double threshold );
864 #define CV_COMP_CORREL 0
865 #define CV_COMP_CHISQR 1
866 #define CV_COMP_INTERSECT 2
867 #define CV_COMP_BHATTACHARYYA 3
869 /* Compares two histogram */
870 CVAPI(double) cvCompareHist( const CvHistogram* hist1,
871 const CvHistogram* hist2,
874 /* Copies one histogram to another. Destination histogram is created if
875 the destination pointer is NULL */
876 CVAPI(void) cvCopyHist( const CvHistogram* src, CvHistogram** dst );
879 /* Calculates bayesian probabilistic histograms
880 (each or src and dst is an array of <number> histograms */
881 CVAPI(void) cvCalcBayesianProb( CvHistogram** src, int number,
884 /* Calculates array histogram */
885 CVAPI(void) cvCalcArrHist( CvArr** arr, CvHistogram* hist,
886 int accumulate CV_DEFAULT(0),
887 const CvArr* mask CV_DEFAULT(NULL) );
889 CV_INLINE void cvCalcHist( IplImage** image, CvHistogram* hist,
890 int accumulate CV_DEFAULT(0),
891 const CvArr* mask CV_DEFAULT(NULL) )
893 cvCalcArrHist( (CvArr**)image, hist, accumulate, mask );
896 /* Calculates back project */
897 CVAPI(void) cvCalcArrBackProject( CvArr** image, CvArr* dst,
898 const CvHistogram* hist );
899 #define cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist)
902 /* Does some sort of template matching but compares histograms of
903 template and each window location */
904 CVAPI(void) cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range,
905 CvHistogram* hist, int method,
907 #define cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \
908 cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor )
911 /* calculates probabilistic density (divides one histogram by another) */
912 CVAPI(void) cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2,
913 CvHistogram* dst_hist, double scale CV_DEFAULT(255) );
915 /* equalizes histogram of 8-bit single-channel image */
916 CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst );
921 /* Updates active contour in order to minimize its cummulative
922 (internal and external) energy. */
923 CVAPI(void) cvSnakeImage( const IplImage* image, CvPoint* points,
924 int length, float* alpha,
925 float* beta, float* gamma,
926 int coeff_usage, CvSize win,
927 CvTermCriteria criteria, int calc_gradient CV_DEFAULT(1));
929 /* Calculates the cooficients of the homography matrix */
930 CVAPI(void) cvCalcImageHomography( float* line, CvPoint3D32f* center,
931 float* intrinsic, float* homography );
933 #define CV_DIST_MASK_3 3
934 #define CV_DIST_MASK_5 5
935 #define CV_DIST_MASK_PRECISE 0
937 /* Applies distance transform to binary image */
938 CVAPI(void) cvDistTransform( const CvArr* src, CvArr* dst,
939 int distance_type CV_DEFAULT(CV_DIST_L2),
940 int mask_size CV_DEFAULT(3),
941 const float* mask CV_DEFAULT(NULL),
942 CvArr* labels CV_DEFAULT(NULL));
945 /* Types of thresholding */
946 #define CV_THRESH_BINARY 0 /* value = value > threshold ? max_value : 0 */
947 #define CV_THRESH_BINARY_INV 1 /* value = value > threshold ? 0 : max_value */
948 #define CV_THRESH_TRUNC 2 /* value = value > threshold ? threshold : value */
949 #define CV_THRESH_TOZERO 3 /* value = value > threshold ? value : 0 */
950 #define CV_THRESH_TOZERO_INV 4 /* value = value > threshold ? 0 : value */
951 #define CV_THRESH_MASK 7
953 #define CV_THRESH_OTSU 8 /* use Otsu algorithm to choose the optimal threshold value;
954 combine the flag with one of the above CV_THRESH_* values */
956 /* Applies fixed-level threshold to grayscale image.
957 This is a basic operation applied before retrieving contours */
958 CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst,
959 double threshold, double max_value,
960 int threshold_type );
962 #define CV_ADAPTIVE_THRESH_MEAN_C 0
963 #define CV_ADAPTIVE_THRESH_GAUSSIAN_C 1
965 /* Applies adaptive threshold to grayscale image.
966 The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and
967 CV_ADAPTIVE_THRESH_GAUSSIAN_C are:
968 neighborhood size (3, 5, 7 etc.),
969 and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */
970 CVAPI(void) cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
971 int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C),
972 int threshold_type CV_DEFAULT(CV_THRESH_BINARY),
973 int block_size CV_DEFAULT(3),
974 double param1 CV_DEFAULT(5));
976 #define CV_FLOODFILL_FIXED_RANGE (1 << 16)
977 #define CV_FLOODFILL_MASK_ONLY (1 << 17)
979 /* Fills the connected component until the color difference gets large enough */
980 CVAPI(void) cvFloodFill( CvArr* image, CvPoint seed_point,
981 CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)),
982 CvScalar up_diff CV_DEFAULT(cvScalarAll(0)),
983 CvConnectedComp* comp CV_DEFAULT(NULL),
984 int flags CV_DEFAULT(4),
985 CvArr* mask CV_DEFAULT(NULL));
987 /****************************************************************************************\
988 * Feature detection *
989 \****************************************************************************************/
991 #define CV_CANNY_L2_GRADIENT (1 << 31)
993 /* Runs canny edge detector */
994 CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1,
995 double threshold2, int aperture_size CV_DEFAULT(3) );
997 /* Calculates constraint image for corner detection
998 Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy.
999 Applying threshold to the result gives coordinates of corners */
1000 CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners,
1001 int aperture_size CV_DEFAULT(3) );
1003 /* Calculates eigen values and vectors of 2x2
1004 gradient covariation matrix at every image pixel */
1005 CVAPI(void) cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,
1006 int block_size, int aperture_size CV_DEFAULT(3) );
1008 /* Calculates minimal eigenvalue for 2x2 gradient covariation matrix at
1009 every image pixel */
1010 CVAPI(void) cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval,
1011 int block_size, int aperture_size CV_DEFAULT(3) );
1013 /* Harris corner detector:
1014 Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */
1015 CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_responce,
1016 int block_size, int aperture_size CV_DEFAULT(3),
1017 double k CV_DEFAULT(0.04) );
1019 /* Adjust corner position using some sort of gradient search */
1020 CVAPI(void) cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,
1021 int count, CvSize win, CvSize zero_zone,
1022 CvTermCriteria criteria );
1024 /* Finds a sparse set of points within the selected region
1025 that seem to be easy to track */
1026 CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image,
1027 CvArr* temp_image, CvPoint2D32f* corners,
1028 int* corner_count, double quality_level,
1029 double min_distance,
1030 const CvArr* mask CV_DEFAULT(NULL),
1031 int block_size CV_DEFAULT(3),
1032 int use_harris CV_DEFAULT(0),
1033 double k CV_DEFAULT(0.04) );
1035 #define CV_HOUGH_STANDARD 0
1036 #define CV_HOUGH_PROBABILISTIC 1
1037 #define CV_HOUGH_MULTI_SCALE 2
1038 #define CV_HOUGH_GRADIENT 3
1040 /* Finds lines on binary image using one of several methods.
1041 line_storage is either memory storage or 1 x <max number of lines> CvMat, its
1042 number of columns is changed by the function.
1043 method is one of CV_HOUGH_*;
1044 rho, theta and threshold are used for each of those methods;
1045 param1 ~ line length, param2 ~ line gap - for probabilistic,
1046 param1 ~ srn, param2 ~ stn - for multi-scale */
1047 CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method,
1048 double rho, double theta, int threshold,
1049 double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0));
1051 /* Finds circles in the image */
1052 CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,
1053 int method, double dp, double min_dist,
1054 double param1 CV_DEFAULT(100),
1055 double param2 CV_DEFAULT(100),
1056 int min_radius CV_DEFAULT(0),
1057 int max_radius CV_DEFAULT(0));
1059 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */
1060 CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param,
1061 double reps, double aeps, float* line );
1065 struct CvFeatureTree;
1067 /* Constructs kd-tree from set of feature descriptors */
1068 CVAPI(struct CvFeatureTree*) cvCreateKDTree(CvMat* desc);
1070 /* Constructs spill-tree from set of feature descriptors */
1071 CVAPI(struct CvFeatureTree*) cvCreateSpillTree( const CvMat* raw_data,
1072 const int naive CV_DEFAULT(50),
1073 const double rho CV_DEFAULT(.7),
1074 const double tau CV_DEFAULT(.1) );
1076 /* Release feature tree */
1077 CVAPI(void) cvReleaseFeatureTree(struct CvFeatureTree* tr);
1079 /* Searches feature tree for k nearest neighbors of given reference points,
1080 searching (in case of kd-tree/bbf) at most emax leaves. */
1081 CVAPI(void) cvFindFeatures(struct CvFeatureTree* tr, const CvMat* query_points,
1082 CvMat* indices, CvMat* dist, int k, int emax CV_DEFAULT(20));
1084 /* Search feature tree for all points that are inlier to given rect region.
1085 Only implemented for kd trees */
1086 CVAPI(int) cvFindFeaturesBoxed(struct CvFeatureTree* tr,
1087 CvMat* bounds_min, CvMat* bounds_max,
1088 CvMat* out_indices);
1092 struct CvLSHOperations;
1094 /* Construct a Locality Sensitive Hash (LSH) table, for indexing d-dimensional vectors of
1095 given type. Vectors will be hashed L times with k-dimensional p-stable (p=2) functions. */
1096 CVAPI(struct CvLSH*) cvCreateLSH(struct CvLSHOperations* ops, int d,
1097 int L CV_DEFAULT(10), int k CV_DEFAULT(10),
1098 int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4),
1099 int64 seed CV_DEFAULT(-1));
1101 /* Construct in-memory LSH table, with n bins. */
1102 CVAPI(struct CvLSH*) cvCreateMemoryLSH(int d, int n, int L CV_DEFAULT(10), int k CV_DEFAULT(10),
1103 int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4),
1104 int64 seed CV_DEFAULT(-1));
1106 /* Free the given LSH structure. */
1107 CVAPI(void) cvReleaseLSH(struct CvLSH** lsh);
1109 /* Return the number of vectors in the LSH. */
1110 CVAPI(unsigned int) LSHSize(struct CvLSH* lsh);
1112 /* Add vectors to the LSH structure, optionally returning indices. */
1113 CVAPI(void) cvLSHAdd(struct CvLSH* lsh, const CvMat* data, CvMat* indices CV_DEFAULT(0));
1115 /* Remove vectors from LSH, as addressed by given indices. */
1116 CVAPI(void) cvLSHRemove(struct CvLSH* lsh, const CvMat* indices);
1118 /* Query the LSH n times for at most k nearest points; data is n x d,
1119 indices and dist are n x k. At most emax stored points will be accessed. */
1120 CVAPI(void) cvLSHQuery(struct CvLSH* lsh, const CvMat* query_points,
1121 CvMat* indices, CvMat* dist, int k, int emax);
1124 typedef struct CvSURFPoint
1133 CV_INLINE CvSURFPoint cvSURFPoint( CvPoint2D32f pt, int laplacian,
1134 int size, float dir CV_DEFAULT(0),
1135 float hessian CV_DEFAULT(0))
1139 kp.laplacian = laplacian;
1142 kp.hessian = hessian;
1146 typedef struct CvSURFParams
1149 double hessianThreshold;
1156 CVAPI(CvSURFParams) cvSURFParams( double hessianThreshold, int extended CV_DEFAULT(0) );
1158 // If useProvidedKeyPts!=0, keypoints are not detected, but descriptors are computed
1159 // at the locations provided in keypoints (a CvSeq of CvSURFPoint).
1160 CVAPI(void) cvExtractSURF( const CvArr* img, const CvArr* mask,
1161 CvSeq** keypoints, CvSeq** descriptors,
1162 CvMemStorage* storage, CvSURFParams params, int useProvidedKeyPts CV_DEFAULT(0) );
1164 typedef struct CvMSERParams
1166 // delta, in the code, it compares (size_{i}-size_{i-delta})/size_{i-delta}
1168 // prune the area which bigger/smaller than max_area/min_area
1171 // prune the area have simliar size to its children
1173 // trace back to cut off mser with diversity < min_diversity
1175 /* the next few params for MSER of color image */
1176 // for color image, the evolution steps
1178 // the area threshold to cause re-initialize
1179 double areaThreshold;
1180 // ignore too small margin
1182 // the aperture size for edge blur
1187 CVAPI(CvMSERParams) cvMSERParams( int delta CV_DEFAULT(5), int min_area CV_DEFAULT(60),
1188 int max_area CV_DEFAULT(14400), float max_variation CV_DEFAULT(.25f),
1189 float min_diversity CV_DEFAULT(.2f), int max_evolution CV_DEFAULT(200),
1190 double area_threshold CV_DEFAULT(1.01),
1191 double min_margin CV_DEFAULT(.003),
1192 int edge_blur_size CV_DEFAULT(5) );
1194 // Extracts the contours of Maximally Stable Extremal Regions
1195 CVAPI(void) cvExtractMSER( CvArr* _img, CvArr* _mask, CvSeq** contours, CvMemStorage* storage, CvMSERParams params );
1198 typedef struct CvStarKeypoint
1206 CV_INLINE CvStarKeypoint cvStarKeypoint(CvPoint pt, int size, float response)
1211 kpt.response = response;
1215 typedef struct CvStarDetectorParams
1218 int responseThreshold;
1219 int lineThresholdProjected;
1220 int lineThresholdBinarized;
1221 int suppressNonmaxSize;
1223 CvStarDetectorParams;
1225 CV_INLINE CvStarDetectorParams cvStarDetectorParams(
1226 int maxSize CV_DEFAULT(45),
1227 int responseThreshold CV_DEFAULT(30),
1228 int lineThresholdProjected CV_DEFAULT(10),
1229 int lineThresholdBinarized CV_DEFAULT(8),
1230 int suppressNonmaxSize CV_DEFAULT(5))
1232 CvStarDetectorParams params;
1233 params.maxSize = maxSize;
1234 params.responseThreshold = responseThreshold;
1235 params.lineThresholdProjected = lineThresholdProjected;
1236 params.lineThresholdBinarized = lineThresholdBinarized;
1237 params.suppressNonmaxSize = suppressNonmaxSize;
1242 CVAPI(CvSeq*) cvGetStarKeypoints( const CvArr* img, CvMemStorage* storage,
1243 CvStarDetectorParams params CV_DEFAULT(cvStarDetectorParams()));
1245 /****************************************************************************************\
1246 * Haar-like Object Detection functions *
1247 \****************************************************************************************/
1249 /* Loads haar classifier cascade from a directory.
1250 It is obsolete: convert your cascade to xml and use cvLoad instead */
1251 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
1252 const char* directory, CvSize orig_window_size);
1254 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
1256 #define CV_HAAR_DO_CANNY_PRUNING 1
1257 #define CV_HAAR_SCALE_IMAGE 2
1258 #define CV_HAAR_FIND_BIGGEST_OBJECT 4
1259 #define CV_HAAR_DO_ROUGH_SEARCH 8
1261 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
1262 CvHaarClassifierCascade* cascade,
1263 CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
1264 int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
1265 CvSize min_size CV_DEFAULT(cvSize(0,0)));
1267 /* sets images for haar classifier cascade */
1268 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
1269 const CvArr* sum, const CvArr* sqsum,
1270 const CvArr* tilted_sum, double scale );
1272 /* runs the cascade on the specified window */
1273 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
1274 CvPoint pt, int start_stage CV_DEFAULT(0));
1276 /****************************************************************************************\
1277 * Camera Calibration, Pose Estimation and Stereo *
1278 \****************************************************************************************/
1280 /* Transforms the input image to compensate lens distortion */
1281 CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
1282 const CvMat* camera_matrix,
1283 const CvMat* distortion_coeffs );
1285 /* Computes transformation map from intrinsic camera parameters
1286 that can used by cvRemap */
1287 CVAPI(void) cvInitUndistortMap( const CvMat* camera_matrix,
1288 const CvMat* distortion_coeffs,
1289 CvArr* mapx, CvArr* mapy );
1291 /* Computes undistortion+rectification map for a head of stereo camera */
1292 CVAPI(void) cvInitUndistortRectifyMap( const CvMat* camera_matrix,
1293 const CvMat* dist_coeffs,
1294 const CvMat *R, const CvMat* new_camera_matrix,
1295 CvArr* mapx, CvArr* mapy );
1297 /* Computes the original (undistorted) feature coordinates
1298 from the observed (distorted) coordinates */
1299 CVAPI(void) cvUndistortPoints( const CvMat* src, CvMat* dst,
1300 const CvMat* camera_matrix,
1301 const CvMat* dist_coeffs,
1302 const CvMat* R CV_DEFAULT(0),
1303 const CvMat* P CV_DEFAULT(0));
1305 /* Converts rotation vector to rotation matrix or vice versa */
1306 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
1307 CvMat* jacobian CV_DEFAULT(0) );
1312 /* Finds perspective transformation between the object plane and image (view) plane */
1313 CVAPI(int) cvFindHomography( const CvMat* src_points,
1314 const CvMat* dst_points,
1316 int method CV_DEFAULT(0),
1317 double ransacReprojThreshold CV_DEFAULT(0),
1318 CvMat* mask CV_DEFAULT(0));
1320 /* Computes RQ decomposition for 3x3 matrices */
1321 CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
1322 CvMat *matrixQx CV_DEFAULT(NULL),
1323 CvMat *matrixQy CV_DEFAULT(NULL),
1324 CvMat *matrixQz CV_DEFAULT(NULL),
1325 CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1327 /* Computes projection matrix decomposition */
1328 CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
1329 CvMat *rotMatr, CvMat *posVect,
1330 CvMat *rotMatrX CV_DEFAULT(NULL),
1331 CvMat *rotMatrY CV_DEFAULT(NULL),
1332 CvMat *rotMatrZ CV_DEFAULT(NULL),
1333 CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
1335 /* Computes d(AB)/dA and d(AB)/dB */
1336 CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
1338 /* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
1339 t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
1340 CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
1341 const CvMat* _rvec2, const CvMat* _tvec2,
1342 CvMat* _rvec3, CvMat* _tvec3,
1343 CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
1344 CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
1345 CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
1346 CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
1348 /* Projects object points to the view plane using
1349 the specified extrinsic and intrinsic camera parameters */
1350 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
1351 const CvMat* translation_vector, const CvMat* camera_matrix,
1352 const CvMat* distortion_coeffs, CvMat* image_points,
1353 CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
1354 CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
1355 CvMat* dpddist CV_DEFAULT(NULL),
1356 double aspect_ratio CV_DEFAULT(0));
1358 /* Finds extrinsic camera parameters from
1359 a few known corresponding point pairs and intrinsic parameters */
1360 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
1361 const CvMat* image_points,
1362 const CvMat* camera_matrix,
1363 const CvMat* distortion_coeffs,
1364 CvMat* rotation_vector,
1365 CvMat* translation_vector,
1366 int use_extrinsic_guess CV_DEFAULT(0) );
1368 /* Computes initial estimate of the intrinsic camera parameters
1369 in case of planar calibration target (e.g. chessboard) */
1370 CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
1371 const CvMat* image_points,
1372 const CvMat* npoints, CvSize image_size,
1373 CvMat* camera_matrix,
1374 double aspect_ratio CV_DEFAULT(1.) );
1376 #define CV_CALIB_CB_ADAPTIVE_THRESH 1
1377 #define CV_CALIB_CB_NORMALIZE_IMAGE 2
1378 #define CV_CALIB_CB_FILTER_QUADS 4
1380 /* Detects corners on a chessboard calibration pattern */
1381 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
1382 CvPoint2D32f* corners,
1383 int* corner_count CV_DEFAULT(NULL),
1384 int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+
1385 CV_CALIB_CB_NORMALIZE_IMAGE) );
1387 /* Draws individual chessboard corners or the whole chessboard detected */
1388 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
1389 CvPoint2D32f* corners,
1390 int count, int pattern_was_found );
1392 #define CV_CALIB_USE_INTRINSIC_GUESS 1
1393 #define CV_CALIB_FIX_ASPECT_RATIO 2
1394 #define CV_CALIB_FIX_PRINCIPAL_POINT 4
1395 #define CV_CALIB_ZERO_TANGENT_DIST 8
1396 #define CV_CALIB_FIX_FOCAL_LENGTH 16
1397 #define CV_CALIB_FIX_K1 32
1398 #define CV_CALIB_FIX_K2 64
1399 #define CV_CALIB_FIX_K3 128
1401 /* Finds intrinsic and extrinsic camera parameters
1402 from a few views of known calibration pattern */
1403 CVAPI(void) cvCalibrateCamera2( const CvMat* object_points,
1404 const CvMat* image_points,
1405 const CvMat* point_counts,
1407 CvMat* camera_matrix,
1408 CvMat* distortion_coeffs,
1409 CvMat* rotation_vectors CV_DEFAULT(NULL),
1410 CvMat* translation_vectors CV_DEFAULT(NULL),
1411 int flags CV_DEFAULT(0) );
1413 /* Computes various useful characteristics of the camera from the data computed by
1414 cvCalibrateCamera2 */
1415 CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
1417 double aperture_width CV_DEFAULT(0),
1418 double aperture_height CV_DEFAULT(0),
1419 double *fovx CV_DEFAULT(NULL),
1420 double *fovy CV_DEFAULT(NULL),
1421 double *focal_length CV_DEFAULT(NULL),
1422 CvPoint2D64f *principal_point CV_DEFAULT(NULL),
1423 double *pixel_aspect_ratio CV_DEFAULT(NULL));
1425 #define CV_CALIB_FIX_INTRINSIC 256
1426 #define CV_CALIB_SAME_FOCAL_LENGTH 512
1428 /* Computes the transformation from one camera coordinate system to another one
1429 from a few correspondent views of the same calibration target. Optionally, calibrates
1431 CVAPI(void) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
1432 const CvMat* image_points2, const CvMat* npoints,
1433 CvMat* camera_matrix1, CvMat* dist_coeffs1,
1434 CvMat* camera_matrix2, CvMat* dist_coeffs2,
1435 CvSize image_size, CvMat* R, CvMat* T,
1436 CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
1437 CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
1438 CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
1439 int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC) );
1441 #define CV_CALIB_ZERO_DISPARITY 1024
1443 /* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
1444 views parallel (=> to make all the epipolar lines horizontal or vertical) */
1445 CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
1446 const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
1447 CvSize image_size, const CvMat* R, const CvMat* T,
1448 CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
1449 CvMat* Q CV_DEFAULT(0),
1450 int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY) );
1452 /* Computes rectification transformations for uncalibrated pair of images using a set
1453 of point correspondences */
1454 CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
1455 const CvMat* F, CvSize img_size,
1456 CvMat* H1, CvMat* H2,
1457 double threshold CV_DEFAULT(5));
1459 typedef struct CvPOSITObject CvPOSITObject;
1461 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
1462 CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
1465 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
1466 an object given its model and projection in a weak-perspective case */
1467 CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
1468 double focal_length, CvTermCriteria criteria,
1469 CvMatr32f rotation_matrix, CvVect32f translation_vector);
1471 /* Releases CvPOSITObject structure */
1472 CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
1474 /* updates the number of RANSAC iterations */
1475 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
1476 int model_points, int max_iters );
1478 CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
1480 /* Calculates fundamental matrix given a set of corresponding points */
1481 #define CV_FM_7POINT 1
1482 #define CV_FM_8POINT 2
1483 #define CV_FM_LMEDS_ONLY CV_LMEDS
1484 #define CV_FM_RANSAC_ONLY CV_RANSAC
1485 #define CV_FM_LMEDS CV_LMEDS
1486 #define CV_FM_RANSAC CV_RANSAC
1487 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
1488 CvMat* fundamental_matrix,
1489 int method CV_DEFAULT(CV_FM_RANSAC),
1490 double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
1491 CvMat* status CV_DEFAULT(NULL) );
1493 /* For each input point on one of images
1494 computes parameters of the corresponding
1495 epipolar line on the other image */
1496 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
1498 const CvMat* fundamental_matrix,
1499 CvMat* correspondent_lines );
1501 /* Triangulation functions */
1503 CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
1504 CvMat* projPoints1, CvMat* projPoints2,
1507 CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
1508 CvMat* new_points1, CvMat* new_points2);
1510 /* stereo correspondence parameters and functions */
1512 #define CV_STEREO_BM_NORMALIZED_RESPONSE 0
1514 /* Block matching algorithm structure */
1515 typedef struct CvStereoBMState
1517 // pre-filtering (normalization of input images)
1518 int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
1519 int preFilterSize; // averaging window size: ~5x5..21x21
1520 int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
1522 // correspondence using Sum of Absolute Difference (SAD)
1523 int SADWindowSize; // ~5x5..21x21
1524 int minDisparity; // minimum disparity (can be negative)
1525 int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
1528 int textureThreshold; // the disparity is only computed for pixels
1529 // with textured enough neighborhood
1530 int uniquenessRatio; // accept the computed disparity d* only if
1531 // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
1532 // for any d != d*+/-1 within the search range.
1533 int speckleWindowSize; // disparity variation window
1534 int speckleRange; // acceptable range of variation in window
1536 int trySmallerWindows; // if 1, the results may be more accurate,
1537 // at the expense of slower processing
1539 // temporary buffers
1540 CvMat* preFilteredImg0;
1541 CvMat* preFilteredImg1;
1542 CvMat* slidingSumBuf;
1548 #define CV_STEREO_BM_BASIC 0
1549 #define CV_STEREO_BM_FISH_EYE 1
1550 #define CV_STEREO_BM_NARROW 2
1552 CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
1553 int numberOfDisparities CV_DEFAULT(0));
1555 CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
1557 CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
1558 CvArr* disparity, CvStereoBMState* state );
1560 /* Kolmogorov-Zabin stereo-correspondence algorithm (a.k.a. KZ1) */
1561 #define CV_STEREO_GC_OCCLUDED SHRT_MAX
1563 typedef struct CvStereoGCState
1566 int interactionRadius;
1567 float K, lambda, lambda1, lambda2;
1570 int numberOfDisparities;
1584 CVAPI(CvStereoGCState*) cvCreateStereoGCState( int numberOfDisparities, int maxIters );
1585 CVAPI(void) cvReleaseStereoGCState( CvStereoGCState** state );
1587 CVAPI(void) cvFindStereoCorrespondenceGC( const CvArr* left, const CvArr* right,
1588 CvArr* disparityLeft, CvArr* disparityRight,
1589 CvStereoGCState* state,
1590 int useDisparityGuess CV_DEFAULT(0) );
1592 /* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
1593 CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
1594 CvArr* _3dImage, const CvMat* Q,
1595 int handleMissingValues CV_DEFAULT(0) );
1602 #ifndef SKIP_INCLUDES // for now only expose old interface to swig
1604 #endif // SKIP_INCLUDES
1607 /****************************************************************************************\
1608 * Backward compatibility *
1609 \****************************************************************************************/
1611 #ifndef CV_NO_BACKWARD_COMPATIBILITY
1612 #include "cvcompat.h"