added Generalized Hough implementation
[profile/ivi/opencv.git] / modules / imgproc / include / opencv2 / imgproc / imgproc.hpp
1 /*! \file imgproc.hpp
2  \brief The Image Processing
3  */
4
5 /*M///////////////////////////////////////////////////////////////////////////////////////
6 //
7 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
8 //
9 //  By downloading, copying, installing or using the software you agree to this license.
10 //  If you do not agree to this license, do not download, install,
11 //  copy or use the software.
12 //
13 //
14 //                           License Agreement
15 //                For Open Source Computer Vision Library
16 //
17 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
18 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
19 // Third party copyrights are property of their respective owners.
20 //
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
23 //
24 //   * Redistribution's of source code must retain the above copyright notice,
25 //     this list of conditions and the following disclaimer.
26 //
27 //   * Redistribution's in binary form must reproduce the above copyright notice,
28 //     this list of conditions and the following disclaimer in the documentation
29 //     and/or other materials provided with the distribution.
30 //
31 //   * The name of the copyright holders may not be used to endorse or promote products
32 //     derived from this software without specific prior written permission.
33 //
34 // This software is provided by the copyright holders and contributors "as is" and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
44 //
45 //M*/
46
47 #ifndef __OPENCV_IMGPROC_HPP__
48 #define __OPENCV_IMGPROC_HPP__
49
50 #include "opencv2/core/core.hpp"
51 #include "opencv2/imgproc/types_c.h"
52
53 #ifdef __cplusplus
54
55 /*! \namespace cv
56  Namespace where all the C++ OpenCV functionality resides
57  */
58 namespace cv
59 {
60
61 //! various border interpolation methods
62 enum { BORDER_REPLICATE=IPL_BORDER_REPLICATE, BORDER_CONSTANT=IPL_BORDER_CONSTANT,
63        BORDER_REFLECT=IPL_BORDER_REFLECT, BORDER_WRAP=IPL_BORDER_WRAP,
64        BORDER_REFLECT_101=IPL_BORDER_REFLECT_101, BORDER_REFLECT101=BORDER_REFLECT_101,
65        BORDER_TRANSPARENT=IPL_BORDER_TRANSPARENT,
66        BORDER_DEFAULT=BORDER_REFLECT_101, BORDER_ISOLATED=16 };
67
68 //! 1D interpolation function: returns coordinate of the "donor" pixel for the specified location p.
69 CV_EXPORTS_W int borderInterpolate( int p, int len, int borderType );
70
71 /*!
72  The Base Class for 1D or Row-wise Filters
73
74  This is the base class for linear or non-linear filters that process 1D data.
75  In particular, such filters are used for the "horizontal" filtering parts in separable filters.
76
77  Several functions in OpenCV return Ptr<BaseRowFilter> for the specific types of filters,
78  and those pointers can be used directly or within cv::FilterEngine.
79 */
80 class CV_EXPORTS BaseRowFilter
81 {
82 public:
83     //! the default constructor
84     BaseRowFilter();
85     //! the destructor
86     virtual ~BaseRowFilter();
87     //! the filtering operator. Must be overrided in the derived classes. The horizontal border interpolation is done outside of the class.
88     virtual void operator()(const uchar* src, uchar* dst,
89                             int width, int cn) = 0;
90     int ksize, anchor;
91 };
92
93
94 /*!
95  The Base Class for Column-wise Filters
96
97  This is the base class for linear or non-linear filters that process columns of 2D arrays.
98  Such filters are used for the "vertical" filtering parts in separable filters.
99
100  Several functions in OpenCV return Ptr<BaseColumnFilter> for the specific types of filters,
101  and those pointers can be used directly or within cv::FilterEngine.
102
103  Unlike cv::BaseRowFilter, cv::BaseColumnFilter may have some context information,
104  i.e. box filter keeps the sliding sum of elements. To reset the state BaseColumnFilter::reset()
105  must be called (e.g. the method is called by cv::FilterEngine)
106  */
107 class CV_EXPORTS BaseColumnFilter
108 {
109 public:
110     //! the default constructor
111     BaseColumnFilter();
112     //! the destructor
113     virtual ~BaseColumnFilter();
114     //! the filtering operator. Must be overrided in the derived classes. The vertical border interpolation is done outside of the class.
115     virtual void operator()(const uchar** src, uchar* dst, int dststep,
116                             int dstcount, int width) = 0;
117     //! resets the internal buffers, if any
118     virtual void reset();
119     int ksize, anchor;
120 };
121
122 /*!
123  The Base Class for Non-Separable 2D Filters.
124
125  This is the base class for linear or non-linear 2D filters.
126
127  Several functions in OpenCV return Ptr<BaseFilter> for the specific types of filters,
128  and those pointers can be used directly or within cv::FilterEngine.
129
130  Similar to cv::BaseColumnFilter, the class may have some context information,
131  that should be reset using BaseFilter::reset() method before processing the new array.
132 */
133 class CV_EXPORTS BaseFilter
134 {
135 public:
136     //! the default constructor
137     BaseFilter();
138     //! the destructor
139     virtual ~BaseFilter();
140     //! the filtering operator. The horizontal and the vertical border interpolation is done outside of the class.
141     virtual void operator()(const uchar** src, uchar* dst, int dststep,
142                             int dstcount, int width, int cn) = 0;
143     //! resets the internal buffers, if any
144     virtual void reset();
145     Size ksize;
146     Point anchor;
147 };
148
149 /*!
150  The Main Class for Image Filtering.
151
152  The class can be used to apply an arbitrary filtering operation to an image.
153  It contains all the necessary intermediate buffers, it computes extrapolated values
154  of the "virtual" pixels outside of the image etc.
155  Pointers to the initialized cv::FilterEngine instances
156  are returned by various OpenCV functions, such as cv::createSeparableLinearFilter(),
157  cv::createLinearFilter(), cv::createGaussianFilter(), cv::createDerivFilter(),
158  cv::createBoxFilter() and cv::createMorphologyFilter().
159
160  Using the class you can process large images by parts and build complex pipelines
161  that include filtering as some of the stages. If all you need is to apply some pre-defined
162  filtering operation, you may use cv::filter2D(), cv::erode(), cv::dilate() etc.
163  functions that create FilterEngine internally.
164
165  Here is the example on how to use the class to implement Laplacian operator, which is the sum of
166  second-order derivatives. More complex variant for different types is implemented in cv::Laplacian().
167
168  \code
169  void laplace_f(const Mat& src, Mat& dst)
170  {
171      CV_Assert( src.type() == CV_32F );
172      // make sure the destination array has the proper size and type
173      dst.create(src.size(), src.type());
174
175      // get the derivative and smooth kernels for d2I/dx2.
176      // for d2I/dy2 we could use the same kernels, just swapped
177      Mat kd, ks;
178      getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
179
180      // let's process 10 source rows at once
181      int DELTA = std::min(10, src.rows);
182      Ptr<FilterEngine> Fxx = createSeparableLinearFilter(src.type(),
183      dst.type(), kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
184      Ptr<FilterEngine> Fyy = createSeparableLinearFilter(src.type(),
185      dst.type(), ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
186
187      int y = Fxx->start(src), dsty = 0, dy = 0;
188      Fyy->start(src);
189      const uchar* sptr = src.data + y*src.step;
190
191      // allocate the buffers for the spatial image derivatives;
192      // the buffers need to have more than DELTA rows, because at the
193      // last iteration the output may take max(kd.rows-1,ks.rows-1)
194      // rows more than the input.
195      Mat Ixx( DELTA + kd.rows - 1, src.cols, dst.type() );
196      Mat Iyy( DELTA + kd.rows - 1, src.cols, dst.type() );
197
198      // inside the loop we always pass DELTA rows to the filter
199      // (note that the "proceed" method takes care of possibe overflow, since
200      // it was given the actual image height in the "start" method)
201      // on output we can get:
202      //  * < DELTA rows (the initial buffer accumulation stage)
203      //  * = DELTA rows (settled state in the middle)
204      //  * > DELTA rows (then the input image is over, but we generate
205      //                  "virtual" rows using the border mode and filter them)
206      // this variable number of output rows is dy.
207      // dsty is the current output row.
208      // sptr is the pointer to the first input row in the portion to process
209      for( ; dsty < dst.rows; sptr += DELTA*src.step, dsty += dy )
210      {
211          Fxx->proceed( sptr, (int)src.step, DELTA, Ixx.data, (int)Ixx.step );
212          dy = Fyy->proceed( sptr, (int)src.step, DELTA, d2y.data, (int)Iyy.step );
213          if( dy > 0 )
214          {
215              Mat dstripe = dst.rowRange(dsty, dsty + dy);
216              add(Ixx.rowRange(0, dy), Iyy.rowRange(0, dy), dstripe);
217          }
218      }
219  }
220  \endcode
221 */
222 class CV_EXPORTS FilterEngine
223 {
224 public:
225     //! the default constructor
226     FilterEngine();
227     //! the full constructor. Either _filter2D or both _rowFilter and _columnFilter must be non-empty.
228     FilterEngine(const Ptr<BaseFilter>& _filter2D,
229                  const Ptr<BaseRowFilter>& _rowFilter,
230                  const Ptr<BaseColumnFilter>& _columnFilter,
231                  int srcType, int dstType, int bufType,
232                  int _rowBorderType=BORDER_REPLICATE,
233                  int _columnBorderType=-1,
234                  const Scalar& _borderValue=Scalar());
235     //! the destructor
236     virtual ~FilterEngine();
237     //! reinitializes the engine. The previously assigned filters are released.
238     void init(const Ptr<BaseFilter>& _filter2D,
239               const Ptr<BaseRowFilter>& _rowFilter,
240               const Ptr<BaseColumnFilter>& _columnFilter,
241               int srcType, int dstType, int bufType,
242               int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1,
243               const Scalar& _borderValue=Scalar());
244     //! starts filtering of the specified ROI of an image of size wholeSize.
245     virtual int start(Size wholeSize, Rect roi, int maxBufRows=-1);
246     //! starts filtering of the specified ROI of the specified image.
247     virtual int start(const Mat& src, const Rect& srcRoi=Rect(0,0,-1,-1),
248                       bool isolated=false, int maxBufRows=-1);
249     //! processes the next srcCount rows of the image.
250     virtual int proceed(const uchar* src, int srcStep, int srcCount,
251                         uchar* dst, int dstStep);
252     //! applies filter to the specified ROI of the image. if srcRoi=(0,0,-1,-1), the whole image is filtered.
253     virtual void apply( const Mat& src, Mat& dst,
254                         const Rect& srcRoi=Rect(0,0,-1,-1),
255                         Point dstOfs=Point(0,0),
256                         bool isolated=false);
257     //! returns true if the filter is separable
258     bool isSeparable() const { return (const BaseFilter*)filter2D == 0; }
259     //! returns the number
260     int remainingInputRows() const;
261     int remainingOutputRows() const;
262
263     int srcType, dstType, bufType;
264     Size ksize;
265     Point anchor;
266     int maxWidth;
267     Size wholeSize;
268     Rect roi;
269     int dx1, dx2;
270     int rowBorderType, columnBorderType;
271     vector<int> borderTab;
272     int borderElemSize;
273     vector<uchar> ringBuf;
274     vector<uchar> srcRow;
275     vector<uchar> constBorderValue;
276     vector<uchar> constBorderRow;
277     int bufStep, startY, startY0, endY, rowCount, dstY;
278     vector<uchar*> rows;
279
280     Ptr<BaseFilter> filter2D;
281     Ptr<BaseRowFilter> rowFilter;
282     Ptr<BaseColumnFilter> columnFilter;
283 };
284
285 //! type of the kernel
286 enum { KERNEL_GENERAL=0, KERNEL_SYMMETRICAL=1, KERNEL_ASYMMETRICAL=2,
287        KERNEL_SMOOTH=4, KERNEL_INTEGER=8 };
288
289 //! returns type (one of KERNEL_*) of 1D or 2D kernel specified by its coefficients.
290 CV_EXPORTS int getKernelType(InputArray kernel, Point anchor);
291
292 //! returns the primitive row filter with the specified kernel
293 CV_EXPORTS Ptr<BaseRowFilter> getLinearRowFilter(int srcType, int bufType,
294                                             InputArray kernel, int anchor,
295                                             int symmetryType);
296
297 //! returns the primitive column filter with the specified kernel
298 CV_EXPORTS Ptr<BaseColumnFilter> getLinearColumnFilter(int bufType, int dstType,
299                                             InputArray kernel, int anchor,
300                                             int symmetryType, double delta=0,
301                                             int bits=0);
302
303 //! returns 2D filter with the specified kernel
304 CV_EXPORTS Ptr<BaseFilter> getLinearFilter(int srcType, int dstType,
305                                            InputArray kernel,
306                                            Point anchor=Point(-1,-1),
307                                            double delta=0, int bits=0);
308
309 //! returns the separable linear filter engine
310 CV_EXPORTS Ptr<FilterEngine> createSeparableLinearFilter(int srcType, int dstType,
311                           InputArray rowKernel, InputArray columnKernel,
312                           Point anchor=Point(-1,-1), double delta=0,
313                           int rowBorderType=BORDER_DEFAULT,
314                           int columnBorderType=-1,
315                           const Scalar& borderValue=Scalar());
316
317 //! returns the non-separable linear filter engine
318 CV_EXPORTS Ptr<FilterEngine> createLinearFilter(int srcType, int dstType,
319                  InputArray kernel, Point _anchor=Point(-1,-1),
320                  double delta=0, int rowBorderType=BORDER_DEFAULT,
321                  int columnBorderType=-1, const Scalar& borderValue=Scalar());
322
323 //! returns the Gaussian kernel with the specified parameters
324 CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F );
325
326 //! returns the Gaussian filter engine
327 CV_EXPORTS Ptr<FilterEngine> createGaussianFilter( int type, Size ksize,
328                                     double sigma1, double sigma2=0,
329                                     int borderType=BORDER_DEFAULT);
330 //! initializes kernels of the generalized Sobel operator
331 CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky,
332                                    int dx, int dy, int ksize,
333                                    bool normalize=false, int ktype=CV_32F );
334 //! returns filter engine for the generalized Sobel operator
335 CV_EXPORTS Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,
336                                         int dx, int dy, int ksize,
337                                         int borderType=BORDER_DEFAULT );
338 //! returns horizontal 1D box filter
339 CV_EXPORTS Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,
340                                               int ksize, int anchor=-1);
341 //! returns vertical 1D box filter
342 CV_EXPORTS Ptr<BaseColumnFilter> getColumnSumFilter( int sumType, int dstType,
343                                                      int ksize, int anchor=-1,
344                                                      double scale=1);
345 //! returns box filter engine
346 CV_EXPORTS Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize,
347                                               Point anchor=Point(-1,-1),
348                                               bool normalize=true,
349                                               int borderType=BORDER_DEFAULT);
350
351 //! returns the Gabor kernel with the specified parameters
352 CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd,
353                                  double gamma, double psi=CV_PI*0.5, int ktype=CV_64F );
354
355 //! type of morphological operation
356 enum { MORPH_ERODE=CV_MOP_ERODE, MORPH_DILATE=CV_MOP_DILATE,
357        MORPH_OPEN=CV_MOP_OPEN, MORPH_CLOSE=CV_MOP_CLOSE,
358        MORPH_GRADIENT=CV_MOP_GRADIENT, MORPH_TOPHAT=CV_MOP_TOPHAT,
359        MORPH_BLACKHAT=CV_MOP_BLACKHAT };
360
361 //! returns horizontal 1D morphological filter
362 CV_EXPORTS Ptr<BaseRowFilter> getMorphologyRowFilter(int op, int type, int ksize, int anchor=-1);
363 //! returns vertical 1D morphological filter
364 CV_EXPORTS Ptr<BaseColumnFilter> getMorphologyColumnFilter(int op, int type, int ksize, int anchor=-1);
365 //! returns 2D morphological filter
366 CV_EXPORTS Ptr<BaseFilter> getMorphologyFilter(int op, int type, InputArray kernel,
367                                                Point anchor=Point(-1,-1));
368
369 //! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
370 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
371
372 //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
373 CV_EXPORTS Ptr<FilterEngine> createMorphologyFilter(int op, int type, InputArray kernel,
374                     Point anchor=Point(-1,-1), int rowBorderType=BORDER_CONSTANT,
375                     int columnBorderType=-1,
376                     const Scalar& borderValue=morphologyDefaultBorderValue());
377
378 //! shape of the structuring element
379 enum { MORPH_RECT=0, MORPH_CROSS=1, MORPH_ELLIPSE=2 };
380 //! returns structuring element of the specified shape and size
381 CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1));
382
383 template<> CV_EXPORTS void Ptr<IplConvKernel>::delete_obj();
384
385 //! copies 2D array to a larger destination array with extrapolation of the outer part of src using the specified border mode
386 CV_EXPORTS_W void copyMakeBorder( InputArray src, OutputArray dst,
387                                 int top, int bottom, int left, int right,
388                                 int borderType, const Scalar& value=Scalar() );
389
390 //! smooths the image using median filter.
391 CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize );
392 //! smooths the image using Gaussian filter.
393 CV_EXPORTS_W void GaussianBlur( InputArray src,
394                                                OutputArray dst, Size ksize,
395                                                double sigmaX, double sigmaY=0,
396                                                int borderType=BORDER_DEFAULT );
397 //! smooths the image using bilateral filter
398 CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,
399                                    double sigmaColor, double sigmaSpace,
400                                    int borderType=BORDER_DEFAULT );
401 //! smooths the image using the box filter. Each pixel is processed in O(1) time
402 CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
403                              Size ksize, Point anchor=Point(-1,-1),
404                              bool normalize=true,
405                              int borderType=BORDER_DEFAULT );
406 //! a synonym for normalized box filter
407 CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
408                         Size ksize, Point anchor=Point(-1,-1),
409                         int borderType=BORDER_DEFAULT );
410
411 //! applies non-separable 2D linear filter to the image
412 CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth,
413                             InputArray kernel, Point anchor=Point(-1,-1),
414                             double delta=0, int borderType=BORDER_DEFAULT );
415
416 //! applies separable 2D linear filter to the image
417 CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth,
418                                InputArray kernelX, InputArray kernelY,
419                                Point anchor=Point(-1,-1),
420                                double delta=0, int borderType=BORDER_DEFAULT );
421
422 //! applies generalized Sobel operator to the image
423 CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
424                          int dx, int dy, int ksize=3,
425                          double scale=1, double delta=0,
426                          int borderType=BORDER_DEFAULT );
427
428 //! applies the vertical or horizontal Scharr operator to the image
429 CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth,
430                           int dx, int dy, double scale=1, double delta=0,
431                           int borderType=BORDER_DEFAULT );
432
433 //! applies Laplacian operator to the image
434 CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
435                              int ksize=1, double scale=1, double delta=0,
436                              int borderType=BORDER_DEFAULT );
437
438 //! applies Canny edge detector and produces the edge map.
439 CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
440                          double threshold1, double threshold2,
441                          int apertureSize=3, bool L2gradient=false );
442
443 //! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria
444 CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst,
445                                    int blockSize, int ksize=3,
446                                    int borderType=BORDER_DEFAULT );
447
448 //! computes Harris cornerness criteria at each image pixel
449 CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,
450                                 int ksize, double k,
451                                 int borderType=BORDER_DEFAULT );
452
453 // low-level function for computing eigenvalues and eigenvectors of 2x2 matrices
454 CV_EXPORTS void eigen2x2( const float* a, float* e, int n );
455
456 //! computes both eigenvalues and the eigenvectors of 2x2 derivative covariation matrix  at each pixel. The output is stored as 6-channel matrix.
457 CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst,
458                                           int blockSize, int ksize,
459                                           int borderType=BORDER_DEFAULT );
460
461 //! computes another complex cornerness criteria at each pixel
462 CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize,
463                                    int borderType=BORDER_DEFAULT );
464
465 //! adjusts the corner locations with sub-pixel accuracy to maximize the certain cornerness criteria
466 CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners,
467                                 Size winSize, Size zeroZone,
468                                 TermCriteria criteria );
469
470 //! finds the strong enough corners where the cornerMinEigenVal() or cornerHarris() report the local maxima
471 CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
472                                      int maxCorners, double qualityLevel, double minDistance,
473                                      InputArray mask=noArray(), int blockSize=3,
474                                      bool useHarrisDetector=false, double k=0.04 );
475
476 //! finds lines in the black-n-white image using the standard or pyramid Hough transform
477 CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,
478                               double rho, double theta, int threshold,
479                               double srn=0, double stn=0 );
480
481 //! finds line segments in the black-n-white image using probabalistic Hough transform
482 CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,
483                                double rho, double theta, int threshold,
484                                double minLineLength=0, double maxLineGap=0 );
485
486 //! finds circles in the grayscale image using 2+1 gradient Hough transform
487 CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles,
488                                int method, double dp, double minDist,
489                                double param1=100, double param2=100,
490                                int minRadius=0, int maxRadius=0 );
491
492 enum
493 {
494     GHT_POSITION = 0,
495     GHT_SCALE = 1,
496     GHT_ROTATION = 2
497 };
498
499 //! finds arbitrary template in the grayscale image using Generalized Hough Transform
500 //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.
501 //! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.
502 class CV_EXPORTS GeneralizedHough : public Algorithm
503 {
504 public:
505     static Ptr<GeneralizedHough> create(int method);
506
507     virtual ~GeneralizedHough();
508
509     //! set template to search
510     void setTemplate(InputArray templ, int cannyThreshold = 100, Point templCenter = Point(-1, -1));
511     void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1));
512
513     //! find template on image
514     void detect(InputArray image, OutputArray positions, OutputArray votes = cv::noArray(), int cannyThreshold = 100);
515     void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = cv::noArray());
516
517     void release();
518
519 protected:
520     virtual void setTemplateImpl(const Mat& edges, const Mat& dx, const Mat& dy, Point templCenter) = 0;
521     virtual void detectImpl(const Mat& edges, const Mat& dx, const Mat& dy, OutputArray positions, OutputArray votes) = 0;
522     virtual void releaseImpl() = 0;
523
524 private:
525     Mat edges_, dx_, dy_;
526 };
527
528 //! erodes the image (applies the local minimum operator)
529 CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
530                          Point anchor=Point(-1,-1), int iterations=1,
531                          int borderType=BORDER_CONSTANT,
532                          const Scalar& borderValue=morphologyDefaultBorderValue() );
533
534 //! dilates the image (applies the local maximum operator)
535 CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
536                           Point anchor=Point(-1,-1), int iterations=1,
537                           int borderType=BORDER_CONSTANT,
538                           const Scalar& borderValue=morphologyDefaultBorderValue() );
539
540 //! applies an advanced morphological operation to the image
541 CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
542                                 int op, InputArray kernel,
543                                 Point anchor=Point(-1,-1), int iterations=1,
544                                 int borderType=BORDER_CONSTANT,
545                                 const Scalar& borderValue=morphologyDefaultBorderValue() );
546
547 //! interpolation algorithm
548 enum
549 {
550     INTER_NEAREST=CV_INTER_NN, //!< nearest neighbor interpolation
551     INTER_LINEAR=CV_INTER_LINEAR, //!< bilinear interpolation
552     INTER_CUBIC=CV_INTER_CUBIC, //!< bicubic interpolation
553     INTER_AREA=CV_INTER_AREA, //!< area-based (or super) interpolation
554     INTER_LANCZOS4=CV_INTER_LANCZOS4, //!< Lanczos interpolation over 8x8 neighborhood
555     INTER_MAX=7,
556     WARP_INVERSE_MAP=CV_WARP_INVERSE_MAP
557 };
558
559 //! resizes the image
560 CV_EXPORTS_W void resize( InputArray src, OutputArray dst,
561                           Size dsize, double fx=0, double fy=0,
562                           int interpolation=INTER_LINEAR );
563
564 //! warps the image using affine transformation
565 CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,
566                               InputArray M, Size dsize,
567                               int flags=INTER_LINEAR,
568                               int borderMode=BORDER_CONSTANT,
569                               const Scalar& borderValue=Scalar());
570
571 //! warps the image using perspective transformation
572 CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst,
573                                    InputArray M, Size dsize,
574                                    int flags=INTER_LINEAR,
575                                    int borderMode=BORDER_CONSTANT,
576                                    const Scalar& borderValue=Scalar());
577
578 enum
579 {
580     INTER_BITS=5, INTER_BITS2=INTER_BITS*2,
581     INTER_TAB_SIZE=(1<<INTER_BITS),
582     INTER_TAB_SIZE2=INTER_TAB_SIZE*INTER_TAB_SIZE
583 };
584
585 //! warps the image using the precomputed maps. The maps are stored in either floating-point or integer fixed-point format
586 CV_EXPORTS_W void remap( InputArray src, OutputArray dst,
587                          InputArray map1, InputArray map2,
588                          int interpolation, int borderMode=BORDER_CONSTANT,
589                          const Scalar& borderValue=Scalar());
590
591 //! converts maps for remap from floating-point to fixed-point format or backwards
592 CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2,
593                                OutputArray dstmap1, OutputArray dstmap2,
594                                int dstmap1type, bool nninterpolation=false );
595
596 //! returns 2x3 affine transformation matrix for the planar rotation.
597 CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale );
598 //! returns 3x3 perspective transformation for the corresponding 4 point pairs.
599 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
600 //! returns 2x3 affine transformation for the corresponding 3 point pairs.
601 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
602 //! computes 2x3 affine transformation matrix that is inverse to the specified 2x3 affine transformation.
603 CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );
604
605 CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst );
606 CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
607
608 //! extracts rectangle from the image at sub-pixel location
609 CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
610                                  Point2f center, OutputArray patch, int patchType=-1 );
611
612 //! computes the integral image
613 CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth=-1 );
614
615 //! computes the integral image and integral for the squared image
616 CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,
617                                         OutputArray sqsum, int sdepth=-1 );
618 //! computes the integral image, integral for the squared image and the tilted integral image
619 CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum,
620                                         OutputArray sqsum, OutputArray tilted,
621                                         int sdepth=-1 );
622
623 //! adds image to the accumulator (dst += src). Unlike cv::add, dst and src can have different types.
624 CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
625                               InputArray mask=noArray() );
626 //! adds squared src image to the accumulator (dst += src*src).
627 CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst,
628                                     InputArray mask=noArray() );
629 //! adds product of the 2 images to the accumulator (dst += src1*src2).
630 CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,
631                                      InputOutputArray dst, InputArray mask=noArray() );
632 //! updates the running average (dst = dst*(1-alpha) + src*alpha)
633 CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
634                                       double alpha, InputArray mask=noArray() );
635
636 //! computes PSNR image/video quality metric
637 CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2);
638
639 CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2,
640                                     InputArray window = noArray(), CV_OUT double* response=0);
641 CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);
642
643 //! type of the threshold operation
644 enum { THRESH_BINARY=CV_THRESH_BINARY, THRESH_BINARY_INV=CV_THRESH_BINARY_INV,
645        THRESH_TRUNC=CV_THRESH_TRUNC, THRESH_TOZERO=CV_THRESH_TOZERO,
646        THRESH_TOZERO_INV=CV_THRESH_TOZERO_INV, THRESH_MASK=CV_THRESH_MASK,
647        THRESH_OTSU=CV_THRESH_OTSU };
648
649 //! applies fixed threshold to the image
650 CV_EXPORTS_W double threshold( InputArray src, OutputArray dst,
651                                double thresh, double maxval, int type );
652
653 //! adaptive threshold algorithm
654 enum { ADAPTIVE_THRESH_MEAN_C=0, ADAPTIVE_THRESH_GAUSSIAN_C=1 };
655
656 //! applies variable (adaptive) threshold to the image
657 CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst,
658                                      double maxValue, int adaptiveMethod,
659                                      int thresholdType, int blockSize, double C );
660
661 //! smooths and downsamples the image
662 CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst,
663                            const Size& dstsize=Size(), int borderType=BORDER_DEFAULT );
664 //! upsamples and smoothes the image
665 CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst,
666                          const Size& dstsize=Size(), int borderType=BORDER_DEFAULT );
667
668 //! builds the gaussian pyramid using pyrDown() as a basic operation
669 CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst,
670                               int maxlevel, int borderType=BORDER_DEFAULT );
671
672 //! corrects lens distortion for the given camera matrix and distortion coefficients
673 CV_EXPORTS_W void undistort( InputArray src, OutputArray dst,
674                              InputArray cameraMatrix,
675                              InputArray distCoeffs,
676                              InputArray newCameraMatrix=noArray() );
677
678 //! initializes maps for cv::remap() to correct lens distortion and optionally rectify the image
679 CV_EXPORTS_W void initUndistortRectifyMap( InputArray cameraMatrix, InputArray distCoeffs,
680                            InputArray R, InputArray newCameraMatrix,
681                            Size size, int m1type, OutputArray map1, OutputArray map2 );
682
683 enum
684 {
685     PROJ_SPHERICAL_ORTHO = 0,
686     PROJ_SPHERICAL_EQRECT = 1
687 };
688
689 //! initializes maps for cv::remap() for wide-angle
690 CV_EXPORTS_W float initWideAngleProjMap( InputArray cameraMatrix, InputArray distCoeffs,
691                                          Size imageSize, int destImageWidth,
692                                          int m1type, OutputArray map1, OutputArray map2,
693                                          int projType=PROJ_SPHERICAL_EQRECT, double alpha=0);
694
695 //! returns the default new camera matrix (by default it is the same as cameraMatrix unless centerPricipalPoint=true)
696 CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsize=Size(),
697                                             bool centerPrincipalPoint=false );
698
699 //! returns points' coordinates after lens distortion correction
700 CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst,
701                                    InputArray cameraMatrix, InputArray distCoeffs,
702                                    InputArray R=noArray(), InputArray P=noArray());
703
704 template<> CV_EXPORTS void Ptr<CvHistogram>::delete_obj();
705
706 //! computes the joint dense histogram for a set of images.
707 CV_EXPORTS void calcHist( const Mat* images, int nimages,
708                           const int* channels, InputArray mask,
709                           OutputArray hist, int dims, const int* histSize,
710                           const float** ranges, bool uniform=true, bool accumulate=false );
711
712 //! computes the joint sparse histogram for a set of images.
713 CV_EXPORTS void calcHist( const Mat* images, int nimages,
714                           const int* channels, InputArray mask,
715                           SparseMat& hist, int dims,
716                           const int* histSize, const float** ranges,
717                           bool uniform=true, bool accumulate=false );
718
719 CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
720                             const vector<int>& channels,
721                             InputArray mask, OutputArray hist,
722                             const vector<int>& histSize,
723                             const vector<float>& ranges,
724                             bool accumulate=false );
725
726 //! computes back projection for the set of images
727 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
728                                  const int* channels, InputArray hist,
729                                  OutputArray backProject, const float** ranges,
730                                  double scale=1, bool uniform=true );
731
732 //! computes back projection for the set of images
733 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
734                                  const int* channels, const SparseMat& hist,
735                                  OutputArray backProject, const float** ranges,
736                                  double scale=1, bool uniform=true );
737
738 CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const vector<int>& channels,
739                                    InputArray hist, OutputArray dst,
740                                    const vector<float>& ranges,
741                                    double scale );
742
743 /*CV_EXPORTS void calcBackProjectPatch( const Mat* images, int nimages, const int* channels,
744                                       InputArray hist, OutputArray dst, Size patchSize,
745                                       int method, double factor=1 );
746
747 CV_EXPORTS_W void calcBackProjectPatch( InputArrayOfArrays images, const vector<int>& channels,
748                                         InputArray hist, OutputArray dst, Size patchSize,
749                                         int method, double factor=1 );*/
750
751 //! compares two histograms stored in dense arrays
752 CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method );
753
754 //! compares two histograms stored in sparse arrays
755 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
756
757 //! normalizes the grayscale image brightness and contrast by normalizing its histogram
758 CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );
759
760 CV_EXPORTS float EMD( InputArray signature1, InputArray signature2,
761                       int distType, InputArray cost=noArray(),
762                       float* lowerBound=0, OutputArray flow=noArray() );
763
764 //! segments the image using watershed algorithm
765 CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers );
766
767 //! filters image using meanshift algorithm
768 CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst,
769                                          double sp, double sr, int maxLevel=1,
770                                          TermCriteria termcrit=TermCriteria(
771                                             TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) );
772
773 //! class of the pixel in GrabCut algorithm
774 enum
775 {
776     GC_BGD    = 0,  //!< background
777     GC_FGD    = 1,  //!< foreground
778     GC_PR_BGD = 2,  //!< most probably background
779     GC_PR_FGD = 3   //!< most probably foreground
780 };
781
782 //! GrabCut algorithm flags
783 enum
784 {
785     GC_INIT_WITH_RECT  = 0,
786     GC_INIT_WITH_MASK  = 1,
787     GC_EVAL            = 2
788 };
789
790 //! segments the image using GrabCut algorithm
791 CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect,
792                            InputOutputArray bgdModel, InputOutputArray fgdModel,
793                            int iterCount, int mode = GC_EVAL );
794
795 enum
796 {
797     DIST_LABEL_CCOMP = 0,
798     DIST_LABEL_PIXEL = 1
799 };
800
801 //! builds the discrete Voronoi diagram
802 CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst,
803                                      OutputArray labels, int distanceType, int maskSize,
804                                      int labelType=DIST_LABEL_CCOMP );
805
806 //! computes the distance transform map
807 CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst,
808                                      int distanceType, int maskSize );
809
810 enum { FLOODFILL_FIXED_RANGE = 1 << 16, FLOODFILL_MASK_ONLY = 1 << 17 };
811
812 //! fills the semi-uniform image region starting from the specified seed point
813 CV_EXPORTS int floodFill( InputOutputArray image,
814                           Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0,
815                           Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
816                           int flags=4 );
817
818 //! fills the semi-uniform image region and/or the mask starting from the specified seed point
819 CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
820                             Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0,
821                             Scalar loDiff=Scalar(), Scalar upDiff=Scalar(),
822                             int flags=4 );
823
824
825 enum
826 {
827     COLOR_BGR2BGRA    =0,
828     COLOR_RGB2RGBA    =COLOR_BGR2BGRA,
829
830     COLOR_BGRA2BGR    =1,
831     COLOR_RGBA2RGB    =COLOR_BGRA2BGR,
832
833     COLOR_BGR2RGBA    =2,
834     COLOR_RGB2BGRA    =COLOR_BGR2RGBA,
835
836     COLOR_RGBA2BGR    =3,
837     COLOR_BGRA2RGB    =COLOR_RGBA2BGR,
838
839     COLOR_BGR2RGB     =4,
840     COLOR_RGB2BGR     =COLOR_BGR2RGB,
841
842     COLOR_BGRA2RGBA   =5,
843     COLOR_RGBA2BGRA   =COLOR_BGRA2RGBA,
844
845     COLOR_BGR2GRAY    =6,
846     COLOR_RGB2GRAY    =7,
847     COLOR_GRAY2BGR    =8,
848     COLOR_GRAY2RGB    =COLOR_GRAY2BGR,
849     COLOR_GRAY2BGRA   =9,
850     COLOR_GRAY2RGBA   =COLOR_GRAY2BGRA,
851     COLOR_BGRA2GRAY   =10,
852     COLOR_RGBA2GRAY   =11,
853
854     COLOR_BGR2BGR565  =12,
855     COLOR_RGB2BGR565  =13,
856     COLOR_BGR5652BGR  =14,
857     COLOR_BGR5652RGB  =15,
858     COLOR_BGRA2BGR565 =16,
859     COLOR_RGBA2BGR565 =17,
860     COLOR_BGR5652BGRA =18,
861     COLOR_BGR5652RGBA =19,
862
863     COLOR_GRAY2BGR565 =20,
864     COLOR_BGR5652GRAY =21,
865
866     COLOR_BGR2BGR555  =22,
867     COLOR_RGB2BGR555  =23,
868     COLOR_BGR5552BGR  =24,
869     COLOR_BGR5552RGB  =25,
870     COLOR_BGRA2BGR555 =26,
871     COLOR_RGBA2BGR555 =27,
872     COLOR_BGR5552BGRA =28,
873     COLOR_BGR5552RGBA =29,
874
875     COLOR_GRAY2BGR555 =30,
876     COLOR_BGR5552GRAY =31,
877
878     COLOR_BGR2XYZ     =32,
879     COLOR_RGB2XYZ     =33,
880     COLOR_XYZ2BGR     =34,
881     COLOR_XYZ2RGB     =35,
882
883     COLOR_BGR2YCrCb   =36,
884     COLOR_RGB2YCrCb   =37,
885     COLOR_YCrCb2BGR   =38,
886     COLOR_YCrCb2RGB   =39,
887
888     COLOR_BGR2HSV     =40,
889     COLOR_RGB2HSV     =41,
890
891     COLOR_BGR2Lab     =44,
892     COLOR_RGB2Lab     =45,
893
894     COLOR_BayerBG2BGR =46,
895     COLOR_BayerGB2BGR =47,
896     COLOR_BayerRG2BGR =48,
897     COLOR_BayerGR2BGR =49,
898
899     COLOR_BayerBG2RGB =COLOR_BayerRG2BGR,
900     COLOR_BayerGB2RGB =COLOR_BayerGR2BGR,
901     COLOR_BayerRG2RGB =COLOR_BayerBG2BGR,
902     COLOR_BayerGR2RGB =COLOR_BayerGB2BGR,
903
904     COLOR_BGR2Luv     =50,
905     COLOR_RGB2Luv     =51,
906     COLOR_BGR2HLS     =52,
907     COLOR_RGB2HLS     =53,
908
909     COLOR_HSV2BGR     =54,
910     COLOR_HSV2RGB     =55,
911
912     COLOR_Lab2BGR     =56,
913     COLOR_Lab2RGB     =57,
914     COLOR_Luv2BGR     =58,
915     COLOR_Luv2RGB     =59,
916     COLOR_HLS2BGR     =60,
917     COLOR_HLS2RGB     =61,
918
919     COLOR_BayerBG2BGR_VNG =62,
920     COLOR_BayerGB2BGR_VNG =63,
921     COLOR_BayerRG2BGR_VNG =64,
922     COLOR_BayerGR2BGR_VNG =65,
923
924     COLOR_BayerBG2RGB_VNG =COLOR_BayerRG2BGR_VNG,
925     COLOR_BayerGB2RGB_VNG =COLOR_BayerGR2BGR_VNG,
926     COLOR_BayerRG2RGB_VNG =COLOR_BayerBG2BGR_VNG,
927     COLOR_BayerGR2RGB_VNG =COLOR_BayerGB2BGR_VNG,
928
929     COLOR_BGR2HSV_FULL = 66,
930     COLOR_RGB2HSV_FULL = 67,
931     COLOR_BGR2HLS_FULL = 68,
932     COLOR_RGB2HLS_FULL = 69,
933
934     COLOR_HSV2BGR_FULL = 70,
935     COLOR_HSV2RGB_FULL = 71,
936     COLOR_HLS2BGR_FULL = 72,
937     COLOR_HLS2RGB_FULL = 73,
938
939     COLOR_LBGR2Lab     = 74,
940     COLOR_LRGB2Lab     = 75,
941     COLOR_LBGR2Luv     = 76,
942     COLOR_LRGB2Luv     = 77,
943
944     COLOR_Lab2LBGR     = 78,
945     COLOR_Lab2LRGB     = 79,
946     COLOR_Luv2LBGR     = 80,
947     COLOR_Luv2LRGB     = 81,
948
949     COLOR_BGR2YUV      = 82,
950     COLOR_RGB2YUV      = 83,
951     COLOR_YUV2BGR      = 84,
952     COLOR_YUV2RGB      = 85,
953
954     COLOR_BayerBG2GRAY = 86,
955     COLOR_BayerGB2GRAY = 87,
956     COLOR_BayerRG2GRAY = 88,
957     COLOR_BayerGR2GRAY = 89,
958
959     //YUV 4:2:0 formats family
960     COLOR_YUV2RGB_NV12 = 90,
961     COLOR_YUV2BGR_NV12 = 91,
962     COLOR_YUV2RGB_NV21 = 92,
963     COLOR_YUV2BGR_NV21 = 93,
964     COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
965     COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,
966
967     COLOR_YUV2RGBA_NV12 = 94,
968     COLOR_YUV2BGRA_NV12 = 95,
969     COLOR_YUV2RGBA_NV21 = 96,
970     COLOR_YUV2BGRA_NV21 = 97,
971     COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
972     COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
973
974     COLOR_YUV2RGB_YV12 = 98,
975     COLOR_YUV2BGR_YV12 = 99,
976     COLOR_YUV2RGB_IYUV = 100,
977     COLOR_YUV2BGR_IYUV = 101,
978     COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
979     COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
980     COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
981     COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
982
983     COLOR_YUV2RGBA_YV12 = 102,
984     COLOR_YUV2BGRA_YV12 = 103,
985     COLOR_YUV2RGBA_IYUV = 104,
986     COLOR_YUV2BGRA_IYUV = 105,
987     COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
988     COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
989     COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
990     COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,
991
992     COLOR_YUV2GRAY_420 = 106,
993     COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
994     COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
995     COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
996     COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
997     COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
998     COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
999     COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,
1000
1001     //YUV 4:2:2 formats family
1002     COLOR_YUV2RGB_UYVY = 107,
1003     COLOR_YUV2BGR_UYVY = 108,
1004     //COLOR_YUV2RGB_VYUY = 109,
1005     //COLOR_YUV2BGR_VYUY = 110,
1006     COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
1007     COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
1008     COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
1009     COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,
1010
1011     COLOR_YUV2RGBA_UYVY = 111,
1012     COLOR_YUV2BGRA_UYVY = 112,
1013     //COLOR_YUV2RGBA_VYUY = 113,
1014     //COLOR_YUV2BGRA_VYUY = 114,
1015     COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
1016     COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
1017     COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
1018     COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,
1019
1020     COLOR_YUV2RGB_YUY2 = 115,
1021     COLOR_YUV2BGR_YUY2 = 116,
1022     COLOR_YUV2RGB_YVYU = 117,
1023     COLOR_YUV2BGR_YVYU = 118,
1024     COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
1025     COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
1026     COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
1027     COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,
1028
1029     COLOR_YUV2RGBA_YUY2 = 119,
1030     COLOR_YUV2BGRA_YUY2 = 120,
1031     COLOR_YUV2RGBA_YVYU = 121,
1032     COLOR_YUV2BGRA_YVYU = 122,
1033     COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
1034     COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
1035     COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
1036     COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,
1037
1038     COLOR_YUV2GRAY_UYVY = 123,
1039     COLOR_YUV2GRAY_YUY2 = 124,
1040     //COLOR_YUV2GRAY_VYUY = COLOR_YUV2GRAY_UYVY,
1041     COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
1042     COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
1043     COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
1044     COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
1045     COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,
1046
1047     // alpha premultiplication
1048     COLOR_RGBA2mRGBA = 125,
1049     COLOR_mRGBA2RGBA = 126,
1050
1051     COLOR_COLORCVT_MAX  = 127
1052 };
1053
1054
1055 //! converts image from one color space to another
1056 CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 );
1057
1058 //! raster image moments
1059 class CV_EXPORTS_W_MAP Moments
1060 {
1061 public:
1062     //! the default constructor
1063     Moments();
1064     //! the full constructor
1065     Moments(double m00, double m10, double m01, double m20, double m11,
1066             double m02, double m30, double m21, double m12, double m03 );
1067     //! the conversion from CvMoments
1068     Moments( const CvMoments& moments );
1069     //! the conversion to CvMoments
1070     operator CvMoments() const;
1071
1072     //! spatial moments
1073     CV_PROP_RW double  m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;
1074     //! central moments
1075     CV_PROP_RW double  mu20, mu11, mu02, mu30, mu21, mu12, mu03;
1076     //! central normalized moments
1077     CV_PROP_RW double  nu20, nu11, nu02, nu30, nu21, nu12, nu03;
1078 };
1079
1080 //! computes moments of the rasterized shape or a vector of points
1081 CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage=false );
1082
1083 //! computes 7 Hu invariants from the moments
1084 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
1085 CV_EXPORTS_W void HuMoments( const Moments& m, CV_OUT OutputArray hu );
1086
1087 //! type of the template matching operation
1088 enum { TM_SQDIFF=0, TM_SQDIFF_NORMED=1, TM_CCORR=2, TM_CCORR_NORMED=3, TM_CCOEFF=4, TM_CCOEFF_NORMED=5 };
1089
1090 //! computes the proximity map for the raster template and the image where the template is searched for
1091 CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,
1092                                  OutputArray result, int method );
1093
1094 //! mode of the contour retrieval algorithm
1095 enum
1096 {
1097     RETR_EXTERNAL=CV_RETR_EXTERNAL, //!< retrieve only the most external (top-level) contours
1098     RETR_LIST=CV_RETR_LIST, //!< retrieve all the contours without any hierarchical information
1099     RETR_CCOMP=CV_RETR_CCOMP, //!< retrieve the connected components (that can possibly be nested)
1100     RETR_TREE=CV_RETR_TREE, //!< retrieve all the contours and the whole hierarchy
1101     RETR_FLOODFILL=CV_RETR_FLOODFILL
1102 };
1103
1104 //! the contour approximation algorithm
1105 enum
1106 {
1107     CHAIN_APPROX_NONE=CV_CHAIN_APPROX_NONE,
1108     CHAIN_APPROX_SIMPLE=CV_CHAIN_APPROX_SIMPLE,
1109     CHAIN_APPROX_TC89_L1=CV_CHAIN_APPROX_TC89_L1,
1110     CHAIN_APPROX_TC89_KCOS=CV_CHAIN_APPROX_TC89_KCOS
1111 };
1112
1113 //! retrieves contours and the hierarchical information from black-n-white image.
1114 CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours,
1115                               OutputArray hierarchy, int mode,
1116                               int method, Point offset=Point());
1117
1118 //! retrieves contours from black-n-white image.
1119 CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours,
1120                               int mode, int method, Point offset=Point());
1121
1122 //! approximates contour or a curve using Douglas-Peucker algorithm
1123 CV_EXPORTS_W void approxPolyDP( InputArray curve,
1124                                 OutputArray approxCurve,
1125                                 double epsilon, bool closed );
1126
1127 //! computes the contour perimeter (closed=true) or a curve length
1128 CV_EXPORTS_W double arcLength( InputArray curve, bool closed );
1129 //! computes the bounding rectangle for a contour
1130 CV_EXPORTS_W Rect boundingRect( InputArray points );
1131 //! computes the contour area
1132 CV_EXPORTS_W double contourArea( InputArray contour, bool oriented=false );
1133 //! computes the minimal rotated rectangle for a set of points
1134 CV_EXPORTS_W RotatedRect minAreaRect( InputArray points );
1135 //! computes the minimal enclosing circle for a set of points
1136 CV_EXPORTS_W void minEnclosingCircle( InputArray points,
1137                                       CV_OUT Point2f& center, CV_OUT float& radius );
1138 //! matches two contours using one of the available algorithms
1139 CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
1140                                  int method, double parameter );
1141 //! computes convex hull for a set of 2D points.
1142 CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull,
1143                               bool clockwise=false, bool returnPoints=true );
1144 //! computes the contour convexity defects
1145 CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects );
1146
1147 //! returns true if the contour is convex. Does not support contours with self-intersection
1148 CV_EXPORTS_W bool isContourConvex( InputArray contour );
1149
1150 //! finds intersection of two convex polygons
1151 CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2,
1152                                           OutputArray _p12, bool handleNested=true );
1153
1154 //! fits ellipse to the set of 2D points
1155 CV_EXPORTS_W RotatedRect fitEllipse( InputArray points );
1156
1157 //! fits line to the set of 2D points using M-estimator algorithm
1158 CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType,
1159                            double param, double reps, double aeps );
1160 //! checks if the point is inside the contour. Optionally computes the signed distance from the point to the contour boundary
1161 CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist );
1162
1163
1164 class CV_EXPORTS_W Subdiv2D
1165 {
1166 public:
1167     enum
1168     {
1169         PTLOC_ERROR = -2,
1170         PTLOC_OUTSIDE_RECT = -1,
1171         PTLOC_INSIDE = 0,
1172         PTLOC_VERTEX = 1,
1173         PTLOC_ON_EDGE = 2
1174     };
1175
1176     enum
1177     {
1178         NEXT_AROUND_ORG   = 0x00,
1179         NEXT_AROUND_DST   = 0x22,
1180         PREV_AROUND_ORG   = 0x11,
1181         PREV_AROUND_DST   = 0x33,
1182         NEXT_AROUND_LEFT  = 0x13,
1183         NEXT_AROUND_RIGHT = 0x31,
1184         PREV_AROUND_LEFT  = 0x20,
1185         PREV_AROUND_RIGHT = 0x02
1186     };
1187
1188     CV_WRAP Subdiv2D();
1189     CV_WRAP Subdiv2D(Rect rect);
1190     CV_WRAP void initDelaunay(Rect rect);
1191
1192     CV_WRAP int insert(Point2f pt);
1193     CV_WRAP void insert(const vector<Point2f>& ptvec);
1194     CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex);
1195
1196     CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt=0);
1197     CV_WRAP void getEdgeList(CV_OUT vector<Vec4f>& edgeList) const;
1198     CV_WRAP void getTriangleList(CV_OUT vector<Vec6f>& triangleList) const;
1199     CV_WRAP void getVoronoiFacetList(const vector<int>& idx, CV_OUT vector<vector<Point2f> >& facetList,
1200                                      CV_OUT vector<Point2f>& facetCenters);
1201
1202     CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge=0) const;
1203
1204     CV_WRAP int getEdge( int edge, int nextEdgeType ) const;
1205     CV_WRAP int nextEdge(int edge) const;
1206     CV_WRAP int rotateEdge(int edge, int rotate) const;
1207     CV_WRAP int symEdge(int edge) const;
1208     CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt=0) const;
1209     CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt=0) const;
1210
1211 protected:
1212     int newEdge();
1213     void deleteEdge(int edge);
1214     int newPoint(Point2f pt, bool isvirtual, int firstEdge=0);
1215     void deletePoint(int vtx);
1216     void setEdgePoints( int edge, int orgPt, int dstPt );
1217     void splice( int edgeA, int edgeB );
1218     int connectEdges( int edgeA, int edgeB );
1219     void swapEdges( int edge );
1220     int isRightOf(Point2f pt, int edge) const;
1221     void calcVoronoi();
1222     void clearVoronoi();
1223     void checkSubdiv() const;
1224
1225     struct CV_EXPORTS Vertex
1226     {
1227         Vertex();
1228         Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0);
1229         bool isvirtual() const;
1230         bool isfree() const;
1231         int firstEdge;
1232         int type;
1233         Point2f pt;
1234     };
1235     struct CV_EXPORTS QuadEdge
1236     {
1237         QuadEdge();
1238         QuadEdge(int edgeidx);
1239         bool isfree() const;
1240         int next[4];
1241         int pt[4];
1242     };
1243
1244     vector<Vertex> vtx;
1245     vector<QuadEdge> qedges;
1246     int freeQEdge;
1247     int freePoint;
1248     bool validGeometry;
1249
1250     int recentEdge;
1251     Point2f topLeft;
1252     Point2f bottomRight;
1253 };
1254
1255 }
1256
1257 #endif /* __cplusplus */
1258
1259 #endif
1260
1261 /* End of file. */