Merge pull request #2887 from ilya-lavrenov:ipp_morph_fix
[platform/upstream/opencv.git] / modules / legacy / include / opencv2 / legacy / compat.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright( C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 //(including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort(including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef __OPENCV_COMPAT_HPP__
43 #define __OPENCV_COMPAT_HPP__
44
45 #include "opencv2/core/core_c.h"
46 #include "opencv2/imgproc/types_c.h"
47
48 #include <math.h>
49 #include <string.h>
50
51 #define CV_NOOP(...)
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 typedef int CvMatType;
58 typedef int CvDisMaskType;
59 typedef CvMat CvMatArray;
60
61 typedef int CvThreshType;
62 typedef int CvAdaptiveThreshMethod;
63 typedef int CvCompareMethod;
64 typedef int CvFontFace;
65 typedef int CvPolyApproxMethod;
66 typedef int CvContoursMatchMethod;
67 typedef int CvContourTreesMatchMethod;
68 typedef int CvCoeffType;
69 typedef int CvRodriguesType;
70 typedef int CvElementShape;
71 typedef int CvMorphOp;
72 typedef int CvTemplMatchMethod;
73
74 typedef CvPoint2D64f CvPoint2D64d;
75 typedef CvPoint3D64f CvPoint3D64d;
76
77 enum
78 {
79     CV_MAT32F      = CV_32FC1,
80     CV_MAT3x1_32F  = CV_32FC1,
81     CV_MAT4x1_32F  = CV_32FC1,
82     CV_MAT3x3_32F  = CV_32FC1,
83     CV_MAT4x4_32F  = CV_32FC1,
84
85     CV_MAT64D      = CV_64FC1,
86     CV_MAT3x1_64D  = CV_64FC1,
87     CV_MAT4x1_64D  = CV_64FC1,
88     CV_MAT3x3_64D  = CV_64FC1,
89     CV_MAT4x4_64D  = CV_64FC1
90 };
91
92 enum
93 {
94     IPL_GAUSSIAN_5x5 = 7
95 };
96
97 typedef CvBox2D  CvBox2D32f;
98
99 /* allocation/deallocation macros */
100 #define cvCreateImageData   cvCreateData
101 #define cvReleaseImageData  cvReleaseData
102 #define cvSetImageData      cvSetData
103 #define cvGetImageRawData   cvGetRawData
104
105 #define cvmAlloc            cvCreateData
106 #define cvmFree             cvReleaseData
107 #define cvmAllocArray       cvCreateData
108 #define cvmFreeArray        cvReleaseData
109
110 #define cvIntegralImage     cvIntegral
111 #define cvMatchContours     cvMatchShapes
112
113 CV_EXPORTS CvMat cvMatArray( int rows, int cols, int type,
114                             int count, void* data CV_DEFAULT(0));
115
116 #define cvUpdateMHIByTime  cvUpdateMotionHistory
117
118 #define cvAccMask cvAcc
119 #define cvSquareAccMask cvSquareAcc
120 #define cvMultiplyAccMask cvMultiplyAcc
121 #define cvRunningAvgMask(imgY, imgU, mask, alpha) cvRunningAvg(imgY, imgU, alpha, mask)
122
123 #define cvSetHistThresh  cvSetHistBinRanges
124 #define cvCalcHistMask(img, mask, hist, doNotClear) cvCalcHist(img, hist, doNotClear, mask)
125
126 CV_EXPORTS double cvMean( const CvArr* image, const CvArr* mask CV_DEFAULT(0));
127 CV_EXPORTS double cvSumPixels( const CvArr* image );
128 CV_EXPORTS void  cvMean_StdDev( const CvArr* image, double* mean, double* sdv,
129                                 const CvArr* mask CV_DEFAULT(0));
130
131 CV_EXPORTS void cvmPerspectiveProject( const CvMat* mat, const CvArr* src, CvArr* dst );
132 CV_EXPORTS void cvFillImage( CvArr* mat, double color );
133
134 #define cvCvtPixToPlane cvSplit
135 #define cvCvtPlaneToPix cvMerge
136
137 typedef struct CvRandState
138 {
139     CvRNG     state;    /* RNG state (the current seed and carry)*/
140     int       disttype; /* distribution type */
141     CvScalar  param[2]; /* parameters of RNG */
142 } CvRandState;
143
144 /* Changes RNG range while preserving RNG state */
145 CV_EXPORTS void  cvRandSetRange( CvRandState* state, double param1,
146                                  double param2, int index CV_DEFAULT(-1));
147
148 CV_EXPORTS void  cvRandInit( CvRandState* state, double param1,
149                              double param2, int seed,
150                              int disttype CV_DEFAULT(CV_RAND_UNI));
151
152 /* Fills array with random numbers */
153 CV_EXPORTS void cvRand( CvRandState* state, CvArr* arr );
154
155 #define cvRandNext( _state ) cvRandInt( &(_state)->state )
156
157 CV_EXPORTS void cvbRand( CvRandState* state, float* dst, int len );
158
159 CV_EXPORTS void  cvbCartToPolar( const float* y, const float* x,
160                                  float* magnitude, float* angle, int len );
161 CV_EXPORTS void  cvbFastArctan( const float* y, const float* x, float* angle, int len );
162 CV_EXPORTS void  cvbSqrt( const float* x, float* y, int len );
163 CV_EXPORTS void  cvbInvSqrt( const float* x, float* y, int len );
164 CV_EXPORTS void  cvbReciprocal( const float* x, float* y, int len );
165 CV_EXPORTS void  cvbFastExp( const float* x, double* y, int len );
166 CV_EXPORTS void  cvbFastLog( const double* x, float* y, int len );
167
168 CV_EXPORTS CvRect  cvContourBoundingRect( void* point_set, int update CV_DEFAULT(0));
169
170 CV_EXPORTS double cvPseudoInverse( const CvArr* src, CvArr* dst );
171 #define cvPseudoInv cvPseudoInverse
172
173 #define cvContourMoments( contour, moments ) cvMoments( contour, moments, 0 )
174
175 #define cvGetPtrAt              cvPtr2D
176 #define cvGetAt                 cvGet2D
177 #define cvSetAt(arr,val,y,x)    cvSet2D((arr),(y),(x),(val))
178
179 #define cvMeanMask  cvMean
180 #define cvMean_StdDevMask(img,mask,mean,sdv) cvMean_StdDev(img,mean,sdv,mask)
181
182 #define cvNormMask(imgA,imgB,mask,normType) cvNorm(imgA,imgB,normType,mask)
183
184 #define cvMinMaxLocMask(img, mask, min_val, max_val, min_loc, max_loc) \
185         cvMinMaxLoc(img, min_val, max_val, min_loc, max_loc, mask)
186
187 #define cvRemoveMemoryManager  CV_NOOP
188 #define cvSetMemoryManager     CV_NOOP
189
190 #define cvmSetZero( mat )               cvSetZero( mat )
191 #define cvmSetIdentity( mat )           cvSetIdentity( mat )
192 #define cvmAdd( src1, src2, dst )       cvAdd( src1, src2, dst, 0 )
193 #define cvmSub( src1, src2, dst )       cvSub( src1, src2, dst, 0 )
194 #define cvmCopy( src, dst )             cvCopy( src, dst, 0 )
195 #define cvmMul( src1, src2, dst )       cvMatMulAdd( src1, src2, 0, dst )
196 #define cvmTranspose( src, dst )        cvT( src, dst )
197 #define cvmInvert( src, dst )           cvInv( src, dst )
198 #define cvmMahalanobis(vec1, vec2, mat) cvMahalanobis( vec1, vec2, mat )
199 #define cvmDotProduct( vec1, vec2 )     cvDotProduct( vec1, vec2 )
200 #define cvmCrossProduct(vec1, vec2,dst) cvCrossProduct( vec1, vec2, dst )
201 #define cvmTrace( mat )                 (cvTrace( mat )).val[0]
202 #define cvmMulTransposed( src, dst, order ) cvMulTransposed( src, dst, order )
203 #define cvmEigenVV( mat, evec, eval, eps)   cvEigenVV( mat, evec, eval, eps )
204 #define cvmDet( mat )                   cvDet( mat )
205 #define cvmScale( src, dst, scale )     cvScale( src, dst, scale )
206
207 #define cvCopyImage( src, dst )         cvCopy( src, dst, 0 )
208 #define cvReleaseMatHeader              cvReleaseMat
209
210 /* Calculates exact convex hull of 2d point set */
211 CV_EXPORTS void cvConvexHull( CvPoint* points, int num_points,
212                              CvRect* bound_rect,
213                              int orientation, int* hull, int* hullsize );
214
215
216 CV_EXPORTS void cvMinAreaRect( CvPoint* points, int n,
217                               int left, int bottom,
218                               int right, int top,
219                               CvPoint2D32f* anchor,
220                               CvPoint2D32f* vect1,
221                               CvPoint2D32f* vect2 );
222
223 typedef int CvDisType;
224 typedef int CvChainApproxMethod;
225 typedef int CvContourRetrievalMode;
226
227 CV_EXPORTS  void  cvFitLine3D( CvPoint3D32f* points, int count, int dist,
228                     void *param, float reps, float aeps, float* line );
229
230 /* Fits a line into set of 2d points in a robust way (M-estimator technique) */
231 CV_EXPORTS  void  cvFitLine2D( CvPoint2D32f* points, int count, int dist,
232                     void *param, float reps, float aeps, float* line );
233
234 CV_EXPORTS  void  cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* box );
235
236 /* Projects 2d points to one of standard coordinate planes
237    (i.e. removes one of coordinates) */
238 CV_EXPORTS  void  cvProject3D( CvPoint3D32f* points3D, int count,
239                               CvPoint2D32f* points2D,
240                               int xIndx CV_DEFAULT(0),
241                               int yIndx CV_DEFAULT(1));
242
243 /* Retrieves value of the particular bin
244    of x-dimensional (x=1,2,3,...) histogram */
245 #define cvQueryHistValue_1D( hist, idx0 ) \
246     ((float)cvGetReal1D( (hist)->bins, (idx0)))
247 #define cvQueryHistValue_2D( hist, idx0, idx1 ) \
248     ((float)cvGetReal2D( (hist)->bins, (idx0), (idx1)))
249 #define cvQueryHistValue_3D( hist, idx0, idx1, idx2 ) \
250     ((float)cvGetReal3D( (hist)->bins, (idx0), (idx1), (idx2)))
251 #define cvQueryHistValue_nD( hist, idx ) \
252     ((float)cvGetRealND( (hist)->bins, (idx)))
253
254 /* Returns pointer to the particular bin of x-dimesional histogram.
255    For sparse histogram the bin is created if it didn't exist before */
256 #define cvGetHistValue_1D( hist, idx0 ) \
257     ((float*)cvPtr1D( (hist)->bins, (idx0), 0))
258 #define cvGetHistValue_2D( hist, idx0, idx1 ) \
259     ((float*)cvPtr2D( (hist)->bins, (idx0), (idx1), 0))
260 #define cvGetHistValue_3D( hist, idx0, idx1, idx2 ) \
261     ((float*)cvPtr3D( (hist)->bins, (idx0), (idx1), (idx2), 0))
262 #define cvGetHistValue_nD( hist, idx ) \
263     ((float*)cvPtrND( (hist)->bins, (idx), 0))
264
265
266 #define CV_IS_SET_ELEM_EXISTS CV_IS_SET_ELEM
267
268
269 CV_EXPORTS  int  cvHoughLines( CvArr* image, double rho,
270                               double theta, int threshold,
271                               float* lines, int linesNumber );
272
273 CV_EXPORTS  int  cvHoughLinesP( CvArr* image, double rho,
274                                double theta, int threshold,
275                                int lineLength, int lineGap,
276                                int* lines, int linesNumber );
277
278
279 CV_EXPORTS  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,
280                                   double theta, int stn, int threshold,
281                                   float* lines, int linesNumber );
282
283 CV_EXPORTS  float  cvCalcEMD( const float* signature1, int size1,
284                              const float* signature2, int size2,
285                              int dims, int dist_type CV_DEFAULT(CV_DIST_L2),
286                              CvDistanceFunction dist_func CV_DEFAULT(0),
287                              float* lower_bound CV_DEFAULT(0),
288                              void* user_param CV_DEFAULT(0));
289
290 CV_EXPORTS  void  cvKMeans( int num_clusters, float** samples,
291                            int num_samples, int vec_size,
292                            CvTermCriteria termcrit, int* cluster_idx );
293
294 CV_EXPORTS void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
295                                   CvGraphVtx* vtx CV_DEFAULT(NULL),
296                                   int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS));
297
298 CV_EXPORTS  void  cvEndScanGraph( CvGraphScanner* scanner );
299
300
301 /* old drawing functions */
302 CV_EXPORTS void  cvLineAA( CvArr* img, CvPoint pt1, CvPoint pt2,
303                             double color, int scale CV_DEFAULT(0));
304
305 CV_EXPORTS void  cvCircleAA( CvArr* img, CvPoint center, int radius,
306                             double color, int scale CV_DEFAULT(0) );
307
308 CV_EXPORTS void  cvEllipseAA( CvArr* img, CvPoint center, CvSize axes,
309                               double angle, double start_angle,
310                               double end_angle, double color,
311                               int scale CV_DEFAULT(0) );
312
313 CV_EXPORTS void  cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
314                               int is_closed, double color, int scale CV_DEFAULT(0) );
315
316 /****************************************************************************************\
317 *                                   Pixel Access Macros                                  *
318 \****************************************************************************************/
319
320 typedef struct _CvPixelPosition8u
321 {
322     uchar*  currline;      /* pointer to the start of the current pixel line   */
323     uchar*  topline;       /* pointer to the start of the top pixel line       */
324     uchar*  bottomline;    /* pointer to the start of the first line           */
325                                     /* which is below the image                         */
326     int     x;                      /* current x coordinate ( in pixels )               */
327     int     width;                  /* width of the image  ( in pixels )                */
328     int     height;                 /* height of the image  ( in pixels )               */
329     int     step;                   /* distance between lines ( in elements of single   */
330                                     /* plane )                                          */
331     int     step_arr[3];            /* array: ( 0, -step, step ). It is used for        */
332                                     /* vertical moving                                  */
333 } CvPixelPosition8u;
334
335 /* this structure differs from the above only in data type */
336 typedef struct _CvPixelPosition8s
337 {
338     schar*  currline;
339     schar*  topline;
340     schar*  bottomline;
341     int     x;
342     int     width;
343     int     height;
344     int     step;
345     int     step_arr[3];
346 } CvPixelPosition8s;
347
348 /* this structure differs from the CvPixelPosition8u only in data type */
349 typedef struct _CvPixelPosition32f
350 {
351     float*  currline;
352     float*  topline;
353     float*  bottomline;
354     int     x;
355     int     width;
356     int     height;
357     int     step;
358     int     step_arr[3];
359 } CvPixelPosition32f;
360
361
362 /* Initialize one of the CvPixelPosition structures.   */
363 /*  pos    - initialized structure                     */
364 /*  origin - pointer to the left-top corner of the ROI */
365 /*  step   - width of the whole image in bytes         */
366 /*  roi    - width & height of the ROI                 */
367 /*  x, y   - initial position                          */
368 #define CV_INIT_PIXEL_POS(pos, origin, _step, roi, _x, _y, orientation)    \
369     (                                                                        \
370     (pos).step = (_step)/sizeof((pos).currline[0]) * (orientation ? -1 : 1), \
371     (pos).width = (roi).width,                                               \
372     (pos).height = (roi).height,                                             \
373     (pos).bottomline = (origin) + (pos).step*(pos).height,                   \
374     (pos).topline = (origin) - (pos).step,                                   \
375     (pos).step_arr[0] = 0,                                                   \
376     (pos).step_arr[1] = -(pos).step,                                         \
377     (pos).step_arr[2] = (pos).step,                                          \
378     (pos).x = (_x),                                                          \
379     (pos).currline = (origin) + (pos).step*(_y) )
380
381
382 /* Move to specified point ( absolute shift ) */
383 /*  pos    - position structure               */
384 /*  x, y   - coordinates of the new position  */
385 /*  cs     - number of the image channels     */
386 #define CV_MOVE_TO( pos, _x, _y, cs )                                                   \
387 ((pos).currline = (_y) >= 0 && (_y) < (pos).height ? (pos).topline + ((_y)+1)*(pos).step : 0, \
388  (pos).x = (_x) >= 0 && (_x) < (pos).width ? (_x) : 0, (pos).currline + (_x) * (cs) )
389
390 /* Get current coordinates                    */
391 /*  pos    - position structure               */
392 /*  x, y   - coordinates of the new position  */
393 /*  cs     - number of the image channels     */
394 #define CV_GET_CURRENT( pos, cs )  ((pos).currline + (pos).x * (cs))
395
396 /* Move by one pixel relatively to current position */
397 /*  pos    - position structure                     */
398 /*  cs     - number of the image channels           */
399
400 /* left */
401 #define CV_MOVE_LEFT( pos, cs ) \
402  ( --(pos).x >= 0 ? (pos).currline + (pos).x*(cs) : 0 )
403
404 /* right */
405 #define CV_MOVE_RIGHT( pos, cs ) \
406  ( ++(pos).x < (pos).width ? (pos).currline + (pos).x*(cs) : 0 )
407
408 /* up */
409 #define CV_MOVE_UP( pos, cs ) \
410  (((pos).currline -= (pos).step) != (pos).topline ? (pos).currline + (pos).x*(cs) : 0 )
411
412 /* down */
413 #define CV_MOVE_DOWN( pos, cs ) \
414  (((pos).currline += (pos).step) != (pos).bottomline ? (pos).currline + (pos).x*(cs) : 0 )
415
416 /* left up */
417 #define CV_MOVE_LU( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_UP(pos, cs))
418
419 /* right up */
420 #define CV_MOVE_RU( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_UP(pos, cs))
421
422 /* left down */
423 #define CV_MOVE_LD( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_DOWN(pos, cs))
424
425 /* right down */
426 #define CV_MOVE_RD( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_DOWN(pos, cs))
427
428
429
430 /* Move by one pixel relatively to current position with wrapping when the position     */
431 /* achieves image boundary                                                              */
432 /*  pos    - position structure                                                         */
433 /*  cs     - number of the image channels                                               */
434
435 /* left */
436 #define CV_MOVE_LEFT_WRAP( pos, cs ) \
437  ((pos).currline + ( --(pos).x >= 0 ? (pos).x : ((pos).x = (pos).width-1))*(cs))
438
439 /* right */
440 #define CV_MOVE_RIGHT_WRAP( pos, cs ) \
441  ((pos).currline + ( ++(pos).x < (pos).width ? (pos).x : ((pos).x = 0))*(cs) )
442
443 /* up */
444 #define CV_MOVE_UP_WRAP( pos, cs ) \
445     ((((pos).currline -= (pos).step) != (pos).topline ? \
446     (pos).currline : ((pos).currline = (pos).bottomline - (pos).step)) + (pos).x*(cs) )
447
448 /* down */
449 #define CV_MOVE_DOWN_WRAP( pos, cs ) \
450     ((((pos).currline += (pos).step) != (pos).bottomline ? \
451     (pos).currline : ((pos).currline = (pos).topline + (pos).step)) + (pos).x*(cs) )
452
453 /* left up */
454 #define CV_MOVE_LU_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
455 /* right up */
456 #define CV_MOVE_RU_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
457 /* left down */
458 #define CV_MOVE_LD_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
459 /* right down */
460 #define CV_MOVE_RD_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
461
462 /* Numeric constants which used for moving in arbitrary direction  */
463 enum
464 {
465     CV_SHIFT_NONE = 2,
466     CV_SHIFT_LEFT = 1,
467     CV_SHIFT_RIGHT = 3,
468     CV_SHIFT_UP = 6,
469     CV_SHIFT_DOWN = 10,
470     CV_SHIFT_LU = 5,
471     CV_SHIFT_RU = 7,
472     CV_SHIFT_LD = 9,
473     CV_SHIFT_RD = 11
474 };
475
476 /* Move by one pixel in specified direction                                     */
477 /*  pos    - position structure                                                 */
478 /*  shift  - direction ( it's value must be one of the CV_SHIFT_Ö constants ) */
479 /*  cs     - number of the image channels                                       */
480 #define CV_MOVE_PARAM( pos, shift, cs )                                             \
481     ( (pos).currline += (pos).step_arr[(shift)>>2], (pos).x += ((shift)&3)-2,       \
482     ((pos).currline != (pos).topline && (pos).currline != (pos).bottomline &&       \
483     (pos).x >= 0 && (pos).x < (pos).width) ? (pos).currline + (pos).x*(cs) : 0 )
484
485 /* Move by one pixel in specified direction with wrapping when the               */
486 /* position achieves image boundary                                              */
487 /*  pos    - position structure                                                  */
488 /*  shift  - direction ( it's value must be one of the CV_SHIFT_Ö constants )  */
489 /*  cs     - number of the image channels                                        */
490 #define CV_MOVE_PARAM_WRAP( pos, shift, cs )                                        \
491     ( (pos).currline += (pos).step_arr[(shift)>>2],                                 \
492     (pos).currline = ((pos).currline == (pos).topline ?                             \
493     (pos).bottomline - (pos).step :                                                 \
494     (pos).currline == (pos).bottomline ?                                            \
495     (pos).topline + (pos).step : (pos).currline),                                   \
496                                                                                     \
497     (pos).x += ((shift)&3)-2,                                                       \
498     (pos).x = ((pos).x < 0 ? (pos).width-1 : (pos).x >= (pos).width ? 0 : (pos).x), \
499                                                                                     \
500     (pos).currline + (pos).x*(cs) )
501
502
503 typedef float*   CvVect32f;
504 typedef float*   CvMatr32f;
505 typedef double*  CvVect64d;
506 typedef double*  CvMatr64d;
507
508 CV_EXPORTS void cvUnDistortOnce( const CvArr* src, CvArr* dst,
509                                 const float* intrinsic_matrix,
510                                 const float* distortion_coeffs,
511                                 int interpolate );
512
513 /* the two functions below have quite hackerish implementations, use with care
514    (or, which is better, switch to cvUndistortInitMap and cvRemap instead */
515 CV_EXPORTS void cvUnDistortInit( const CvArr* src,
516                                 CvArr* undistortion_map,
517                                 const float* A, const float* k,
518                                 int interpolate );
519
520 CV_EXPORTS void  cvUnDistort( const CvArr* src, CvArr* dst,
521                              const CvArr* undistortion_map,
522                              int interpolate );
523
524 /* Find fundamental matrix */
525 CV_EXPORTS void  cvFindFundamentalMatrix( int* points1, int* points2,
526     int numpoints, int method, float* matrix );
527
528
529 CV_EXPORTS int cvFindChessBoardCornerGuesses( const void* arr, void* thresharr,
530                                CvMemStorage* storage,
531                                CvSize pattern_size, CvPoint2D32f * corners,
532                                int *corner_count );
533
534 /* Calibrates camera using multiple views of calibration pattern */
535 CV_EXPORTS void cvCalibrateCamera( int image_count, int* _point_counts,
536     CvSize image_size, CvPoint2D32f* _image_points, CvPoint3D32f* _object_points,
537     float* _distortion_coeffs, float* _camera_matrix, float* _translation_vectors,
538     float* _rotation_matrices, int flags );
539
540
541 CV_EXPORTS void cvCalibrateCamera_64d( int image_count, int* _point_counts,
542     CvSize image_size, CvPoint2D64f* _image_points, CvPoint3D64f* _object_points,
543     double* _distortion_coeffs, double* _camera_matrix, double* _translation_vectors,
544     double* _rotation_matrices, int flags );
545
546
547 /* Find 3d position of object given intrinsic camera parameters,
548    3d model of the object and projection of the object into view plane */
549 CV_EXPORTS void cvFindExtrinsicCameraParams( int point_count,
550     CvSize image_size, CvPoint2D32f* _image_points,
551     CvPoint3D32f* _object_points, float* focal_length,
552     CvPoint2D32f principal_point, float* _distortion_coeffs,
553     float* _rotation_vector, float* _translation_vector );
554
555 /* Variant of the previous function that takes double-precision parameters */
556 CV_EXPORTS void cvFindExtrinsicCameraParams_64d( int point_count,
557     CvSize image_size, CvPoint2D64f* _image_points,
558     CvPoint3D64f* _object_points, double* focal_length,
559     CvPoint2D64f principal_point, double* _distortion_coeffs,
560     double* _rotation_vector, double* _translation_vector );
561
562 /* Rodrigues transform */
563 enum
564 {
565     CV_RODRIGUES_M2V = 0,
566     CV_RODRIGUES_V2M = 1
567 };
568
569 /* Converts rotation_matrix matrix to rotation_matrix vector or vice versa */
570 CV_EXPORTS void  cvRodrigues( CvMat* rotation_matrix, CvMat* rotation_vector,
571                               CvMat* jacobian, int conv_type );
572
573 /* Does reprojection of 3d object points to the view plane */
574 CV_EXPORTS void  cvProjectPoints( int point_count, CvPoint3D64f* _object_points,
575     double* _rotation_vector, double*  _translation_vector,
576     double* focal_length, CvPoint2D64f principal_point,
577     double* _distortion, CvPoint2D64f* _image_points,
578     double* _deriv_points_rotation_matrix,
579     double* _deriv_points_translation_vect,
580     double* _deriv_points_focal,
581     double* _deriv_points_principal_point,
582     double* _deriv_points_distortion_coeffs );
583
584
585 /* Simpler version of the previous function */
586 CV_EXPORTS void  cvProjectPointsSimple( int point_count, CvPoint3D64f* _object_points,
587     double* _rotation_matrix, double*  _translation_vector,
588     double* _camera_matrix, double* _distortion, CvPoint2D64f* _image_points );
589
590
591 #define cvMake2DPoints cvConvertPointsHomogeneous
592 #define cvMake3DPoints cvConvertPointsHomogeneous
593
594 #define cvWarpPerspectiveQMatrix cvGetPerspectiveTransform
595
596 #define cvConvertPointsHomogenious cvConvertPointsHomogeneous
597
598
599 //////////////////////////////////// feature extractors: obsolete API //////////////////////////////////
600
601 typedef struct CvSURFPoint
602 {
603     CvPoint2D32f pt;
604
605     int          laplacian;
606     int          size;
607     float        dir;
608     float        hessian;
609
610 } CvSURFPoint;
611
612 CV_INLINE CvSURFPoint cvSURFPoint( CvPoint2D32f pt, int laplacian,
613                                   int size, float dir CV_DEFAULT(0),
614                                   float hessian CV_DEFAULT(0))
615 {
616     CvSURFPoint kp;
617
618     kp.pt        = pt;
619     kp.laplacian = laplacian;
620     kp.size      = size;
621     kp.dir       = dir;
622     kp.hessian   = hessian;
623
624     return kp;
625 }
626
627 typedef struct CvSURFParams
628 {
629     int    extended;
630     int    upright;
631     double hessianThreshold;
632
633     int    nOctaves;
634     int    nOctaveLayers;
635
636 } CvSURFParams;
637
638 CVAPI(CvSURFParams) cvSURFParams( double hessianThreshold, int extended CV_DEFAULT(0) );
639
640 // If useProvidedKeyPts!=0, keypoints are not detected, but descriptors are computed
641 //  at the locations provided in keypoints (a CvSeq of CvSURFPoint).
642 CVAPI(void) cvExtractSURF( const CvArr* img, const CvArr* mask,
643                           CvSeq** keypoints, CvSeq** descriptors,
644                           CvMemStorage* storage, CvSURFParams params,
645                              int useProvidedKeyPts CV_DEFAULT(0)  );
646
647 /*!
648  Maximal Stable Regions Parameters
649  */
650 typedef struct CvMSERParams
651 {
652     //! delta, in the code, it compares (size_{i}-size_{i-delta})/size_{i-delta}
653     int delta;
654     //! prune the area which bigger than maxArea
655     int maxArea;
656     //! prune the area which smaller than minArea
657     int minArea;
658     //! prune the area have simliar size to its children
659     float maxVariation;
660     //! trace back to cut off mser with diversity < min_diversity
661     float minDiversity;
662
663     /////// the next few params for MSER of color image
664
665     //! for color image, the evolution steps
666     int maxEvolution;
667     //! the area threshold to cause re-initialize
668     double areaThreshold;
669     //! ignore too small margin
670     double minMargin;
671     //! the aperture size for edge blur
672     int edgeBlurSize;
673 } CvMSERParams;
674
675 CVAPI(CvMSERParams) cvMSERParams( int delta CV_DEFAULT(5), int min_area CV_DEFAULT(60),
676                                  int max_area CV_DEFAULT(14400), float max_variation CV_DEFAULT(.25f),
677                                  float min_diversity CV_DEFAULT(.2f), int max_evolution CV_DEFAULT(200),
678                                  double area_threshold CV_DEFAULT(1.01),
679                                  double min_margin CV_DEFAULT(.003),
680                                  int edge_blur_size CV_DEFAULT(5) );
681
682 // Extracts the contours of Maximally Stable Extremal Regions
683 CVAPI(void) cvExtractMSER( CvArr* _img, CvArr* _mask, CvSeq** contours, CvMemStorage* storage, CvMSERParams params );
684
685
686 typedef struct CvStarKeypoint
687 {
688     CvPoint pt;
689     int size;
690     float response;
691 } CvStarKeypoint;
692
693 CV_INLINE CvStarKeypoint cvStarKeypoint(CvPoint pt, int size, float response)
694 {
695     CvStarKeypoint kpt;
696     kpt.pt = pt;
697     kpt.size = size;
698     kpt.response = response;
699     return kpt;
700 }
701
702 typedef struct CvStarDetectorParams
703 {
704     int maxSize;
705     int responseThreshold;
706     int lineThresholdProjected;
707     int lineThresholdBinarized;
708     int suppressNonmaxSize;
709 } CvStarDetectorParams;
710
711 CV_INLINE CvStarDetectorParams cvStarDetectorParams(
712                                                     int maxSize CV_DEFAULT(45),
713                                                     int responseThreshold CV_DEFAULT(30),
714                                                     int lineThresholdProjected CV_DEFAULT(10),
715                                                     int lineThresholdBinarized CV_DEFAULT(8),
716                                                     int suppressNonmaxSize CV_DEFAULT(5))
717 {
718     CvStarDetectorParams params;
719     params.maxSize = maxSize;
720     params.responseThreshold = responseThreshold;
721     params.lineThresholdProjected = lineThresholdProjected;
722     params.lineThresholdBinarized = lineThresholdBinarized;
723     params.suppressNonmaxSize = suppressNonmaxSize;
724
725     return params;
726 }
727
728 CVAPI(CvSeq*) cvGetStarKeypoints( const CvArr* img, CvMemStorage* storage,
729                                  CvStarDetectorParams params CV_DEFAULT(cvStarDetectorParams()));
730
731 #ifdef __cplusplus
732 }
733 #endif
734
735 #endif