opencv 2.2.0
|
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 #ifndef __OPENCV_IMGPROC_IMGPROC_C_H__ 00044 #define __OPENCV_IMGPROC_IMGPROC_C_H__ 00045 00046 #include "opencv2/core/core_c.h" 00047 #include "opencv2/imgproc/types_c.h" 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00053 /*********************** Background statistics accumulation *****************************/ 00054 00055 /* Adds image to accumulator */ 00056 CVAPI(void) cvAcc( const CvArr* image, CvArr* sum, 00057 const CvArr* mask CV_DEFAULT(NULL) ); 00058 00059 /* Adds squared image to accumulator */ 00060 CVAPI(void) cvSquareAcc( const CvArr* image, CvArr* sqsum, 00061 const CvArr* mask CV_DEFAULT(NULL) ); 00062 00063 /* Adds a product of two images to accumulator */ 00064 CVAPI(void) cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc, 00065 const CvArr* mask CV_DEFAULT(NULL) ); 00066 00067 /* Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha */ 00068 CVAPI(void) cvRunningAvg( const CvArr* image, CvArr* acc, double alpha, 00069 const CvArr* mask CV_DEFAULT(NULL) ); 00070 00071 /****************************************************************************************\ 00072 * Image Processing * 00073 \****************************************************************************************/ 00074 00075 /* Copies source 2D array inside of the larger destination array and 00076 makes a border of the specified type (IPL_BORDER_*) around the copied area. */ 00077 CVAPI(void) cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, 00078 int bordertype, CvScalar value CV_DEFAULT(cvScalarAll(0))); 00079 00080 /* Smoothes array (removes noise) */ 00081 CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst, 00082 int smoothtype CV_DEFAULT(CV_GAUSSIAN), 00083 int size1 CV_DEFAULT(3), 00084 int size2 CV_DEFAULT(0), 00085 double sigma1 CV_DEFAULT(0), 00086 double sigma2 CV_DEFAULT(0)); 00087 00088 /* Convolves the image with the kernel */ 00089 CVAPI(void) cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel, 00090 CvPoint anchor CV_DEFAULT(cvPoint(-1,-1))); 00091 00092 /* Finds integral image: SUM(X,Y) = sum(x<X,y<Y)I(x,y) */ 00093 CVAPI(void) cvIntegral( const CvArr* image, CvArr* sum, 00094 CvArr* sqsum CV_DEFAULT(NULL), 00095 CvArr* tilted_sum CV_DEFAULT(NULL)); 00096 00097 /* 00098 Smoothes the input image with gaussian kernel and then down-samples it. 00099 dst_width = floor(src_width/2)[+1], 00100 dst_height = floor(src_height/2)[+1] 00101 */ 00102 CVAPI(void) cvPyrDown( const CvArr* src, CvArr* dst, 00103 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); 00104 00105 /* 00106 Up-samples image and smoothes the result with gaussian kernel. 00107 dst_width = src_width*2, 00108 dst_height = src_height*2 00109 */ 00110 CVAPI(void) cvPyrUp( const CvArr* src, CvArr* dst, 00111 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); 00112 00113 /* Builds pyramid for an image */ 00114 CVAPI(CvMat**) cvCreatePyramid( const CvArr* img, int extra_layers, double rate, 00115 const CvSize* layer_sizes CV_DEFAULT(0), 00116 CvArr* bufarr CV_DEFAULT(0), 00117 int calc CV_DEFAULT(1), 00118 int filter CV_DEFAULT(CV_GAUSSIAN_5x5) ); 00119 00120 /* Releases pyramid */ 00121 CVAPI(void) cvReleasePyramid( CvMat*** pyramid, int extra_layers ); 00122 00123 00124 /* Splits color or grayscale image into multiple connected components 00125 of nearly the same color/brightness using modification of Burt algorithm. 00126 comp with contain a pointer to sequence (CvSeq) 00127 of connected components (CvConnectedComp) */ 00128 CVAPI(void) cvPyrSegmentation( IplImage* src, IplImage* dst, 00129 CvMemStorage* storage, CvSeq** comp, 00130 int level, double threshold1, 00131 double threshold2 ); 00132 00133 /* Filters image using meanshift algorithm */ 00134 CVAPI(void) cvPyrMeanShiftFiltering( const CvArr* src, CvArr* dst, 00135 double sp, double sr, int max_level CV_DEFAULT(1), 00136 CvTermCriteria termcrit CV_DEFAULT(cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,5,1))); 00137 00138 /* Segments image using seed "markers" */ 00139 CVAPI(void) cvWatershed( const CvArr* image, CvArr* markers ); 00140 00141 /* Inpaints the selected region in the image */ 00142 CVAPI(void) cvInpaint( const CvArr* src, const CvArr* inpaint_mask, 00143 CvArr* dst, double inpaintRange, int flags ); 00144 00145 /* Calculates an image derivative using generalized Sobel 00146 (aperture_size = 1,3,5,7) or Scharr (aperture_size = -1) operator. 00147 Scharr can be used only for the first dx or dy derivative */ 00148 CVAPI(void) cvSobel( const CvArr* src, CvArr* dst, 00149 int xorder, int yorder, 00150 int aperture_size CV_DEFAULT(3)); 00151 00152 /* Calculates the image Laplacian: (d2/dx + d2/dy)I */ 00153 CVAPI(void) cvLaplace( const CvArr* src, CvArr* dst, 00154 int aperture_size CV_DEFAULT(3) ); 00155 00156 /* Converts input array pixels from one color space to another */ 00157 CVAPI(void) cvCvtColor( const CvArr* src, CvArr* dst, int code ); 00158 00159 00160 /* Resizes image (input array is resized to fit the destination array) */ 00161 CVAPI(void) cvResize( const CvArr* src, CvArr* dst, 00162 int interpolation CV_DEFAULT( CV_INTER_LINEAR )); 00163 00164 /* Warps image with affine transform */ 00165 CVAPI(void) cvWarpAffine( const CvArr* src, CvArr* dst, const CvMat* map_matrix, 00166 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), 00167 CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); 00168 00169 /* Computes affine transform matrix for mapping src[i] to dst[i] (i=0,1,2) */ 00170 CVAPI(CvMat*) cvGetAffineTransform( const CvPoint2D32f * src, 00171 const CvPoint2D32f * dst, 00172 CvMat * map_matrix ); 00173 00174 /* Computes rotation_matrix matrix */ 00175 CVAPI(CvMat*) cv2DRotationMatrix( CvPoint2D32f center, double angle, 00176 double scale, CvMat* map_matrix ); 00177 00178 /* Warps image with perspective (projective) transform */ 00179 CVAPI(void) cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix, 00180 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), 00181 CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); 00182 00183 /* Computes perspective transform matrix for mapping src[i] to dst[i] (i=0,1,2,3) */ 00184 CVAPI(CvMat*) cvGetPerspectiveTransform( const CvPoint2D32f* src, 00185 const CvPoint2D32f* dst, 00186 CvMat* map_matrix ); 00187 00188 /* Performs generic geometric transformation using the specified coordinate maps */ 00189 CVAPI(void) cvRemap( const CvArr* src, CvArr* dst, 00190 const CvArr* mapx, const CvArr* mapy, 00191 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), 00192 CvScalar fillval CV_DEFAULT(cvScalarAll(0)) ); 00193 00194 /* Converts mapx & mapy from floating-point to integer formats for cvRemap */ 00195 CVAPI(void) cvConvertMaps( const CvArr* mapx, const CvArr* mapy, 00196 CvArr* mapxy, CvArr* mapalpha ); 00197 00198 /* Performs forward or inverse log-polar image transform */ 00199 CVAPI(void) cvLogPolar( const CvArr* src, CvArr* dst, 00200 CvPoint2D32f center, double M, 00201 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)); 00202 00203 /* Performs forward or inverse linear-polar image transform */ 00204 CVAPI(void) cvLinearPolar( const CvArr* src, CvArr* dst, 00205 CvPoint2D32f center, double maxRadius, 00206 int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS)); 00207 00208 /* Transforms the input image to compensate lens distortion */ 00209 CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst, 00210 const CvMat* camera_matrix, 00211 const CvMat* distortion_coeffs, 00212 const CvMat* new_camera_matrix CV_DEFAULT(0) ); 00213 00214 /* Computes transformation map from intrinsic camera parameters 00215 that can used by cvRemap */ 00216 CVAPI(void) cvInitUndistortMap( const CvMat* camera_matrix, 00217 const CvMat* distortion_coeffs, 00218 CvArr* mapx, CvArr* mapy ); 00219 00220 /* Computes undistortion+rectification map for a head of stereo camera */ 00221 CVAPI(void) cvInitUndistortRectifyMap( const CvMat* camera_matrix, 00222 const CvMat* dist_coeffs, 00223 const CvMat *R, const CvMat* new_camera_matrix, 00224 CvArr* mapx, CvArr* mapy ); 00225 00226 /* Computes the original (undistorted) feature coordinates 00227 from the observed (distorted) coordinates */ 00228 CVAPI(void) cvUndistortPoints( const CvMat* src, CvMat* dst, 00229 const CvMat* camera_matrix, 00230 const CvMat* dist_coeffs, 00231 const CvMat* R CV_DEFAULT(0), 00232 const CvMat* P CV_DEFAULT(0)); 00233 00234 /* creates structuring element used for morphological operations */ 00235 CVAPI(IplConvKernel*) cvCreateStructuringElementEx( 00236 int cols, int rows, int anchor_x, int anchor_y, 00237 int shape, int* values CV_DEFAULT(NULL) ); 00238 00239 /* releases structuring element */ 00240 CVAPI(void) cvReleaseStructuringElement( IplConvKernel** element ); 00241 00242 /* erodes input image (applies minimum filter) one or more times. 00243 If element pointer is NULL, 3x3 rectangular element is used */ 00244 CVAPI(void) cvErode( const CvArr* src, CvArr* dst, 00245 IplConvKernel* element CV_DEFAULT(NULL), 00246 int iterations CV_DEFAULT(1) ); 00247 00248 /* dilates input image (applies maximum filter) one or more times. 00249 If element pointer is NULL, 3x3 rectangular element is used */ 00250 CVAPI(void) cvDilate( const CvArr* src, CvArr* dst, 00251 IplConvKernel* element CV_DEFAULT(NULL), 00252 int iterations CV_DEFAULT(1) ); 00253 00254 /* Performs complex morphological transformation */ 00255 CVAPI(void) cvMorphologyEx( const CvArr* src, CvArr* dst, 00256 CvArr* temp, IplConvKernel* element, 00257 int operation, int iterations CV_DEFAULT(1) ); 00258 00259 /* Calculates all spatial and central moments up to the 3rd order */ 00260 CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0)); 00261 00262 /* Retrieve particular spatial, central or normalized central moments */ 00263 CVAPI(double) cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order ); 00264 CVAPI(double) cvGetCentralMoment( CvMoments* moments, int x_order, int y_order ); 00265 CVAPI(double) cvGetNormalizedCentralMoment( CvMoments* moments, 00266 int x_order, int y_order ); 00267 00268 /* Calculates 7 Hu's invariants from precalculated spatial and central moments */ 00269 CVAPI(void) cvGetHuMoments( CvMoments* moments, CvHuMoments* hu_moments ); 00270 00271 /*********************************** data sampling **************************************/ 00272 00273 /* Fetches pixels that belong to the specified line segment and stores them to the buffer. 00274 Returns the number of retrieved points. */ 00275 CVAPI(int) cvSampleLine( const CvArr* image, CvPoint pt1, CvPoint pt2, void* buffer, 00276 int connectivity CV_DEFAULT(8)); 00277 00278 /* Retrieves the rectangular image region with specified center from the input array. 00279 dst(x,y) <- src(x + center.x - dst_width/2, y + center.y - dst_height/2). 00280 Values of pixels with fractional coordinates are retrieved using bilinear interpolation*/ 00281 CVAPI(void) cvGetRectSubPix( const CvArr* src, CvArr* dst, CvPoint2D32f center ); 00282 00283 00284 /* Retrieves quadrangle from the input array. 00285 matrixarr = ( a11 a12 | b1 ) dst(x,y) <- src(A[x y]' + b) 00286 ( a21 a22 | b2 ) (bilinear interpolation is used to retrieve pixels 00287 with fractional coordinates) 00288 */ 00289 CVAPI(void) cvGetQuadrangleSubPix( const CvArr* src, CvArr* dst, 00290 const CvMat* map_matrix ); 00291 00292 /* Measures similarity between template and overlapped windows in the source image 00293 and fills the resultant image with the measurements */ 00294 CVAPI(void) cvMatchTemplate( const CvArr* image, const CvArr* templ, 00295 CvArr* result, int method ); 00296 00297 /* Computes earth mover distance between 00298 two weighted point sets (called signatures) */ 00299 CVAPI(float) cvCalcEMD2( const CvArr* signature1, 00300 const CvArr* signature2, 00301 int distance_type, 00302 CvDistanceFunction distance_func CV_DEFAULT(NULL), 00303 const CvArr* cost_matrix CV_DEFAULT(NULL), 00304 CvArr* flow CV_DEFAULT(NULL), 00305 float* lower_bound CV_DEFAULT(NULL), 00306 void* userdata CV_DEFAULT(NULL)); 00307 00308 /****************************************************************************************\ 00309 * Contours retrieving * 00310 \****************************************************************************************/ 00311 00312 /* Retrieves outer and optionally inner boundaries of white (non-zero) connected 00313 components in the black (zero) background */ 00314 CVAPI(int) cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour, 00315 int header_size CV_DEFAULT(sizeof(CvContour)), 00316 int mode CV_DEFAULT(CV_RETR_LIST), 00317 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), 00318 CvPoint offset CV_DEFAULT(cvPoint(0,0))); 00319 00320 /* Initalizes contour retrieving process. 00321 Calls cvStartFindContours. 00322 Calls cvFindNextContour until null pointer is returned 00323 or some other condition becomes true. 00324 Calls cvEndFindContours at the end. */ 00325 CVAPI(CvContourScanner) cvStartFindContours( CvArr* image, CvMemStorage* storage, 00326 int header_size CV_DEFAULT(sizeof(CvContour)), 00327 int mode CV_DEFAULT(CV_RETR_LIST), 00328 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), 00329 CvPoint offset CV_DEFAULT(cvPoint(0,0))); 00330 00331 /* Retrieves next contour */ 00332 CVAPI(CvSeq*) cvFindNextContour( CvContourScanner scanner ); 00333 00334 00335 /* Substitutes the last retrieved contour with the new one 00336 (if the substitutor is null, the last retrieved contour is removed from the tree) */ 00337 CVAPI(void) cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour ); 00338 00339 00340 /* Releases contour scanner and returns pointer to the first outer contour */ 00341 CVAPI(CvSeq*) cvEndFindContours( CvContourScanner* scanner ); 00342 00343 /* Approximates a single Freeman chain or a tree of chains to polygonal curves */ 00344 CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, 00345 int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), 00346 double parameter CV_DEFAULT(0), 00347 int minimal_perimeter CV_DEFAULT(0), 00348 int recursive CV_DEFAULT(0)); 00349 00350 /* Initalizes Freeman chain reader. 00351 The reader is used to iteratively get coordinates of all the chain points. 00352 If the Freeman codes should be read as is, a simple sequence reader should be used */ 00353 CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader ); 00354 00355 /* Retrieves the next chain point */ 00356 CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader ); 00357 00358 /****************************************************************************************\ 00359 * Planar subdivisions * 00360 \****************************************************************************************/ 00361 00362 /* Initializes Delaunay triangulation */ 00363 CVAPI(void) cvInitSubdivDelaunay2D( CvSubdiv2D* subdiv, CvRect rect ); 00364 00365 /* Creates new subdivision */ 00366 CVAPI(CvSubdiv2D*) cvCreateSubdiv2D( int subdiv_type, int header_size, 00367 int vtx_size, int quadedge_size, 00368 CvMemStorage* storage ); 00369 00370 /************************* high-level subdivision functions ***************************/ 00371 00372 /* Simplified Delaunay diagram creation */ 00373 CV_INLINE CvSubdiv2D* cvCreateSubdivDelaunay2D( CvRect rect, CvMemStorage* storage ) 00374 { 00375 CvSubdiv2D* subdiv = cvCreateSubdiv2D( CV_SEQ_KIND_SUBDIV2D, sizeof(*subdiv), 00376 sizeof(CvSubdiv2DPoint), sizeof(CvQuadEdge2D), storage ); 00377 00378 cvInitSubdivDelaunay2D( subdiv, rect ); 00379 return subdiv; 00380 } 00381 00382 00383 /* Inserts new point to the Delaunay triangulation */ 00384 CVAPI(CvSubdiv2DPoint*) cvSubdivDelaunay2DInsert( CvSubdiv2D* subdiv, CvPoint2D32f pt); 00385 00386 /* Locates a point within the Delaunay triangulation (finds the edge 00387 the point is left to or belongs to, or the triangulation point the given 00388 point coinsides with */ 00389 CVAPI(CvSubdiv2DPointLocation) cvSubdiv2DLocate( 00390 CvSubdiv2D* subdiv, CvPoint2D32f pt, 00391 CvSubdiv2DEdge* edge, 00392 CvSubdiv2DPoint** vertex CV_DEFAULT(NULL) ); 00393 00394 /* Calculates Voronoi tesselation (i.e. coordinates of Voronoi points) */ 00395 CVAPI(void) cvCalcSubdivVoronoi2D( CvSubdiv2D* subdiv ); 00396 00397 00398 /* Removes all Voronoi points from the tesselation */ 00399 CVAPI(void) cvClearSubdivVoronoi2D( CvSubdiv2D* subdiv ); 00400 00401 00402 /* Finds the nearest to the given point vertex in subdivision. */ 00403 CVAPI(CvSubdiv2DPoint*) cvFindNearestPoint2D( CvSubdiv2D* subdiv, CvPoint2D32f pt ); 00404 00405 00406 /************ Basic quad-edge navigation and operations ************/ 00407 00408 CV_INLINE CvSubdiv2DEdge cvSubdiv2DNextEdge( CvSubdiv2DEdge edge ) 00409 { 00410 return CV_SUBDIV2D_NEXT_EDGE(edge); 00411 } 00412 00413 00414 CV_INLINE CvSubdiv2DEdge cvSubdiv2DRotateEdge( CvSubdiv2DEdge edge, int rotate ) 00415 { 00416 return (edge & ~3) + ((edge + rotate) & 3); 00417 } 00418 00419 CV_INLINE CvSubdiv2DEdge cvSubdiv2DSymEdge( CvSubdiv2DEdge edge ) 00420 { 00421 return edge ^ 2; 00422 } 00423 00424 CV_INLINE CvSubdiv2DEdge cvSubdiv2DGetEdge( CvSubdiv2DEdge edge, CvNextEdgeType type ) 00425 { 00426 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3); 00427 edge = e->next[(edge + (int)type) & 3]; 00428 return (edge & ~3) + ((edge + ((int)type >> 4)) & 3); 00429 } 00430 00431 00432 CV_INLINE CvSubdiv2DPoint* cvSubdiv2DEdgeOrg( CvSubdiv2DEdge edge ) 00433 { 00434 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3); 00435 return (CvSubdiv2DPoint*)e->pt[edge & 3]; 00436 } 00437 00438 00439 CV_INLINE CvSubdiv2DPoint* cvSubdiv2DEdgeDst( CvSubdiv2DEdge edge ) 00440 { 00441 CvQuadEdge2D* e = (CvQuadEdge2D*)(edge & ~3); 00442 return (CvSubdiv2DPoint*)e->pt[(edge + 2) & 3]; 00443 } 00444 00445 00446 CV_INLINE double cvTriangleArea( CvPoint2D32f a, CvPoint2D32f b, CvPoint2D32f c ) 00447 { 00448 return ((double)b.x - a.x) * ((double)c.y - a.y) - ((double)b.y - a.y) * ((double)c.x - a.x); 00449 } 00450 00451 00452 /****************************************************************************************\ 00453 * Contour Processing and Shape Analysis * 00454 \****************************************************************************************/ 00455 00456 /* Approximates a single polygonal curve (contour) or 00457 a tree of polygonal curves (contours) */ 00458 CVAPI(CvSeq*) cvApproxPoly( const void* src_seq, 00459 int header_size, CvMemStorage* storage, 00460 int method, double parameter, 00461 int parameter2 CV_DEFAULT(0)); 00462 00463 /* Calculates perimeter of a contour or length of a part of contour */ 00464 CVAPI(double) cvArcLength( const void* curve, 00465 CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ), 00466 int is_closed CV_DEFAULT(-1)); 00467 00468 CV_INLINE double cvContourPerimeter( const void* contour ) 00469 { 00470 return cvArcLength( contour, CV_WHOLE_SEQ, 1 ); 00471 } 00472 00473 00474 /* Calculates contour boundning rectangle (update=1) or 00475 just retrieves pre-calculated rectangle (update=0) */ 00476 CVAPI(CvRect) cvBoundingRect( CvArr* points, int update CV_DEFAULT(0) ); 00477 00478 /* Calculates area of a contour or contour segment */ 00479 CVAPI(double) cvContourArea( const CvArr* contour, 00480 CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ), 00481 int oriented CV_DEFAULT(0)); 00482 00483 /* Finds minimum area rotated rectangle bounding a set of points */ 00484 CVAPI(CvBox2D) cvMinAreaRect2( const CvArr* points, 00485 CvMemStorage* storage CV_DEFAULT(NULL)); 00486 00487 /* Finds minimum enclosing circle for a set of points */ 00488 CVAPI(int) cvMinEnclosingCircle( const CvArr* points, 00489 CvPoint2D32f* center, float* radius ); 00490 00491 /* Compares two contours by matching their moments */ 00492 CVAPI(double) cvMatchShapes( const void* object1, const void* object2, 00493 int method, double parameter CV_DEFAULT(0)); 00494 00495 /* Calculates exact convex hull of 2d point set */ 00496 CVAPI(CvSeq*) cvConvexHull2( const CvArr* input, 00497 void* hull_storage CV_DEFAULT(NULL), 00498 int orientation CV_DEFAULT(CV_CLOCKWISE), 00499 int return_points CV_DEFAULT(0)); 00500 00501 /* Checks whether the contour is convex or not (returns 1 if convex, 0 if not) */ 00502 CVAPI(int) cvCheckContourConvexity( const CvArr* contour ); 00503 00504 00505 /* Finds convexity defects for the contour */ 00506 CVAPI(CvSeq*) cvConvexityDefects( const CvArr* contour, const CvArr* convexhull, 00507 CvMemStorage* storage CV_DEFAULT(NULL)); 00508 00509 /* Fits ellipse into a set of 2d points */ 00510 CVAPI(CvBox2D) cvFitEllipse2( const CvArr* points ); 00511 00512 /* Finds minimum rectangle containing two given rectangles */ 00513 CVAPI(CvRect) cvMaxRect( const CvRect* rect1, const CvRect* rect2 ); 00514 00515 /* Finds coordinates of the box vertices */ 00516 CVAPI(void) cvBoxPoints( CvBox2D box, CvPoint2D32f pt[4] ); 00517 00518 /* Initializes sequence header for a matrix (column or row vector) of points - 00519 a wrapper for cvMakeSeqHeaderForArray (it does not initialize bounding rectangle!!!) */ 00520 CVAPI(CvSeq*) cvPointSeqFromMat( int seq_kind, const CvArr* mat, 00521 CvContour* contour_header, 00522 CvSeqBlock* block ); 00523 00524 /* Checks whether the point is inside polygon, outside, on an edge (at a vertex). 00525 Returns positive, negative or zero value, correspondingly. 00526 Optionally, measures a signed distance between 00527 the point and the nearest polygon edge (measure_dist=1) */ 00528 CVAPI(double) cvPointPolygonTest( const CvArr* contour, 00529 CvPoint2D32f pt, int measure_dist ); 00530 00531 /****************************************************************************************\ 00532 * Histogram functions * 00533 \****************************************************************************************/ 00534 00535 /* Creates new histogram */ 00536 CVAPI(CvHistogram*) cvCreateHist( int dims, int* sizes, int type, 00537 float** ranges CV_DEFAULT(NULL), 00538 int uniform CV_DEFAULT(1)); 00539 00540 /* Assignes histogram bin ranges */ 00541 CVAPI(void) cvSetHistBinRanges( CvHistogram* hist, float** ranges, 00542 int uniform CV_DEFAULT(1)); 00543 00544 /* Creates histogram header for array */ 00545 CVAPI(CvHistogram*) cvMakeHistHeaderForArray( 00546 int dims, int* sizes, CvHistogram* hist, 00547 float* data, float** ranges CV_DEFAULT(NULL), 00548 int uniform CV_DEFAULT(1)); 00549 00550 /* Releases histogram */ 00551 CVAPI(void) cvReleaseHist( CvHistogram** hist ); 00552 00553 /* Clears all the histogram bins */ 00554 CVAPI(void) cvClearHist( CvHistogram* hist ); 00555 00556 /* Finds indices and values of minimum and maximum histogram bins */ 00557 CVAPI(void) cvGetMinMaxHistValue( const CvHistogram* hist, 00558 float* min_value, float* max_value, 00559 int* min_idx CV_DEFAULT(NULL), 00560 int* max_idx CV_DEFAULT(NULL)); 00561 00562 00563 /* Normalizes histogram by dividing all bins by sum of the bins, multiplied by <factor>. 00564 After that sum of histogram bins is equal to <factor> */ 00565 CVAPI(void) cvNormalizeHist( CvHistogram* hist, double factor ); 00566 00567 00568 /* Clear all histogram bins that are below the threshold */ 00569 CVAPI(void) cvThreshHist( CvHistogram* hist, double threshold ); 00570 00571 00572 /* Compares two histogram */ 00573 CVAPI(double) cvCompareHist( const CvHistogram* hist1, 00574 const CvHistogram* hist2, 00575 int method); 00576 00577 /* Copies one histogram to another. Destination histogram is created if 00578 the destination pointer is NULL */ 00579 CVAPI(void) cvCopyHist( const CvHistogram* src, CvHistogram** dst ); 00580 00581 00582 /* Calculates bayesian probabilistic histograms 00583 (each or src and dst is an array of <number> histograms */ 00584 CVAPI(void) cvCalcBayesianProb( CvHistogram** src, int number, 00585 CvHistogram** dst); 00586 00587 /* Calculates array histogram */ 00588 CVAPI(void) cvCalcArrHist( CvArr** arr, CvHistogram* hist, 00589 int accumulate CV_DEFAULT(0), 00590 const CvArr* mask CV_DEFAULT(NULL) ); 00591 00592 CV_INLINE void cvCalcHist( IplImage** image, CvHistogram* hist, 00593 int accumulate CV_DEFAULT(0), 00594 const CvArr* mask CV_DEFAULT(NULL) ) 00595 { 00596 cvCalcArrHist( (CvArr**)image, hist, accumulate, mask ); 00597 } 00598 00599 /* Calculates back project */ 00600 CVAPI(void) cvCalcArrBackProject( CvArr** image, CvArr* dst, 00601 const CvHistogram* hist ); 00602 #define cvCalcBackProject(image, dst, hist) cvCalcArrBackProject((CvArr**)image, dst, hist) 00603 00604 00605 /* Does some sort of template matching but compares histograms of 00606 template and each window location */ 00607 CVAPI(void) cvCalcArrBackProjectPatch( CvArr** image, CvArr* dst, CvSize range, 00608 CvHistogram* hist, int method, 00609 double factor ); 00610 #define cvCalcBackProjectPatch( image, dst, range, hist, method, factor ) \ 00611 cvCalcArrBackProjectPatch( (CvArr**)image, dst, range, hist, method, factor ) 00612 00613 00614 /* calculates probabilistic density (divides one histogram by another) */ 00615 CVAPI(void) cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2, 00616 CvHistogram* dst_hist, double scale CV_DEFAULT(255) ); 00617 00618 /* equalizes histogram of 8-bit single-channel image */ 00619 CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst ); 00620 00621 00622 /* Applies distance transform to binary image */ 00623 CVAPI(void) cvDistTransform( const CvArr* src, CvArr* dst, 00624 int distance_type CV_DEFAULT(CV_DIST_L2), 00625 int mask_size CV_DEFAULT(3), 00626 const float* mask CV_DEFAULT(NULL), 00627 CvArr* labels CV_DEFAULT(NULL)); 00628 00629 00630 /* Applies fixed-level threshold to grayscale image. 00631 This is a basic operation applied before retrieving contours */ 00632 CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst, 00633 double threshold, double max_value, 00634 int threshold_type ); 00635 00636 /* Applies adaptive threshold to grayscale image. 00637 The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and 00638 CV_ADAPTIVE_THRESH_GAUSSIAN_C are: 00639 neighborhood size (3, 5, 7 etc.), 00640 and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) */ 00641 CVAPI(void) cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value, 00642 int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C), 00643 int threshold_type CV_DEFAULT(CV_THRESH_BINARY), 00644 int block_size CV_DEFAULT(3), 00645 double param1 CV_DEFAULT(5)); 00646 00647 /* Fills the connected component until the color difference gets large enough */ 00648 CVAPI(void) cvFloodFill( CvArr* image, CvPoint seed_point, 00649 CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)), 00650 CvScalar up_diff CV_DEFAULT(cvScalarAll(0)), 00651 CvConnectedComp* comp CV_DEFAULT(NULL), 00652 int flags CV_DEFAULT(4), 00653 CvArr* mask CV_DEFAULT(NULL)); 00654 00655 /****************************************************************************************\ 00656 * Feature detection * 00657 \****************************************************************************************/ 00658 00659 /* Runs canny edge detector */ 00660 CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1, 00661 double threshold2, int aperture_size CV_DEFAULT(3) ); 00662 00663 /* Calculates constraint image for corner detection 00664 Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy. 00665 Applying threshold to the result gives coordinates of corners */ 00666 CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners, 00667 int aperture_size CV_DEFAULT(3) ); 00668 00669 /* Calculates eigen values and vectors of 2x2 00670 gradient covariation matrix at every image pixel */ 00671 CVAPI(void) cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv, 00672 int block_size, int aperture_size CV_DEFAULT(3) ); 00673 00674 /* Calculates minimal eigenvalue for 2x2 gradient covariation matrix at 00675 every image pixel */ 00676 CVAPI(void) cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, 00677 int block_size, int aperture_size CV_DEFAULT(3) ); 00678 00679 /* Harris corner detector: 00680 Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel */ 00681 CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_responce, 00682 int block_size, int aperture_size CV_DEFAULT(3), 00683 double k CV_DEFAULT(0.04) ); 00684 00685 /* Adjust corner position using some sort of gradient search */ 00686 CVAPI(void) cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, 00687 int count, CvSize win, CvSize zero_zone, 00688 CvTermCriteria criteria ); 00689 00690 /* Finds a sparse set of points within the selected region 00691 that seem to be easy to track */ 00692 CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, 00693 CvArr* temp_image, CvPoint2D32f* corners, 00694 int* corner_count, double quality_level, 00695 double min_distance, 00696 const CvArr* mask CV_DEFAULT(NULL), 00697 int block_size CV_DEFAULT(3), 00698 int use_harris CV_DEFAULT(0), 00699 double k CV_DEFAULT(0.04) ); 00700 00701 /* Finds lines on binary image using one of several methods. 00702 line_storage is either memory storage or 1 x <max number of lines> CvMat, its 00703 number of columns is changed by the function. 00704 method is one of CV_HOUGH_*; 00705 rho, theta and threshold are used for each of those methods; 00706 param1 ~ line length, param2 ~ line gap - for probabilistic, 00707 param1 ~ srn, param2 ~ stn - for multi-scale */ 00708 CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method, 00709 double rho, double theta, int threshold, 00710 double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0)); 00711 00712 /* Finds circles in the image */ 00713 CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage, 00714 int method, double dp, double min_dist, 00715 double param1 CV_DEFAULT(100), 00716 double param2 CV_DEFAULT(100), 00717 int min_radius CV_DEFAULT(0), 00718 int max_radius CV_DEFAULT(0)); 00719 00720 /* Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) */ 00721 CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param, 00722 double reps, double aeps, float* line ); 00723 00724 00725 /* Constructs kd-tree from set of feature descriptors */ 00726 CVAPI(struct CvFeatureTree*) cvCreateKDTree(CvMat* desc); 00727 00728 /* Constructs spill-tree from set of feature descriptors */ 00729 CVAPI(struct CvFeatureTree*) cvCreateSpillTree( const CvMat* raw_data, 00730 const int naive CV_DEFAULT(50), 00731 const double rho CV_DEFAULT(.7), 00732 const double tau CV_DEFAULT(.1) ); 00733 00734 /* Release feature tree */ 00735 CVAPI(void) cvReleaseFeatureTree(struct CvFeatureTree* tr); 00736 00737 /* Searches feature tree for k nearest neighbors of given reference points, 00738 searching (in case of kd-tree/bbf) at most emax leaves. */ 00739 CVAPI(void) cvFindFeatures(struct CvFeatureTree* tr, const CvMat* query_points, 00740 CvMat* indices, CvMat* dist, int k, int emax CV_DEFAULT(20)); 00741 00742 /* Search feature tree for all points that are inlier to given rect region. 00743 Only implemented for kd trees */ 00744 CVAPI(int) cvFindFeaturesBoxed(struct CvFeatureTree* tr, 00745 CvMat* bounds_min, CvMat* bounds_max, 00746 CvMat* out_indices); 00747 00748 00749 /* Construct a Locality Sensitive Hash (LSH) table, for indexing d-dimensional vectors of 00750 given type. Vectors will be hashed L times with k-dimensional p-stable (p=2) functions. */ 00751 CVAPI(struct CvLSH*) cvCreateLSH(struct CvLSHOperations* ops, int d, 00752 int L CV_DEFAULT(10), int k CV_DEFAULT(10), 00753 int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4), 00754 int64 seed CV_DEFAULT(-1)); 00755 00756 /* Construct in-memory LSH table, with n bins. */ 00757 CVAPI(struct CvLSH*) cvCreateMemoryLSH(int d, int n, int L CV_DEFAULT(10), int k CV_DEFAULT(10), 00758 int type CV_DEFAULT(CV_64FC1), double r CV_DEFAULT(4), 00759 int64 seed CV_DEFAULT(-1)); 00760 00761 /* Free the given LSH structure. */ 00762 CVAPI(void) cvReleaseLSH(struct CvLSH** lsh); 00763 00764 /* Return the number of vectors in the LSH. */ 00765 CVAPI(unsigned int) LSHSize(struct CvLSH* lsh); 00766 00767 /* Add vectors to the LSH structure, optionally returning indices. */ 00768 CVAPI(void) cvLSHAdd(struct CvLSH* lsh, const CvMat* data, CvMat* indices CV_DEFAULT(0)); 00769 00770 /* Remove vectors from LSH, as addressed by given indices. */ 00771 CVAPI(void) cvLSHRemove(struct CvLSH* lsh, const CvMat* indices); 00772 00773 /* Query the LSH n times for at most k nearest points; data is n x d, 00774 indices and dist are n x k. At most emax stored points will be accessed. */ 00775 CVAPI(void) cvLSHQuery(struct CvLSH* lsh, const CvMat* query_points, 00776 CvMat* indices, CvMat* dist, int k, int emax); 00777 00778 00779 #ifdef __cplusplus 00780 } 00781 #endif 00782 00783 #endif