]> rtime.felk.cvut.cz Git - opencv.git/blob - opencv/include/opencv/cv.hpp
added optional border value to cv::copyMakeBorder (SF #2796671)
[opencv.git] / opencv / include / opencv / cv.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 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #ifndef _CV_HPP_
44 #define _CV_HPP_
45
46 #ifdef __cplusplus
47
48 namespace cv
49 {
50
51 enum { BORDER_REPLICATE=IPL_BORDER_REPLICATE, BORDER_CONSTANT=IPL_BORDER_CONSTANT,
52        BORDER_REFLECT=IPL_BORDER_REFLECT, BORDER_REFLECT_101=IPL_BORDER_REFLECT_101,
53        BORDER_REFLECT101=BORDER_REFLECT_101, BORDER_WRAP=IPL_BORDER_WRAP,
54        BORDER_TRANSPARENT, BORDER_DEFAULT=BORDER_REFLECT_101, BORDER_ISOLATED=16 };
55
56 CV_EXPORTS int borderInterpolate( int p, int len, int borderType );
57
58 class CV_EXPORTS BaseRowFilter
59 {
60 public:
61     BaseRowFilter();
62     virtual ~BaseRowFilter();
63     virtual void operator()(const uchar* src, uchar* dst,
64                             int width, int cn) = 0;
65     int ksize, anchor;
66 };
67
68
69 class CV_EXPORTS BaseColumnFilter
70 {
71 public:
72     BaseColumnFilter();
73     virtual ~BaseColumnFilter();
74     virtual void operator()(const uchar** src, uchar* dst, int dststep,
75                             int dstcount, int width) = 0;
76     virtual void reset();
77     int ksize, anchor;
78 };
79
80
81 class CV_EXPORTS BaseFilter
82 {
83 public:
84     BaseFilter();
85     virtual ~BaseFilter();
86     virtual void operator()(const uchar** src, uchar* dst, int dststep,
87                             int dstcount, int width, int cn) = 0;
88     virtual void reset();
89     Size ksize;
90     Point anchor;
91 };
92
93
94 class CV_EXPORTS FilterEngine
95 {
96 public:
97     FilterEngine();
98     FilterEngine(const Ptr<BaseFilter>& _filter2D,
99                  const Ptr<BaseRowFilter>& _rowFilter,
100                  const Ptr<BaseColumnFilter>& _columnFilter,
101                  int srcType, int dstType, int bufType,
102                  int _rowBorderType=BORDER_REPLICATE,
103                  int _columnBorderType=-1,
104                  const Scalar& _borderValue=Scalar());
105     virtual ~FilterEngine();
106     void init(const Ptr<BaseFilter>& _filter2D,
107               const Ptr<BaseRowFilter>& _rowFilter,
108               const Ptr<BaseColumnFilter>& _columnFilter,
109               int srcType, int dstType, int bufType,
110               int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1,
111               const Scalar& _borderValue=Scalar());
112     virtual int start(Size wholeSize, Rect roi, int maxBufRows=-1);
113     virtual int start(const Mat& src, const Rect& srcRoi=Rect(0,0,-1,-1),
114                       bool isolated=false, int maxBufRows=-1);
115     virtual int proceed(const uchar* src, int srcStep, int srcCount,
116                         uchar* dst, int dstStep);
117     virtual void apply( const Mat& src, Mat& dst,
118                         const Rect& srcRoi=Rect(0,0,-1,-1),
119                         Point dstOfs=Point(0,0),
120                         bool isolated=false);
121     bool isSeparable() const { return (const BaseFilter*)filter2D == 0; }
122     int remainingInputRows() const;
123     int remainingOutputRows() const;
124     
125     int srcType, dstType, bufType;
126     Size ksize;
127     Point anchor;
128     int maxWidth;
129     Size wholeSize;
130     Rect roi;
131     int dx1, dx2;
132     int rowBorderType, columnBorderType;
133     Vector<int> borderTab;
134     int borderElemSize;
135     Vector<uchar> ringBuf;
136     Vector<uchar> srcRow;
137     Vector<uchar> constBorderValue;
138     Vector<uchar> constBorderRow;
139     int bufStep, startY, startY0, endY, rowCount, dstY;
140     Vector<uchar*> rows;
141     
142     Ptr<BaseFilter> filter2D;
143     Ptr<BaseRowFilter> rowFilter;
144     Ptr<BaseColumnFilter> columnFilter;
145 };
146
147 enum { KERNEL_GENERAL=0, KERNEL_SYMMETRICAL=1, KERNEL_ASYMMETRICAL=2,
148        KERNEL_SMOOTH=4, KERNEL_INTEGER=8 };
149
150 CV_EXPORTS int getKernelType(const Mat& kernel, Point anchor);
151
152 CV_EXPORTS Ptr<BaseRowFilter> getLinearRowFilter(int srcType, int bufType,
153                                             const Mat& kernel, int anchor,
154                                             int symmetryType);
155
156 CV_EXPORTS Ptr<BaseColumnFilter> getLinearColumnFilter(int bufType, int dstType,
157                                             const Mat& kernel, int anchor,
158                                             int symmetryType, double delta=0,
159                                             int bits=0);
160
161 CV_EXPORTS Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
162                                            const Mat& kernel,
163                                            Point anchor=Point(-1,-1),
164                                            double delta=0, int bits=0);
165
166 CV_EXPORTS Ptr<FilterEngine> createSeparableLinearFilter(int srcType, int dstType,
167                           const Mat& rowKernel, const Mat& columnKernel,
168                           Point _anchor=Point(-1,-1), double delta=0,
169                           int _rowBorderType=BORDER_DEFAULT,
170                           int _columnBorderType=-1,
171                           const Scalar& _borderValue=Scalar());
172
173 CV_EXPORTS Ptr<FilterEngine> createLinearFilter(int srcType, int dstType,
174                  const Mat& kernel, Point _anchor=Point(-1,-1),
175                  double delta=0, int _rowBorderType=BORDER_DEFAULT,
176                  int _columnBorderType=-1, const Scalar& _borderValue=Scalar());
177
178 CV_EXPORTS Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F );
179
180 CV_EXPORTS Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
181                                     double sigma1, double sigma2=0,
182                                     int borderType=BORDER_DEFAULT);
183
184 CV_EXPORTS void getDerivKernels( Mat& kx, Mat& ky, int dx, int dy, int ksize,
185                                  bool normalize=false, int ktype=CV_32F );
186
187 CV_EXPORTS Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,
188                                         int dx, int dy, int ksize,
189                                         int borderType=BORDER_DEFAULT );
190
191 CV_EXPORTS Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,
192                                                  int ksize, int anchor=-1);
193 CV_EXPORTS Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType,
194                                                        int ksize, int anchor=-1,
195                                                        double scale=1);
196 CV_EXPORTS Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
197                                                  Point anchor=Point(-1,-1),
198                                                  bool normalize=true,
199                                                  int borderType=BORDER_DEFAULT);
200
201 enum { MORPH_ERODE=0, MORPH_DILATE=1, MORPH_OPEN=2, MORPH_CLOSE=3,
202        MORPH_GRADIENT=4, MORPH_TOPHAT=5, MORPH_BLACKHAT=6 };
203
204 CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1);
205 CV_EXPORTS Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor=-1);
206 CV_EXPORTS Ptr<BaseFilter> getMorphologyFilter(int op, int type, const Mat& kernel,
207                                                Point anchor=Point(-1,-1));
208
209 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
210
211 CV_EXPORTS Ptr<FilterEngine> createMorphologyFilter(int op, int type, const Mat& kernel,
212                     Point anchor=Point(-1,-1), int _rowBorderType=BORDER_CONSTANT,
213                     int _columnBorderType=-1,
214                     const Scalar& _borderValue=morphologyDefaultBorderValue());
215
216 enum { MORPH_RECT=0, MORPH_CROSS=1, MORPH_ELLIPSE=2 };
217 CV_EXPORTS Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1));
218
219 CV_EXPORTS void copyMakeBorder( const Mat& src, Mat& dst,
220                                 int top, int bottom, int left, int right,
221                                 int borderType, const Scalar& value=Scalar() );
222
223 CV_EXPORTS void medianBlur( const Mat& src, Mat& dst, int ksize );
224 CV_EXPORTS void GaussianBlur( const Mat& src, Mat& dst, Size ksize,
225                               double sigma1, double sigma2=0,
226                               int borderType=BORDER_DEFAULT );
227 CV_EXPORTS void bilateralFilter( const Mat& src, Mat& dst, int d,
228                                  double sigmaColor, double sigmaSpace,
229                                  int borderType=BORDER_DEFAULT );
230 CV_EXPORTS void boxFilter( const Mat& src, Mat& dst, int ddepth,
231                            Size ksize, Point anchor=Point(-1,-1),
232                            bool normalize=true,
233                            int borderType=BORDER_DEFAULT );
234 static inline void blur( const Mat& src, Mat& dst,
235                          Size ksize, Point anchor=Point(-1,-1),
236                          int borderType=BORDER_DEFAULT )
237 {
238     boxFilter( src, dst, -1, ksize, anchor, true, borderType );
239 }
240
241 CV_EXPORTS void filter2D( const Mat& src, Mat& dst, int ddepth,
242                           const Mat& kernel, Point anchor=Point(-1,-1),
243                           double delta=0, int borderType=BORDER_DEFAULT );
244
245 CV_EXPORTS void sepFilter2D( const Mat& src, Mat& dst, int ddepth,
246                              const Mat& kernelX, const Mat& kernelY,
247                              Point anchor=Point(-1,-1),
248                              double delta=0, int borderType=BORDER_DEFAULT );
249
250 CV_EXPORTS void Sobel( const Mat& src, Mat& dst, int ddepth,
251                        int dx, int dy, int ksize=3,
252                        double scale=1, double delta=0,
253                        int borderType=BORDER_DEFAULT );
254
255 CV_EXPORTS void Scharr( const Mat& src, Mat& dst, int ddepth,
256                         int dx, int dy, double scale=1, double delta=0,
257                         int borderType=BORDER_DEFAULT );
258
259 CV_EXPORTS void Laplacian( const Mat& src, Mat& dst, int ddepth,
260                            int ksize=1, double scale=1, double delta=0,
261                            int borderType=BORDER_DEFAULT );
262
263 CV_EXPORTS void Canny( const Mat& image, Mat& edges,
264                        double threshold1, double threshold2,
265                        int apertureSize=3, bool L2gradient=false );
266
267 CV_EXPORTS void cornerMinEigenVal( const Mat& src, Mat& dst,
268                                    int blockSize, int ksize=3,
269                                    int borderType=BORDER_DEFAULT );
270
271 CV_EXPORTS void cornerHarris( const Mat& src, Mat& dst, int blockSize,
272                               int ksize, double k,
273                               int borderType=BORDER_DEFAULT );
274
275 CV_EXPORTS void cornerEigenValsAndVecs( const Mat& src, Mat& dst,
276                                         int blockSize, int ksize,
277                                         int borderType=BORDER_DEFAULT );
278
279 CV_EXPORTS void preCornerDetect( const Mat& src, Mat& dst, int ksize,
280                                  int borderType=BORDER_DEFAULT );
281
282 CV_EXPORTS void cornerSubPix( const Mat& image, Vector<Point2f>& corners,
283                               Size winSize, Size zeroZone,
284                               TermCriteria criteria );
285
286 CV_EXPORTS void goodFeaturesToTrack( const Mat& image, Vector<Point2f>& corners,
287                                      int maxCorners, double qualityLevel, double minDistance,
288                                      const Mat& mask=Mat(), int blockSize=3,
289                                      bool useHarrisDetector=false, double k=0.04 );
290
291 CV_EXPORTS void HoughLines( Mat& image, Vector<Vec2f>& lines,
292                             double rho, double theta, int threshold,
293                             double srn=0, double stn=0 );
294
295 CV_EXPORTS void HoughLinesP( Mat& image, Vector<Vec4i>& lines,
296                              double rho, double theta, int threshold,
297                              double minLineLength=0, double maxLineGap=0 );
298
299 CV_EXPORTS void HoughCircles( Mat& image, Vector<Vec3f>& circles,
300                               int method, double dp, double minDist,
301                               double param1=100, double param2=100,
302                               int minRadius=0, int maxRadius=0 );
303
304 CV_EXPORTS void erode( const Mat& src, Mat& dst, const Mat& kernel,
305                        Point anchor=Point(-1,-1), int iterations=1,
306                        int borderType=BORDER_CONSTANT,
307                        const Scalar& borderValue=morphologyDefaultBorderValue() );
308 CV_EXPORTS void dilate( const Mat& src, Mat& dst, const Mat& kernel,
309                         Point anchor=Point(-1,-1), int iterations=1,
310                         int borderType=BORDER_CONSTANT,
311                         const Scalar& borderValue=morphologyDefaultBorderValue() );
312 CV_EXPORTS void morphologyEx( const Mat& src, Mat& dst, int op, const Mat& kernel,
313                               Point anchor=Point(-1,-1), int iterations=1,
314                               int borderType=BORDER_CONSTANT,
315                               const Scalar& borderValue=morphologyDefaultBorderValue() );
316
317 enum { INTER_NEAREST=0, INTER_LINEAR=1, INTER_CUBIC=2, INTER_AREA=3,
318        INTER_LANCZOS4=4, INTER_MAX=7, WARP_INVERSE_MAP=16 };
319
320 CV_EXPORTS void resize( const Mat& src, Mat& dst,
321                         Size dsize=Size(), double fx=0, double fy=0,
322                         int interpolation=INTER_LINEAR );
323
324 CV_EXPORTS void warpAffine( const Mat& src, Mat& dst,
325                             const Mat& M, Size dsize,
326                             int flags=INTER_LINEAR,
327                             int borderMode=BORDER_CONSTANT,
328                             const Scalar& borderValue=Scalar());
329 CV_EXPORTS void warpPerspective( const Mat& src, Mat& dst,
330                                  const Mat& M, Size dsize,
331                                  int flags=INTER_LINEAR,
332                                  int borderMode=BORDER_CONSTANT,
333                                  const Scalar& borderValue=Scalar());
334
335 CV_EXPORTS void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2,
336                        int interpolation, int borderMode=BORDER_CONSTANT,
337                        const Scalar& borderValue=Scalar());
338
339 CV_EXPORTS void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2,
340                              int dstmap1type, bool nninterpolation=false );
341
342 CV_EXPORTS Mat getRotationMatrix2D( Point2f center, double angle, double scale );
343 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
344 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
345 CV_EXPORTS void invertAffineTransform(const Mat& M, Mat& iM);
346
347 CV_EXPORTS void getRectSubPix( const Mat& image, Size patchSize,
348                                Point2f center, Mat& patch, int patchType=-1 );
349
350 CV_EXPORTS void integral( const Mat& src, Mat& sum, int sdepth=-1 );
351 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, int sdepth=-1 );
352 CV_EXPORTS void integral( const Mat& src, Mat& sum, Mat& sqsum, Mat& tilted, int sdepth=-1 );
353
354 CV_EXPORTS void accumulate( const Mat& src, Mat& dst, const Mat& mask=Mat() );
355 CV_EXPORTS void accumulateSquare( const Mat& src, Mat& dst, const Mat& mask=Mat() );
356 CV_EXPORTS void accumulateProduct( const Mat& src1, const Mat& src2,
357                                    Mat& dst, const Mat& mask=Mat() );
358 CV_EXPORTS void accumulateWeighted( const Mat& src, Mat& dst,
359                                     double alpha, const Mat& mask=Mat() );
360
361 enum { THRESH_BINARY=0, THRESH_BINARY_INV=1, THRESH_TRUNC=2, THRESH_TOZERO=3,
362        THRESH_TOZERO_INV=4, THRESH_MASK=7, THRESH_OTSU=8 };
363
364 CV_EXPORTS double threshold( const Mat& src, Mat& dst, double thresh, double maxval, int type );
365
366 enum { ADAPTIVE_THRESH_MEAN_C=0, ADAPTIVE_THRESH_GAUSSIAN_C=1 };
367
368 CV_EXPORTS void adaptiveThreshold( const Mat& src, Mat& dst, double maxValue,
369                                    int adaptiveMethod, int thresholdType,
370                                    int blockSize, double C );
371
372 CV_EXPORTS void pyrDown( const Mat& src, Mat& dst, const Size& dstsize=Size());
373 CV_EXPORTS void pyrUp( const Mat& src, Mat& dst, const Size& dstsize=Size());
374 CV_EXPORTS void buildPyramid( const Mat& src, Vector<Mat>& dst, int maxlevel );
375
376
377 CV_EXPORTS void undistort( const Mat& src, Mat& dst, const Mat& cameraMatrix,
378                            const Mat& distCoeffs, const Mat& newCameraMatrix=Mat() );
379 CV_EXPORTS void initUndistortRectifyMap( const Mat& cameraMatrix, const Mat& distCoeffs,
380                            const Mat& R, const Mat& newCameraMatrix,
381                            Size size, int m1type, Mat& map1, Mat& map2 );
382 CV_EXPORTS Mat getDefaultNewCameraMatrix( const Mat& cameraMatrix, Size imgsize=Size(),
383                                           bool centerPrincipalPoint=false );
384
385 enum { OPTFLOW_USE_INITIAL_FLOW=4, OPTFLOW_FARNEBACK_GAUSSIAN=256 };
386
387 CV_EXPORTS void calcOpticalFlowPyrLK( const Mat& prevImg, const Mat& nextImg,
388                            const Vector<Point2f>& prevPts,
389                            Vector<Point2f>& nextPts,
390                            Vector<bool>& status, Vector<float>& err,
391                            Size winSize=Size(15,15), int maxLevel=3,
392                            TermCriteria criteria=TermCriteria(
393                             TermCriteria::COUNT+TermCriteria::EPS,
394                             30, 0.01),
395                            double derivLambda=0.5,
396                            int flags=0 );
397
398 CV_EXPORTS void calcOpticalFlowFarneback( const Mat& prev0, const Mat& next0,
399                                Mat& flow0, double pyr_scale, int levels, int winsize,
400                                int iterations, int poly_n, double poly_sigma, int flags );
401     
402     
403 CV_EXPORTS void calcHist( const Vector<Mat>& images, const Vector<int>& channels,
404                           const Mat& mask, MatND& hist, const Vector<int>& histSize,
405                           const Vector<Vector<float> >& ranges,
406                           bool uniform=true, bool accumulate=false );
407
408 CV_EXPORTS void calcHist( const Vector<Mat>& images, const Vector<int>& channels,
409                           const Mat& mask, SparseMat& hist, const Vector<int>& histSize,
410                           const Vector<Vector<float> >& ranges,
411                           bool uniform=true, bool accumulate=false );
412     
413 CV_EXPORTS void calcBackProject( const Vector<Mat>& images, const Vector<int>& channels,
414                                  const MatND& hist, Mat& backProject,
415                                  const Vector<Vector<float> >& ranges,
416                                  double scale=1, bool uniform=true );
417     
418 CV_EXPORTS void calcBackProject( const Vector<Mat>& images, const Vector<int>& channels,
419                                  const SparseMat& hist, Mat& backProject,
420                                  const Vector<Vector<float> >& ranges,
421                                  double scale=1, bool uniform=true );
422
423 CV_EXPORTS double compareHist( const MatND& H1, const MatND& H2, int method );
424
425 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
426
427 CV_EXPORTS void equalizeHist( const Mat& src, Mat& dst );
428
429 CV_EXPORTS void watershed( const Mat& image, Mat& markers );
430
431 enum { INPAINT_NS=CV_INPAINT_NS, INPAINT_TELEA=CV_INPAINT_TELEA };
432
433 CV_EXPORTS void inpaint( const Mat& src, const Mat& inpaintMask,
434                          Mat& dst, double inpaintRange, int flags );
435
436 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst, Mat& labels,
437                                    int distanceType, int maskSize );
438
439 CV_EXPORTS void distanceTransform( const Mat& src, Mat& dst,
440                                    int distanceType, int maskSize );
441
442 enum { FLOODFILL_FIXED_RANGE = 1 << 16,
443        FLOODFILL_MASK_ONLY = 1 << 17 };
444
445 CV_EXPORTS int floodFill( Mat& image,
446                           Point seedPoint, Scalar newVal, Rect* rect=0,
447                           Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
448                           int flags=4 );
449
450 CV_EXPORTS int floodFill( Mat& image, Mat& mask,
451                           Point seedPoint, Scalar newVal, Rect* rect=0,
452                           Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
453                           int flags=4 );
454
455 CV_EXPORTS void cvtColor( const Mat& src, Mat& dst, int code, int dstCn=0 );
456
457 class CV_EXPORTS Moments
458 {
459 public:
460     Moments();
461     Moments(double m00, double m10, double m01, double m20, double m11,
462             double m02, double m30, double m21, double m12, double m03 );
463     Moments( const CvMoments& moments );
464     operator CvMoments() const;
465     
466     double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; // spatial moments
467     double  mu20, mu11, mu02, mu30, mu21, mu12, mu03; // central moments
468     double  nu20, nu11, nu02, nu30, nu21, nu12, nu03; // central normalized moments
469 };
470
471 CV_EXPORTS Moments moments( const Mat& image, bool binaryImage=false );
472
473 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
474
475 enum { TM_SQDIFF=CV_TM_SQDIFF, TM_SQDIFF_NORMED=CV_TM_SQDIFF_NORMED,
476        TM_CCORR=CV_TM_CCORR, TM_CCORR_NORMED=CV_TM_CCORR_NORMED,
477        TM_CCOEFF=CV_TM_CCOEFF, TM_CCOEFF_NORMED=CV_TM_CCOEFF_NORMED };
478
479 CV_EXPORTS void matchTemplate( const Mat& image, const Mat& templ, Mat& result, int method );
480
481 enum { RETR_EXTERNAL=CV_RETR_EXTERNAL, RETR_LIST=CV_RETR_LIST,
482        RETR_CCOMP=CV_RETR_CCOMP, RETR_TREE=CV_RETR_TREE };
483
484 enum { CHAIN_APPROX_NONE=CV_CHAIN_APPROX_NONE,
485        CHAIN_APPROX_SIMPLE=CV_CHAIN_APPROX_SIMPLE,
486        CHAIN_APPROX_TC89_L1=CV_CHAIN_APPROX_TC89_L1,
487        CHAIN_APPROX_TC89_KCOS=CV_CHAIN_APPROX_TC89_KCOS };
488
489 CV_EXPORTS Vector<Vector<Point> >
490     findContours( const Mat& image, Vector<Vec4i>& hierarchy,
491                   int mode, int method, Point offset=Point());
492
493 CV_EXPORTS Vector<Vector<Point> >
494     findContours( const Mat& image, int mode, int method, Point offset=Point());
495
496 CV_EXPORTS void
497     drawContours( Mat& image, const Vector<Vector<Point> >& contours,
498                   const Scalar& color, int thickness=1,
499                   int lineType=8, const Vector<Vec4i>& hierarchy=Vector<Vec4i>(),
500                   int maxLevel=1, Point offset=Point() );
501
502 CV_EXPORTS void approxPolyDP( const Vector<Point>& curve,
503                               Vector<Point>& approxCurve,
504                               double epsilon, bool closed );
505 CV_EXPORTS void approxPolyDP( const Vector<Point2f>& curve,
506                               Vector<Point2f>& approxCurve,
507                               double epsilon, bool closed );
508
509 CV_EXPORTS double arcLength( const Vector<Point>& curve, bool closed );
510 CV_EXPORTS double arcLength( const Vector<Point2f>& curve, bool closed );
511
512 CV_EXPORTS Rect boundingRect( const Vector<Point>& points );
513 CV_EXPORTS Rect boundingRect( const Vector<Point2f>& points );
514
515 CV_EXPORTS double contourArea( const Vector<Point>& contour );
516 CV_EXPORTS double contourArea( const Vector<Point2f>& contour );
517
518 CV_EXPORTS RotatedRect minAreaRect( const Vector<Point>& points );
519 CV_EXPORTS RotatedRect minAreaRect( const Vector<Point2f>& points );
520
521 CV_EXPORTS void minEnclosingCircle( const Vector<Point>& points,
522                                     Point2f center, float& radius );
523 CV_EXPORTS void minEnclosingCircle( const Vector<Point2f>& points,
524                                     Point2f center, float& radius );
525
526 CV_EXPORTS Moments moments( const Vector<Point>& points );
527 CV_EXPORTS Moments moments( const Vector<Point2f>& points );
528
529 CV_EXPORTS double matchShapes( const Vector<Point2f>& contour1,
530                                const Vector<Point2f>& contour2,
531                                int method, double parameter );
532 CV_EXPORTS double matchShapes( const Vector<Point>& contour1,
533                                const Vector<Point>& contour2,
534                                int method, double parameter );
535
536 CV_EXPORTS void convexHull( const Vector<Point>& points,
537                             Vector<int>& hull, bool clockwise=false );
538 CV_EXPORTS void convexHull( const Vector<Point>& points,
539                             Vector<Point>& hull, bool clockwise=false );
540 CV_EXPORTS void convexHull( const Vector<Point2f>& points,
541                             Vector<int>& hull, bool clockwise=false );
542 CV_EXPORTS void convexHull( const Vector<Point2f>& points,
543                             Vector<Point2f>& hull, bool clockwise=false );
544
545 CV_EXPORTS bool isContourConvex( const Vector<Point>& contour );
546 CV_EXPORTS bool isContourConvex( const Vector<Point2f>& contour );
547
548 CV_EXPORTS RotatedRect fitEllipse( const Vector<Point>& points );
549 CV_EXPORTS RotatedRect fitEllipse( const Vector<Point2f>& points );
550
551 CV_EXPORTS Vec4f fitLine( const Vector<Point> points, int distType,
552                           double param, double reps, double aeps );
553 CV_EXPORTS Vec4f fitLine( const Vector<Point2f> points, int distType,
554                           double param, double reps, double aeps );
555 CV_EXPORTS Vec6f fitLine( const Vector<Point3f> points, int distType,
556                           double param, double reps, double aeps );
557
558 CV_EXPORTS double pointPolygonTest( const Vector<Point>& contour,
559                                     Point2f pt, bool measureDist );
560 CV_EXPORTS double pointPolygonTest( const Vector<Point2f>& contour,
561                                     Point2f pt, bool measureDist );
562
563 CV_EXPORTS Mat estimateRigidTransform( const Vector<Point2f>& A,
564                                        const Vector<Point2f>& B,
565                                        bool fullAffine );
566
567 CV_EXPORTS void updateMotionHistory( const Mat& silhouette, Mat& mhi,
568                                      double timestamp, double duration );
569
570 CV_EXPORTS void calcMotionGradient( const Mat& mhi, Mat& mask,
571                                     Mat& orientation,
572                                     double delta1, double delta2,
573                                     int apertureSize=3 );
574
575 CV_EXPORTS double calcGlobalOrientation( const Mat& orientation, const Mat& mask,
576                                          const Mat& mhi, double timestamp,
577                                          double duration );
578 // TODO: need good API for cvSegmentMotion
579
580 CV_EXPORTS RotatedRect CAMShift( const Mat& probImage, Rect& window,
581                                  TermCriteria criteria );
582
583 CV_EXPORTS int meanShift( const Mat& probImage, Rect& window,
584                           TermCriteria criteria );
585
586 class CV_EXPORTS KalmanFilter
587 {
588 public:
589     KalmanFilter();
590     KalmanFilter(int dynamParams, int measureParams, int controlParams=0);
591     void init(int dynamParams, int measureParams, int controlParams=0);
592
593     const Mat& predict(const Mat& control=Mat());
594     const Mat& correct(const Mat& measurement);
595
596     Mat statePre;           // predicted state (x'(k)):
597                             //    x(k)=A*x(k-1)+B*u(k)
598     Mat statePost;          // corrected state (x(k)):
599                             //    x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
600     Mat transitionMatrix;   // state transition matrix (A)
601     Mat controlMatrix;      // control matrix (B)
602                             //   (it is not used if there is no control)
603     Mat measurementMatrix;  // measurement matrix (H)
604     Mat processNoiseCov;    // process noise covariance matrix (Q)
605     Mat measurementNoiseCov;// measurement noise covariance matrix (R)
606     Mat errorCovPre;        // priori error estimate covariance matrix (P'(k)):
607                             //    P'(k)=A*P(k-1)*At + Q)*/
608     Mat gain;               // Kalman gain matrix (K(k)):
609                             //    K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)
610     Mat errorCovPost;       // posteriori error estimate covariance matrix (P(k)):
611                             //    P(k)=(I-K(k)*H)*P'(k)
612     Mat temp1;              // temporary matrices
613     Mat temp2;
614     Mat temp3;
615     Mat temp4;
616     Mat temp5;
617 };
618
619
620 ///////////////////////////// Object Detection ////////////////////////////
621
622 template<> inline void Ptr<CvHaarClassifierCascade>::delete_obj()
623 { cvReleaseHaarClassifierCascade(&obj); }
624
625 class CV_EXPORTS HaarClassifierCascade
626 {
627 public:
628     enum { DO_CANNY_PRUNING = CV_HAAR_DO_CANNY_PRUNING,
629            SCALE_IMAGE = CV_HAAR_SCALE_IMAGE,
630            FIND_BIGGEST_OBJECT = CV_HAAR_FIND_BIGGEST_OBJECT,
631            DO_ROUGH_SEARCH = CV_HAAR_DO_ROUGH_SEARCH };
632     
633     HaarClassifierCascade();
634     HaarClassifierCascade(const String& filename);
635     bool load(const String& filename);
636
637     void detectMultiScale( const Mat& image,
638                            Vector<Rect>& objects,
639                            double scaleFactor=1.1,
640                            int minNeighbors=3, int flags=0,
641                            Size minSize=Size());
642
643     int runAt(Point pt, int startStage=0, int nstages=0) const;
644
645     void setImages( const Mat& sum, const Mat& sqsum,
646                     const Mat& tiltedSum, double scale );
647     
648     Ptr<CvHaarClassifierCascade> cascade;
649 };
650
651 CV_EXPORTS void undistortPoints( const Vector<Point2f>& src, Vector<Point2f>& dst,
652                                  const Mat& cameraMatrix, const Mat& distCoeffs,
653                                  const Mat& R=Mat(), const Mat& P=Mat());
654
655 CV_EXPORTS Mat Rodrigues(const Mat& src);
656 CV_EXPORTS Mat Rodrigues(const Mat& src, Mat& jacobian);
657
658 enum { LMEDS=4, RANSAC=8 };
659
660 CV_EXPORTS Mat findHomography( const Vector<Point2f>& srcPoints,
661                                const Vector<Point2f>& dstPoints,
662                                Vector<bool>& mask, int method=0,
663                                double ransacReprojThreshold=0 );
664
665 CV_EXPORTS Mat findHomography( const Vector<Point2f>& srcPoints,
666                                const Vector<Point2f>& dstPoints,
667                                int method=0, double ransacReprojThreshold=0 );
668
669 /* Computes RQ decomposition for 3x3 matrices */
670 CV_EXPORTS void RQDecomp3x3( const Mat& M, Mat& R, Mat& Q );
671 CV_EXPORTS Vec3d RQDecomp3x3( const Mat& M, Mat& R, Mat& Q,
672                               Mat& Qx, Mat& Qy, Mat& Qz );
673
674 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
675                                            Mat& rotMatrix, Mat& transVect );
676 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
677                                            Mat& rotMatrix, Mat& transVect,
678                                            Mat& rotMatrixX, Mat& rotMatrixY,
679                                            Mat& rotMatrixZ, Vec3d& eulerAngles );
680
681 CV_EXPORTS void matMulDeriv( const Mat& A, const Mat& B, Mat& dABdA, Mat& dABdB );
682
683 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
684                            const Mat& rvec2, const Mat& tvec2,
685                            Mat& rvec3, Mat& tvec3 );
686
687 CV_EXPORTS void composeRT( const Mat& rvec1, const Mat& tvec1,
688                            const Mat& rvec2, const Mat& tvec2,
689                            Mat& rvec3, Mat& tvec3,
690                            Mat& dr3dr1, Mat& dr3dt1,
691                            Mat& dr3dr2, Mat& dr3dt2,
692                            Mat& dt3dr1, Mat& dt3dt1,
693                            Mat& dt3dr2, Mat& dt3dt2 );
694
695 CV_EXPORTS void projectPoints( const Vector<Point3f>& objectPoints,
696                                const Mat& rvec, const Mat& tvec,
697                                const Mat& cameraMatrix,
698                                const Mat& distCoeffs,
699                                Vector<Point2f>& imagePoints );
700
701 CV_EXPORTS void projectPoints( const Vector<Point3f>& objectPoints,
702                                const Mat& rvec, const Mat& tvec,
703                                const Mat& cameraMatrix,
704                                const Mat& distCoeffs,
705                                Vector<Point2f>& imagePoints,
706                                Mat& dpdrot, Mat& dpdt, Mat& dpdf,
707                                Mat& dpdc, Mat& dpddist,
708                                double aspectRatio=0 );
709
710 CV_EXPORTS void solvePnP( const Vector<Point3f>& objectPoints,
711                           const Vector<Point2f>& imagePoints,
712                           const Mat& cameraMatrix,
713                           const Mat& distCoeffs,
714                           Mat& rvec, Mat& tvec,
715                           bool useExtrinsicGuess=false );
716
717 CV_EXPORTS Mat initCameraMatrix2D( const Vector<Vector<Point3f> >& objectPoints,
718                                    const Vector<Vector<Point2f> >& imagePoints,
719                                    Size imageSize, double aspectRatio=1. );
720
721 enum { CALIB_CB_ADAPTIVE_THRESH = CV_CALIB_CB_ADAPTIVE_THRESH,
722        CALIB_CB_NORMALIZE_IMAGE = CV_CALIB_CB_NORMALIZE_IMAGE,
723        CALIB_CB_FILTER_QUADS = CV_CALIB_CB_FILTER_QUADS };
724
725 CV_EXPORTS bool findChessboardCorners( const Mat& image, Size patternSize,
726                                        Vector<Point2f>& corners,
727                                        int flags=CV_CALIB_CB_ADAPTIVE_THRESH+
728                                             CV_CALIB_CB_NORMALIZE_IMAGE );
729
730 CV_EXPORTS void drawChessboardCorners( Mat& image, Size patternSize,
731                                        const Vector<Point2f>& corners,
732                                        bool patternWasFound );
733
734 enum
735 {
736     CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
737     CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
738     CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
739     CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
740     CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
741     CALIB_FIX_K1 = CV_CALIB_FIX_K1,
742     CALIB_FIX_K2 = CV_CALIB_FIX_K2,
743     CALIB_FIX_K3 = CV_CALIB_FIX_K3,
744     // only for stereo
745     CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
746     CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
747     // for stereo rectification
748     CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
749 };
750
751 CV_EXPORTS void calibrateCamera( const Vector<Vector<Point3f> >& objectPoints,
752                                  const Vector<Vector<Point2f> >& imagePoints,
753                                  Size imageSize,
754                                  Mat& cameraMatrix, Mat& distCoeffs,
755                                  Vector<Mat>& rvecs, Vector<Mat>& tvecs,
756                                  int flags=0 );
757
758 CV_EXPORTS void calibrationMatrixValues( const Mat& cameraMatrix,
759                                 Size imageSize,
760                                 double apertureWidth,
761                                 double apertureHeight,
762                                 double& fovx,
763                                 double& fovy,
764                                 double& focalLength,
765                                 Point2d& principalPoint,
766                                 double& aspectRatio );
767
768 CV_EXPORTS void stereoCalibrate( const Vector<Vector<Point3f> >& objectPoints,
769                                  const Vector<Vector<Point2f> >& imagePoints1,
770                                  const Vector<Vector<Point2f> >& imagePoints2,
771                                  Mat& cameraMatrix1, Mat& distCoeffs1,
772                                  Mat& cameraMatrix2, Mat& distCoeffs2,
773                                  Size imageSize, Mat& R, Mat& T,
774                                  Mat& E, Mat& F,
775                                  TermCriteria criteria = TermCriteria(TermCriteria::COUNT+
776                                     TermCriteria::EPS, 30, 1e-6),
777                                  int flags=CALIB_FIX_INTRINSIC );
778
779 CV_EXPORTS void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
780                                const Mat& cameraMatrix2, const Mat& distCoeffs2,
781                                Size imageSize, const Mat& R, const Mat& T,
782                                Mat& R1, Mat& R2, Mat& P1, Mat& P2, Mat& Q,
783                                int flags=CALIB_ZERO_DISPARITY );
784
785 CV_EXPORTS bool stereoRectifyUncalibrated( const Vector<Point2f>& points1,
786                                            const Vector<Point2f>& points2,
787                                            const Mat& F, Size imgSize,
788                                            Mat& H1, Mat& H2,
789                                            double threshold=5 );
790
791 CV_EXPORTS void convertPointsHomogeneous( const Vector<Point2f>& src,
792                                           Vector<Point3f>& dst );
793 CV_EXPORTS void convertPointsHomogeneous( const Vector<Point3f>& src,
794                                           Vector<Point2f>& dst );
795
796 enum
797
798     FM_7POINT = CV_FM_7POINT,
799     FM_8POINT = CV_FM_8POINT,
800     FM_LMEDS = CV_FM_LMEDS,
801     FM_RANSAC = CV_FM_RANSAC
802 };
803
804 CV_EXPORTS Mat findFundamentalMat( const Vector<Point2f>& points1,
805                                    const Vector<Point2f>& points2,
806                                    Vector<bool>& mask,
807                                    int method=FM_RANSAC,
808                                    double param1=3., double param2=0.99 );
809
810 CV_EXPORTS Mat findFundamentalMat( const Vector<Point2f>& points1,
811                                    const Vector<Point2f>& points2,
812                                    int method=FM_RANSAC,
813                                    double param1=3., double param2=0.99 );
814
815 CV_EXPORTS void computeCorrespondEpilines( const Vector<Point2f>& points1,
816                                            int whichImage, const Mat& F,
817                                            Vector<Vec3f>& lines );
818
819 template<> inline void Ptr<CvStereoBMState>::delete_obj()
820 { cvReleaseStereoBMState(&obj); }
821
822 // Block matching stereo correspondence algorithm
823 class CV_EXPORTS StereoBM
824 {
825     enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
826         BASIC_PRESET=CV_STEREO_BM_BASIC,
827         FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
828         NARROW_PRESET=CV_STEREO_BM_NARROW };
829     
830     StereoBM();
831     StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
832     void init(int preset, int ndisparities=0, int SADWindowSize=21);
833     void operator()( const Mat& left, const Mat& right, Mat& disparity );
834
835     Ptr<CvStereoBMState> state;
836 };
837
838 CV_EXPORTS void reprojectImageTo3D( const Mat& disparity,
839                                     Mat& _3dImage, const Mat& Q,
840                                     bool handleMissingValues=false );
841
842 class CV_EXPORTS Keypoint
843 {
844 public:    
845     Keypoint() : pt(0,0), size(0), angle(-1), response(0), octave(0) {}
846     Keypoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0)
847     : pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave) {}
848     Keypoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0)
849     : pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave) {}
850     
851     Point2f pt;
852     float size;
853     float angle;
854     float response;
855     int octave;
856 };
857
858 CV_EXPORTS void write(FileStorage& fs, const String& name, const Vector<Keypoint>& keypoints);
859 CV_EXPORTS void read(const FileNode& node, Vector<Keypoint>& keypoints);    
860
861 class CV_EXPORTS SURF : public CvSURFParams
862 {
863 public:
864     SURF();
865     SURF(double _hessianThreshold, bool _extended=false);
866
867     int descriptorSize() const;
868     void operator()(const Mat& img, const Mat& mask,
869                     Vector<Keypoint>& keypoints) const;
870     void operator()(const Mat& img, const Mat& mask,
871                     Vector<Keypoint>& keypoints,
872                     Vector<float>& descriptors,
873                     bool useProvidedKeypoints=false) const;
874 };
875
876
877 class CV_EXPORTS MSER : public CvMSERParams
878 {
879 public:
880     MSER();
881     MSER( int _delta, int _min_area, int _max_area,
882           float _max_variation, float _min_diversity,
883           int _max_evolution, double _area_threshold,
884           double _min_margin, int _edge_blur_size );
885     Vector<Vector<Point> > operator()(Mat& image, const Mat& mask) const;
886 };
887
888
889 class CV_EXPORTS StarDetector : CvStarDetectorParams
890 {
891 public:
892     StarDetector();
893     StarDetector(int _maxSize, int _responseThreshold,
894                  int _lineThresholdProjected,
895                  int _lineThresholdBinarized,
896                  int _suppressNonmaxSize);
897
898     void operator()(const Mat& image, Vector<Keypoint>& keypoints) const;
899 };
900     
901 }
902
903 //////////////////////////////////////////////////////////////////////////////////////////
904
905 class CV_EXPORTS CvLevMarq
906 {
907 public:
908     CvLevMarq();
909     CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
910         cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
911         bool completeSymmFlag=false );
912     ~CvLevMarq();
913     void init( int nparams, int nerrs, CvTermCriteria criteria=
914         cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
915         bool completeSymmFlag=false );
916     bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
917     bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
918
919     void clear();
920     void step();
921     enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
922
923     CvMat* mask;
924     CvMat* prevParam;
925     CvMat* param;
926     CvMat* J;
927     CvMat* err;
928     CvMat* JtJ;
929     CvMat* JtJN;
930     CvMat* JtErr;
931     CvMat* JtJV;
932     CvMat* JtJW;
933     double prevErrNorm, errNorm;
934     int lambdaLg10;
935     CvTermCriteria criteria;
936     int state;
937     int iters;
938     bool completeSymmFlag;
939 };
940
941
942 // 2009-01-12, Xavier Delacour <xavier.delacour@gmail.com>
943
944 struct lsh_hash {
945   int h1, h2;
946 };
947
948 struct CvLSHOperations
949 {
950   virtual ~CvLSHOperations() {}
951
952   virtual int vector_add(const void* data) = 0;
953   virtual void vector_remove(int i) = 0;
954   virtual const void* vector_lookup(int i) = 0;
955   virtual void vector_reserve(int n) = 0;
956   virtual unsigned int vector_count() = 0;
957
958   virtual void hash_insert(lsh_hash h, int l, int i) = 0;
959   virtual void hash_remove(lsh_hash h, int l, int i) = 0;
960   virtual int hash_lookup(lsh_hash h, int l, int* ret_i, int ret_i_max) = 0;
961 };
962
963
964 #endif /* __cplusplus */
965
966 #endif /* _CV_HPP_ */
967
968 /* End of file. */