Home | History | Annotate | Download | only in opencv2
      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 __OPENCV_IMGPROC_HPP__
     44 #define __OPENCV_IMGPROC_HPP__
     45 
     46 #include "opencv2/core.hpp"
     47 
     48 /**
     49   @defgroup imgproc Image processing
     50   @{
     51     @defgroup imgproc_filter Image Filtering
     52 
     53 Functions and classes described in this section are used to perform various linear or non-linear
     54 filtering operations on 2D images (represented as Mat's). It means that for each pixel location
     55 \f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to
     56 compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of
     57 morphological operations, it is the minimum or maximum values, and so on. The computed response is
     58 stored in the destination image at the same location \f$(x,y)\f$. It means that the output image
     59 will be of the same size as the input image. Normally, the functions support multi-channel arrays,
     60 in which case every channel is processed independently. Therefore, the output image will also have
     61 the same number of channels as the input one.
     62 
     63 Another common feature of the functions and classes described in this section is that, unlike
     64 simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For
     65 example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when
     66 processing the left-most pixels in each row, you need pixels to the left of them, that is, outside
     67 of the image. You can let these pixels be the same as the left-most image pixels ("replicated
     68 border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant
     69 border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method.
     70 For details, see cv::BorderTypes
     71 
     72 @anchor filter_depths
     73 ### Depth combinations
     74 Input depth (src.depth()) | Output depth (ddepth)
     75 --------------------------|----------------------
     76 CV_8U                     | -1/CV_16S/CV_32F/CV_64F
     77 CV_16U/CV_16S             | -1/CV_32F/CV_64F
     78 CV_32F                    | -1/CV_32F/CV_64F
     79 CV_64F                    | -1/CV_64F
     80 
     81 @note when ddepth=-1, the output image will have the same depth as the source.
     82 
     83     @defgroup imgproc_transform Geometric Image Transformations
     84 
     85 The functions in this section perform various geometrical transformations of 2D images. They do not
     86 change the image content but deform the pixel grid and map this deformed grid to the destination
     87 image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from
     88 destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the
     89 functions compute coordinates of the corresponding "donor" pixel in the source image and copy the
     90 pixel value:
     91 
     92 \f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f]
     93 
     94 In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow
     95 \texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping
     96 \f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula.
     97 
     98 The actual implementations of the geometrical transformations, from the most generic remap and to
     99 the simplest and the fastest resize, need to solve two main problems with the above formula:
    100 
    101 - Extrapolation of non-existing pixels. Similarly to the filtering functions described in the
    102 previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both
    103 of them may fall outside of the image. In this case, an extrapolation method needs to be used.
    104 OpenCV provides the same selection of extrapolation methods as in the filtering functions. In
    105 addition, it provides the method BORDER_TRANSPARENT. This means that the corresponding pixels in
    106 the destination image will not be modified at all.
    107 
    108 - Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point
    109 numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective
    110 transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional
    111 coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the
    112 nearest integer coordinates and the corresponding pixel can be used. This is called a
    113 nearest-neighbor interpolation. However, a better result can be achieved by using more
    114 sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) ,
    115 where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y),
    116 f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ is taken as the
    117 interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See
    118 resize for details.
    119 
    120     @defgroup imgproc_misc Miscellaneous Image Transformations
    121     @defgroup imgproc_draw Drawing Functions
    122 
    123 Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be
    124 rendered with antialiasing (implemented only for 8-bit images for now). All the functions include
    125 the parameter color that uses an RGB value (that may be constructed with the Scalar constructor )
    126 for color images and brightness for grayscale images. For color images, the channel ordering is
    127 normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a
    128 color using the Scalar constructor, it should look like:
    129 
    130 \f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f]
    131 
    132 If you are using your own image rendering and I/O functions, you can use any channel ordering. The
    133 drawing functions process each channel independently and do not depend on the channel order or even
    134 on the used color space. The whole image can be converted from BGR to RGB or to a different color
    135 space using cvtColor .
    136 
    137 If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also,
    138 many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means
    139 that the coordinates can be passed as fixed-point numbers encoded as integers. The number of
    140 fractional bits is specified by the shift parameter and the real point coordinates are calculated as
    141 \f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is
    142 especially effective when rendering antialiased shapes.
    143 
    144 @note The functions do not support alpha-transparency when the target image is 4-channel. In this
    145 case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint
    146 semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main
    147 image.
    148 
    149     @defgroup imgproc_colormap ColorMaps in OpenCV
    150 
    151 The human perception isn't built for observing fine changes in grayscale images. Human eyes are more
    152 sensitive to observing changes between colors, so you often need to recolor your grayscale images to
    153 get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your
    154 computer vision application.
    155 
    156 In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample
    157 code reads the path to an image from command line, applies a Jet colormap on it and shows the
    158 result:
    159 
    160 @code
    161 #include <opencv2/core.hpp>
    162 #include <opencv2/imgproc.hpp>
    163 #include <opencv2/imgcodecs.hpp>
    164 #include <opencv2/highgui.hpp>
    165 using namespace cv;
    166 
    167 #include <iostream>
    168 using namespace std;
    169 
    170 int main(int argc, const char *argv[])
    171 {
    172     // We need an input image. (can be grayscale or color)
    173     if (argc < 2)
    174     {
    175         cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl;
    176         return -1;
    177     }
    178     Mat img_in = imread(argv[1]);
    179     if(img_in.empty())
    180     {
    181         cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl;
    182         return -1;
    183     }
    184     // Holds the colormap version of the image:
    185     Mat img_color;
    186     // Apply the colormap:
    187     applyColorMap(img_in, img_color, COLORMAP_JET);
    188     // Show the result:
    189     imshow("colorMap", img_color);
    190     waitKey(0);
    191     return 0;
    192 }
    193 @endcode
    194 
    195 @see cv::ColormapTypes
    196 
    197     @defgroup imgproc_hist Histograms
    198     @defgroup imgproc_shape Structural Analysis and Shape Descriptors
    199     @defgroup imgproc_motion Motion Analysis and Object Tracking
    200     @defgroup imgproc_feature Feature Detection
    201     @defgroup imgproc_object Object Detection
    202     @defgroup imgproc_c C API
    203   @}
    204 */
    205 
    206 namespace cv
    207 {
    208 
    209 /** @addtogroup imgproc
    210 @{
    211 */
    212 
    213 //! @addtogroup imgproc_filter
    214 //! @{
    215 
    216 //! type of morphological operation
    217 enum MorphTypes{
    218     MORPH_ERODE    = 0, //!< see cv::erode
    219     MORPH_DILATE   = 1, //!< see cv::dilate
    220     MORPH_OPEN     = 2, //!< an opening operation
    221                         //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f]
    222     MORPH_CLOSE    = 3, //!< a closing operation
    223                         //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f]
    224     MORPH_GRADIENT = 4, //!< a morphological gradient
    225                         //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f]
    226     MORPH_TOPHAT   = 5, //!< "top hat"
    227                         //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f]
    228     MORPH_BLACKHAT = 6  //!< "black hat"
    229                         //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f]
    230 };
    231 
    232 //! shape of the structuring element
    233 enum MorphShapes {
    234     MORPH_RECT    = 0, //!< a rectangular structuring element:  \f[E_{ij}=1\f]
    235     MORPH_CROSS   = 1, //!< a cross-shaped structuring element:
    236                        //!< \f[E_{ij} =  \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f]
    237     MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed
    238                       //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height)
    239 };
    240 
    241 //! @} imgproc_filter
    242 
    243 //! @addtogroup imgproc_transform
    244 //! @{
    245 
    246 //! interpolation algorithm
    247 enum InterpolationFlags{
    248     /** nearest neighbor interpolation */
    249     INTER_NEAREST        = 0,
    250     /** bilinear interpolation */
    251     INTER_LINEAR         = 1,
    252     /** bicubic interpolation */
    253     INTER_CUBIC          = 2,
    254     /** resampling using pixel area relation. It may be a preferred method for image decimation, as
    255     it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
    256     method. */
    257     INTER_AREA           = 3,
    258     /** Lanczos interpolation over 8x8 neighborhood */
    259     INTER_LANCZOS4       = 4,
    260     /** mask for interpolation codes */
    261     INTER_MAX            = 7,
    262     /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the
    263     source image, they are set to zero */
    264     WARP_FILL_OUTLIERS   = 8,
    265     /** flag, inverse transformation
    266 
    267     For example, polar transforms:
    268     - flag is __not__ set: \f$dst( \phi , \rho ) = src(x,y)\f$
    269     - flag is set: \f$dst(x,y) = src( \phi , \rho )\f$
    270     */
    271     WARP_INVERSE_MAP     = 16
    272 };
    273 
    274 enum InterpolationMasks {
    275        INTER_BITS      = 5,
    276        INTER_BITS2     = INTER_BITS * 2,
    277        INTER_TAB_SIZE  = 1 << INTER_BITS,
    278        INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE
    279      };
    280 
    281 //! @} imgproc_transform
    282 
    283 //! @addtogroup imgproc_misc
    284 //! @{
    285 
    286 //! Distance types for Distance Transform and M-estimators
    287 //! @see cv::distanceTransform, cv::fitLine
    288 enum DistanceTypes {
    289     DIST_USER    = -1,  //!< User defined distance
    290     DIST_L1      = 1,   //!< distance = |x1-x2| + |y1-y2|
    291     DIST_L2      = 2,   //!< the simple euclidean distance
    292     DIST_C       = 3,   //!< distance = max(|x1-x2|,|y1-y2|)
    293     DIST_L12     = 4,   //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))
    294     DIST_FAIR    = 5,   //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998
    295     DIST_WELSCH  = 6,   //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
    296     DIST_HUBER   = 7    //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345
    297 };
    298 
    299 //! Mask size for distance transform
    300 enum DistanceTransformMasks {
    301     DIST_MASK_3       = 3, //!< mask=3
    302     DIST_MASK_5       = 5, //!< mask=5
    303     DIST_MASK_PRECISE = 0  //!<
    304 };
    305 
    306 //! type of the threshold operation
    307 //! ![threshold types](pics/threshold.png)
    308 enum ThresholdTypes {
    309     THRESH_BINARY     = 0, //!< \f[\texttt{dst} (x,y) =  \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
    310     THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) =  \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f]
    311     THRESH_TRUNC      = 2, //!< \f[\texttt{dst} (x,y) =  \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
    312     THRESH_TOZERO     = 3, //!< \f[\texttt{dst} (x,y) =  \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
    313     THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) =  \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
    314     THRESH_MASK       = 7,
    315     THRESH_OTSU       = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value
    316     THRESH_TRIANGLE   = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value
    317 };
    318 
    319 //! adaptive threshold algorithm
    320 //! see cv::adaptiveThreshold
    321 enum AdaptiveThresholdTypes {
    322     /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times
    323     \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */
    324     ADAPTIVE_THRESH_MEAN_C     = 0,
    325     /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian
    326     window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$
    327     minus C . The default sigma (standard deviation) is used for the specified blockSize . See
    328     cv::getGaussianKernel*/
    329     ADAPTIVE_THRESH_GAUSSIAN_C = 1
    330 };
    331 
    332 //! cv::undistort mode
    333 enum UndistortTypes {
    334        PROJ_SPHERICAL_ORTHO  = 0,
    335        PROJ_SPHERICAL_EQRECT = 1
    336      };
    337 
    338 //! class of the pixel in GrabCut algorithm
    339 enum GrabCutClasses {
    340     GC_BGD    = 0,  //!< an obvious background pixels
    341     GC_FGD    = 1,  //!< an obvious foreground (object) pixel
    342     GC_PR_BGD = 2,  //!< a possible background pixel
    343     GC_PR_FGD = 3   //!< a possible foreground pixel
    344 };
    345 
    346 //! GrabCut algorithm flags
    347 enum GrabCutModes {
    348     /** The function initializes the state and the mask using the provided rectangle. After that it
    349     runs iterCount iterations of the algorithm. */
    350     GC_INIT_WITH_RECT  = 0,
    351     /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT
    352     and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are
    353     automatically initialized with GC_BGD .*/
    354     GC_INIT_WITH_MASK  = 1,
    355     /** The value means that the algorithm should just resume. */
    356     GC_EVAL            = 2
    357 };
    358 
    359 //! distanceTransform algorithm flags
    360 enum DistanceTransformLabelTypes {
    361     /** each connected component of zeros in src (as well as all the non-zero pixels closest to the
    362     connected component) will be assigned the same label */
    363     DIST_LABEL_CCOMP = 0,
    364     /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */
    365     DIST_LABEL_PIXEL = 1
    366 };
    367 
    368 //! floodfill algorithm flags
    369 enum FloodFillFlags {
    370     /** If set, the difference between the current pixel and seed pixel is considered. Otherwise,
    371     the difference between neighbor pixels is considered (that is, the range is floating). */
    372     FLOODFILL_FIXED_RANGE = 1 << 16,
    373     /** If set, the function does not change the image ( newVal is ignored), and only fills the
    374     mask with the value specified in bits 8-16 of flags as described above. This option only make
    375     sense in function variants that have the mask parameter. */
    376     FLOODFILL_MASK_ONLY   = 1 << 17
    377 };
    378 
    379 //! @} imgproc_misc
    380 
    381 //! @addtogroup imgproc_shape
    382 //! @{
    383 
    384 //! connected components algorithm output formats
    385 enum ConnectedComponentsTypes {
    386     CC_STAT_LEFT   = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding
    387                         //!< box in the horizontal direction.
    388     CC_STAT_TOP    = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding
    389                         //!< box in the vertical direction.
    390     CC_STAT_WIDTH  = 2, //!< The horizontal size of the bounding box
    391     CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box
    392     CC_STAT_AREA   = 4, //!< The total area (in pixels) of the connected component
    393     CC_STAT_MAX    = 5
    394 };
    395 
    396 //! mode of the contour retrieval algorithm
    397 enum RetrievalModes {
    398     /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for
    399     all the contours. */
    400     RETR_EXTERNAL  = 0,
    401     /** retrieves all of the contours without establishing any hierarchical relationships. */
    402     RETR_LIST      = 1,
    403     /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top
    404     level, there are external boundaries of the components. At the second level, there are
    405     boundaries of the holes. If there is another contour inside a hole of a connected component, it
    406     is still put at the top level. */
    407     RETR_CCOMP     = 2,
    408     /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/
    409     RETR_TREE      = 3,
    410     RETR_FLOODFILL = 4 //!<
    411 };
    412 
    413 //! the contour approximation algorithm
    414 enum ContourApproximationModes {
    415     /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and
    416     (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is,
    417     max(abs(x1-x2),abs(y2-y1))==1. */
    418     CHAIN_APPROX_NONE      = 1,
    419     /** compresses horizontal, vertical, and diagonal segments and leaves only their end points.
    420     For example, an up-right rectangular contour is encoded with 4 points. */
    421     CHAIN_APPROX_SIMPLE    = 2,
    422     /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
    423     CHAIN_APPROX_TC89_L1   = 3,
    424     /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
    425     CHAIN_APPROX_TC89_KCOS = 4
    426 };
    427 
    428 //! @} imgproc_shape
    429 
    430 //! Variants of a Hough transform
    431 enum HoughModes {
    432 
    433     /** classical or standard Hough transform. Every line is represented by two floating-point
    434     numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line,
    435     and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must
    436     be (the created sequence will be) of CV_32FC2 type */
    437     HOUGH_STANDARD      = 0,
    438     /** probabilistic Hough transform (more efficient in case if the picture contains a few long
    439     linear segments). It returns line segments rather than the whole line. Each segment is
    440     represented by starting and ending points, and the matrix must be (the created sequence will
    441     be) of the CV_32SC4 type. */
    442     HOUGH_PROBABILISTIC = 1,
    443     /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as
    444     HOUGH_STANDARD. */
    445     HOUGH_MULTI_SCALE   = 2,
    446     HOUGH_GRADIENT      = 3 //!< basically *21HT*, described in @cite Yuen90
    447 };
    448 
    449 //! Variants of Line Segment %Detector
    450 //! @ingroup imgproc_feature
    451 enum LineSegmentDetectorModes {
    452     LSD_REFINE_NONE = 0, //!< No refinement applied
    453     LSD_REFINE_STD  = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations.
    454     LSD_REFINE_ADV  = 2  //!< Advanced refinement. Number of false alarms is calculated, lines are
    455                          //!< refined through increase of precision, decrement in size, etc.
    456 };
    457 
    458 /** Histogram comparison methods
    459   @ingroup imgproc_hist
    460 */
    461 enum HistCompMethods {
    462     /** Correlation
    463     \f[d(H_1,H_2) =  \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\f]
    464     where
    465     \f[\bar{H_k} =  \frac{1}{N} \sum _J H_k(J)\f]
    466     and \f$N\f$ is a total number of histogram bins. */
    467     HISTCMP_CORREL        = 0,
    468     /** Chi-Square
    469     \f[d(H_1,H_2) =  \sum _I  \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */
    470     HISTCMP_CHISQR        = 1,
    471     /** Intersection
    472     \f[d(H_1,H_2) =  \sum _I  \min (H_1(I), H_2(I))\f] */
    473     HISTCMP_INTERSECT     = 2,
    474     /** Bhattacharyya distance
    475     (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.)
    476     \f[d(H_1,H_2) =  \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\f] */
    477     HISTCMP_BHATTACHARYYA = 3,
    478     HISTCMP_HELLINGER     = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA
    479     /** Alternative Chi-Square
    480     \f[d(H_1,H_2) =  2 * \sum _I  \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}\f]
    481     This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */
    482     HISTCMP_CHISQR_ALT    = 4,
    483     /** Kullback-Leibler divergence
    484     \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */
    485     HISTCMP_KL_DIV        = 5
    486 };
    487 
    488 /** the color conversion code
    489 @see @ref imgproc_color_conversions
    490 @ingroup imgproc_misc
    491  */
    492 enum ColorConversionCodes {
    493     COLOR_BGR2BGRA     = 0, //!< add alpha channel to RGB or BGR image
    494     COLOR_RGB2RGBA     = COLOR_BGR2BGRA,
    495 
    496     COLOR_BGRA2BGR     = 1, //!< remove alpha channel from RGB or BGR image
    497     COLOR_RGBA2RGB     = COLOR_BGRA2BGR,
    498 
    499     COLOR_BGR2RGBA     = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)
    500     COLOR_RGB2BGRA     = COLOR_BGR2RGBA,
    501 
    502     COLOR_RGBA2BGR     = 3,
    503     COLOR_BGRA2RGB     = COLOR_RGBA2BGR,
    504 
    505     COLOR_BGR2RGB      = 4,
    506     COLOR_RGB2BGR      = COLOR_BGR2RGB,
    507 
    508     COLOR_BGRA2RGBA    = 5,
    509     COLOR_RGBA2BGRA    = COLOR_BGRA2RGBA,
    510 
    511     COLOR_BGR2GRAY     = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
    512     COLOR_RGB2GRAY     = 7,
    513     COLOR_GRAY2BGR     = 8,
    514     COLOR_GRAY2RGB     = COLOR_GRAY2BGR,
    515     COLOR_GRAY2BGRA    = 9,
    516     COLOR_GRAY2RGBA    = COLOR_GRAY2BGRA,
    517     COLOR_BGRA2GRAY    = 10,
    518     COLOR_RGBA2GRAY    = 11,
    519 
    520     COLOR_BGR2BGR565   = 12, //!< convert between RGB/BGR and BGR565 (16-bit images)
    521     COLOR_RGB2BGR565   = 13,
    522     COLOR_BGR5652BGR   = 14,
    523     COLOR_BGR5652RGB   = 15,
    524     COLOR_BGRA2BGR565  = 16,
    525     COLOR_RGBA2BGR565  = 17,
    526     COLOR_BGR5652BGRA  = 18,
    527     COLOR_BGR5652RGBA  = 19,
    528 
    529     COLOR_GRAY2BGR565  = 20, //!< convert between grayscale to BGR565 (16-bit images)
    530     COLOR_BGR5652GRAY  = 21,
    531 
    532     COLOR_BGR2BGR555   = 22,  //!< convert between RGB/BGR and BGR555 (16-bit images)
    533     COLOR_RGB2BGR555   = 23,
    534     COLOR_BGR5552BGR   = 24,
    535     COLOR_BGR5552RGB   = 25,
    536     COLOR_BGRA2BGR555  = 26,
    537     COLOR_RGBA2BGR555  = 27,
    538     COLOR_BGR5552BGRA  = 28,
    539     COLOR_BGR5552RGBA  = 29,
    540 
    541     COLOR_GRAY2BGR555  = 30, //!< convert between grayscale and BGR555 (16-bit images)
    542     COLOR_BGR5552GRAY  = 31,
    543 
    544     COLOR_BGR2XYZ      = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
    545     COLOR_RGB2XYZ      = 33,
    546     COLOR_XYZ2BGR      = 34,
    547     COLOR_XYZ2RGB      = 35,
    548 
    549     COLOR_BGR2YCrCb    = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions"
    550     COLOR_RGB2YCrCb    = 37,
    551     COLOR_YCrCb2BGR    = 38,
    552     COLOR_YCrCb2RGB    = 39,
    553 
    554     COLOR_BGR2HSV      = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
    555     COLOR_RGB2HSV      = 41,
    556 
    557     COLOR_BGR2Lab      = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
    558     COLOR_RGB2Lab      = 45,
    559 
    560     COLOR_BGR2Luv      = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
    561     COLOR_RGB2Luv      = 51,
    562     COLOR_BGR2HLS      = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
    563     COLOR_RGB2HLS      = 53,
    564 
    565     COLOR_HSV2BGR      = 54, //!< backward conversions to RGB/BGR
    566     COLOR_HSV2RGB      = 55,
    567 
    568     COLOR_Lab2BGR      = 56,
    569     COLOR_Lab2RGB      = 57,
    570     COLOR_Luv2BGR      = 58,
    571     COLOR_Luv2RGB      = 59,
    572     COLOR_HLS2BGR      = 60,
    573     COLOR_HLS2RGB      = 61,
    574 
    575     COLOR_BGR2HSV_FULL = 66, //!<
    576     COLOR_RGB2HSV_FULL = 67,
    577     COLOR_BGR2HLS_FULL = 68,
    578     COLOR_RGB2HLS_FULL = 69,
    579 
    580     COLOR_HSV2BGR_FULL = 70,
    581     COLOR_HSV2RGB_FULL = 71,
    582     COLOR_HLS2BGR_FULL = 72,
    583     COLOR_HLS2RGB_FULL = 73,
    584 
    585     COLOR_LBGR2Lab     = 74,
    586     COLOR_LRGB2Lab     = 75,
    587     COLOR_LBGR2Luv     = 76,
    588     COLOR_LRGB2Luv     = 77,
    589 
    590     COLOR_Lab2LBGR     = 78,
    591     COLOR_Lab2LRGB     = 79,
    592     COLOR_Luv2LBGR     = 80,
    593     COLOR_Luv2LRGB     = 81,
    594 
    595     COLOR_BGR2YUV      = 82, //!< convert between RGB/BGR and YUV
    596     COLOR_RGB2YUV      = 83,
    597     COLOR_YUV2BGR      = 84,
    598     COLOR_YUV2RGB      = 85,
    599 
    600     //! YUV 4:2:0 family to RGB
    601     COLOR_YUV2RGB_NV12  = 90,
    602     COLOR_YUV2BGR_NV12  = 91,
    603     COLOR_YUV2RGB_NV21  = 92,
    604     COLOR_YUV2BGR_NV21  = 93,
    605     COLOR_YUV420sp2RGB  = COLOR_YUV2RGB_NV21,
    606     COLOR_YUV420sp2BGR  = COLOR_YUV2BGR_NV21,
    607 
    608     COLOR_YUV2RGBA_NV12 = 94,
    609     COLOR_YUV2BGRA_NV12 = 95,
    610     COLOR_YUV2RGBA_NV21 = 96,
    611     COLOR_YUV2BGRA_NV21 = 97,
    612     COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
    613     COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
    614 
    615     COLOR_YUV2RGB_YV12  = 98,
    616     COLOR_YUV2BGR_YV12  = 99,
    617     COLOR_YUV2RGB_IYUV  = 100,
    618     COLOR_YUV2BGR_IYUV  = 101,
    619     COLOR_YUV2RGB_I420  = COLOR_YUV2RGB_IYUV,
    620     COLOR_YUV2BGR_I420  = COLOR_YUV2BGR_IYUV,
    621     COLOR_YUV420p2RGB   = COLOR_YUV2RGB_YV12,
    622     COLOR_YUV420p2BGR   = COLOR_YUV2BGR_YV12,
    623 
    624     COLOR_YUV2RGBA_YV12 = 102,
    625     COLOR_YUV2BGRA_YV12 = 103,
    626     COLOR_YUV2RGBA_IYUV = 104,
    627     COLOR_YUV2BGRA_IYUV = 105,
    628     COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
    629     COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
    630     COLOR_YUV420p2RGBA  = COLOR_YUV2RGBA_YV12,
    631     COLOR_YUV420p2BGRA  = COLOR_YUV2BGRA_YV12,
    632 
    633     COLOR_YUV2GRAY_420  = 106,
    634     COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
    635     COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
    636     COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
    637     COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
    638     COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
    639     COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
    640     COLOR_YUV420p2GRAY  = COLOR_YUV2GRAY_420,
    641 
    642     //! YUV 4:2:2 family to RGB
    643     COLOR_YUV2RGB_UYVY = 107,
    644     COLOR_YUV2BGR_UYVY = 108,
    645     //COLOR_YUV2RGB_VYUY = 109,
    646     //COLOR_YUV2BGR_VYUY = 110,
    647     COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
    648     COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
    649     COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
    650     COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,
    651 
    652     COLOR_YUV2RGBA_UYVY = 111,
    653     COLOR_YUV2BGRA_UYVY = 112,
    654     //COLOR_YUV2RGBA_VYUY = 113,
    655     //COLOR_YUV2BGRA_VYUY = 114,
    656     COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
    657     COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
    658     COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
    659     COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,
    660 
    661     COLOR_YUV2RGB_YUY2 = 115,
    662     COLOR_YUV2BGR_YUY2 = 116,
    663     COLOR_YUV2RGB_YVYU = 117,
    664     COLOR_YUV2BGR_YVYU = 118,
    665     COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
    666     COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
    667     COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
    668     COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,
    669 
    670     COLOR_YUV2RGBA_YUY2 = 119,
    671     COLOR_YUV2BGRA_YUY2 = 120,
    672     COLOR_YUV2RGBA_YVYU = 121,
    673     COLOR_YUV2BGRA_YVYU = 122,
    674     COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
    675     COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
    676     COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
    677     COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,
    678 
    679     COLOR_YUV2GRAY_UYVY = 123,
    680     COLOR_YUV2GRAY_YUY2 = 124,
    681     //CV_YUV2GRAY_VYUY    = CV_YUV2GRAY_UYVY,
    682     COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
    683     COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
    684     COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
    685     COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
    686     COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,
    687 
    688     //! alpha premultiplication
    689     COLOR_RGBA2mRGBA    = 125,
    690     COLOR_mRGBA2RGBA    = 126,
    691 
    692     //! RGB to YUV 4:2:0 family
    693     COLOR_RGB2YUV_I420  = 127,
    694     COLOR_BGR2YUV_I420  = 128,
    695     COLOR_RGB2YUV_IYUV  = COLOR_RGB2YUV_I420,
    696     COLOR_BGR2YUV_IYUV  = COLOR_BGR2YUV_I420,
    697 
    698     COLOR_RGBA2YUV_I420 = 129,
    699     COLOR_BGRA2YUV_I420 = 130,
    700     COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,
    701     COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,
    702     COLOR_RGB2YUV_YV12  = 131,
    703     COLOR_BGR2YUV_YV12  = 132,
    704     COLOR_RGBA2YUV_YV12 = 133,
    705     COLOR_BGRA2YUV_YV12 = 134,
    706 
    707     //! Demosaicing
    708     COLOR_BayerBG2BGR = 46,
    709     COLOR_BayerGB2BGR = 47,
    710     COLOR_BayerRG2BGR = 48,
    711     COLOR_BayerGR2BGR = 49,
    712 
    713     COLOR_BayerBG2RGB = COLOR_BayerRG2BGR,
    714     COLOR_BayerGB2RGB = COLOR_BayerGR2BGR,
    715     COLOR_BayerRG2RGB = COLOR_BayerBG2BGR,
    716     COLOR_BayerGR2RGB = COLOR_BayerGB2BGR,
    717 
    718     COLOR_BayerBG2GRAY = 86,
    719     COLOR_BayerGB2GRAY = 87,
    720     COLOR_BayerRG2GRAY = 88,
    721     COLOR_BayerGR2GRAY = 89,
    722 
    723     //! Demosaicing using Variable Number of Gradients
    724     COLOR_BayerBG2BGR_VNG = 62,
    725     COLOR_BayerGB2BGR_VNG = 63,
    726     COLOR_BayerRG2BGR_VNG = 64,
    727     COLOR_BayerGR2BGR_VNG = 65,
    728 
    729     COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG,
    730     COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG,
    731     COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG,
    732     COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG,
    733 
    734     //! Edge-Aware Demosaicing
    735     COLOR_BayerBG2BGR_EA  = 135,
    736     COLOR_BayerGB2BGR_EA  = 136,
    737     COLOR_BayerRG2BGR_EA  = 137,
    738     COLOR_BayerGR2BGR_EA  = 138,
    739 
    740     COLOR_BayerBG2RGB_EA  = COLOR_BayerRG2BGR_EA,
    741     COLOR_BayerGB2RGB_EA  = COLOR_BayerGR2BGR_EA,
    742     COLOR_BayerRG2RGB_EA  = COLOR_BayerBG2BGR_EA,
    743     COLOR_BayerGR2RGB_EA  = COLOR_BayerGB2BGR_EA,
    744 
    745 
    746     COLOR_COLORCVT_MAX  = 139
    747 };
    748 
    749 /** types of intersection between rectangles
    750 @ingroup imgproc_shape
    751 */
    752 enum RectanglesIntersectTypes {
    753     INTERSECT_NONE = 0, //!< No intersection
    754     INTERSECT_PARTIAL  = 1, //!< There is a partial intersection
    755     INTERSECT_FULL  = 2 //!< One of the rectangle is fully enclosed in the other
    756 };
    757 
    758 //! finds arbitrary template in the grayscale image using Generalized Hough Transform
    759 class CV_EXPORTS GeneralizedHough : public Algorithm
    760 {
    761 public:
    762     //! set template to search
    763     virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0;
    764     virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0;
    765 
    766     //! find template on image
    767     virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0;
    768     virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0;
    769 
    770     //! Canny low threshold.
    771     virtual void setCannyLowThresh(int cannyLowThresh) = 0;
    772     virtual int getCannyLowThresh() const = 0;
    773 
    774     //! Canny high threshold.
    775     virtual void setCannyHighThresh(int cannyHighThresh) = 0;
    776     virtual int getCannyHighThresh() const = 0;
    777 
    778     //! Minimum distance between the centers of the detected objects.
    779     virtual void setMinDist(double minDist) = 0;
    780     virtual double getMinDist() const = 0;
    781 
    782     //! Inverse ratio of the accumulator resolution to the image resolution.
    783     virtual void setDp(double dp) = 0;
    784     virtual double getDp() const = 0;
    785 
    786     //! Maximal size of inner buffers.
    787     virtual void setMaxBufferSize(int maxBufferSize) = 0;
    788     virtual int getMaxBufferSize() const = 0;
    789 };
    790 
    791 //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.
    792 //! Detects position only without traslation and rotation
    793 class CV_EXPORTS GeneralizedHoughBallard : public GeneralizedHough
    794 {
    795 public:
    796     //! R-Table levels.
    797     virtual void setLevels(int levels) = 0;
    798     virtual int getLevels() const = 0;
    799 
    800     //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected.
    801     virtual void setVotesThreshold(int votesThreshold) = 0;
    802     virtual int getVotesThreshold() const = 0;
    803 };
    804 
    805 //! Guil, N., Gonzlez-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.
    806 //! Detects position, traslation and rotation
    807 class CV_EXPORTS GeneralizedHoughGuil : public GeneralizedHough
    808 {
    809 public:
    810     //! Angle difference in degrees between two points in feature.
    811     virtual void setXi(double xi) = 0;
    812     virtual double getXi() const = 0;
    813 
    814     //! Feature table levels.
    815     virtual void setLevels(int levels) = 0;
    816     virtual int getLevels() const = 0;
    817 
    818     //! Maximal difference between angles that treated as equal.
    819     virtual void setAngleEpsilon(double angleEpsilon) = 0;
    820     virtual double getAngleEpsilon() const = 0;
    821 
    822     //! Minimal rotation angle to detect in degrees.
    823     virtual void setMinAngle(double minAngle) = 0;
    824     virtual double getMinAngle() const = 0;
    825 
    826     //! Maximal rotation angle to detect in degrees.
    827     virtual void setMaxAngle(double maxAngle) = 0;
    828     virtual double getMaxAngle() const = 0;
    829 
    830     //! Angle step in degrees.
    831     virtual void setAngleStep(double angleStep) = 0;
    832     virtual double getAngleStep() const = 0;
    833 
    834     //! Angle votes threshold.
    835     virtual void setAngleThresh(int angleThresh) = 0;
    836     virtual int getAngleThresh() const = 0;
    837 
    838     //! Minimal scale to detect.
    839     virtual void setMinScale(double minScale) = 0;
    840     virtual double getMinScale() const = 0;
    841 
    842     //! Maximal scale to detect.
    843     virtual void setMaxScale(double maxScale) = 0;
    844     virtual double getMaxScale() const = 0;
    845 
    846     //! Scale step.
    847     virtual void setScaleStep(double scaleStep) = 0;
    848     virtual double getScaleStep() const = 0;
    849 
    850     //! Scale votes threshold.
    851     virtual void setScaleThresh(int scaleThresh) = 0;
    852     virtual int getScaleThresh() const = 0;
    853 
    854     //! Position votes threshold.
    855     virtual void setPosThresh(int posThresh) = 0;
    856     virtual int getPosThresh() const = 0;
    857 };
    858 
    859 
    860 class CV_EXPORTS_W CLAHE : public Algorithm
    861 {
    862 public:
    863     CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0;
    864 
    865     CV_WRAP virtual void setClipLimit(double clipLimit) = 0;
    866     CV_WRAP virtual double getClipLimit() const = 0;
    867 
    868     CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0;
    869     CV_WRAP virtual Size getTilesGridSize() const = 0;
    870 
    871     CV_WRAP virtual void collectGarbage() = 0;
    872 };
    873 
    874 
    875 class CV_EXPORTS_W Subdiv2D
    876 {
    877 public:
    878     enum { PTLOC_ERROR        = -2,
    879            PTLOC_OUTSIDE_RECT = -1,
    880            PTLOC_INSIDE       = 0,
    881            PTLOC_VERTEX       = 1,
    882            PTLOC_ON_EDGE      = 2
    883          };
    884 
    885     enum { NEXT_AROUND_ORG   = 0x00,
    886            NEXT_AROUND_DST   = 0x22,
    887            PREV_AROUND_ORG   = 0x11,
    888            PREV_AROUND_DST   = 0x33,
    889            NEXT_AROUND_LEFT  = 0x13,
    890            NEXT_AROUND_RIGHT = 0x31,
    891            PREV_AROUND_LEFT  = 0x20,
    892            PREV_AROUND_RIGHT = 0x02
    893          };
    894 
    895     CV_WRAP Subdiv2D();
    896     CV_WRAP Subdiv2D(Rect rect);
    897     CV_WRAP void initDelaunay(Rect rect);
    898 
    899     CV_WRAP int insert(Point2f pt);
    900     CV_WRAP void insert(const std::vector<Point2f>& ptvec);
    901     CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex);
    902 
    903     CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0);
    904     CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const;
    905     CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const;
    906     CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList,
    907                                      CV_OUT std::vector<Point2f>& facetCenters);
    908 
    909     CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const;
    910 
    911     CV_WRAP int getEdge( int edge, int nextEdgeType ) const;
    912     CV_WRAP int nextEdge(int edge) const;
    913     CV_WRAP int rotateEdge(int edge, int rotate) const;
    914     CV_WRAP int symEdge(int edge) const;
    915     CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const;
    916     CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const;
    917 
    918 protected:
    919     int newEdge();
    920     void deleteEdge(int edge);
    921     int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0);
    922     void deletePoint(int vtx);
    923     void setEdgePoints( int edge, int orgPt, int dstPt );
    924     void splice( int edgeA, int edgeB );
    925     int connectEdges( int edgeA, int edgeB );
    926     void swapEdges( int edge );
    927     int isRightOf(Point2f pt, int edge) const;
    928     void calcVoronoi();
    929     void clearVoronoi();
    930     void checkSubdiv() const;
    931 
    932     struct CV_EXPORTS Vertex
    933     {
    934         Vertex();
    935         Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0);
    936         bool isvirtual() const;
    937         bool isfree() const;
    938 
    939         int firstEdge;
    940         int type;
    941         Point2f pt;
    942     };
    943 
    944     struct CV_EXPORTS QuadEdge
    945     {
    946         QuadEdge();
    947         QuadEdge(int edgeidx);
    948         bool isfree() const;
    949 
    950         int next[4];
    951         int pt[4];
    952     };
    953 
    954     std::vector<Vertex> vtx;
    955     std::vector<QuadEdge> qedges;
    956     int freeQEdge;
    957     int freePoint;
    958     bool validGeometry;
    959 
    960     int recentEdge;
    961     Point2f topLeft;
    962     Point2f bottomRight;
    963 };
    964 
    965 //! @addtogroup imgproc_feature
    966 //! @{
    967 
    968 /** @example lsd_lines.cpp
    969 An example using the LineSegmentDetector
    970 */
    971 
    972 /** @brief Line segment detector class
    973 
    974 following the algorithm described at @cite Rafael12 .
    975 */
    976 class CV_EXPORTS_W LineSegmentDetector : public Algorithm
    977 {
    978 public:
    979 
    980     /** @brief Finds lines in the input image.
    981 
    982     This is the output of the default parameters of the algorithm on the above shown image.
    983 
    984     ![image](pics/building_lsd.png)
    985 
    986     @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use:
    987     `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
    988     @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where
    989     Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly
    990     oriented depending on the gradient.
    991     @param width Vector of widths of the regions, where the lines are found. E.g. Width of line.
    992     @param prec Vector of precisions with which the lines are found.
    993     @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The
    994     bigger the value, logarithmically better the detection.
    995     - -1 corresponds to 10 mean false alarms
    996     - 0 corresponds to 1 mean false alarm
    997     - 1 corresponds to 0.1 mean false alarms
    998     This vector will be calculated only when the objects type is LSD_REFINE_ADV.
    999     */
   1000     CV_WRAP virtual void detect(InputArray _image, OutputArray _lines,
   1001                         OutputArray width = noArray(), OutputArray prec = noArray(),
   1002                         OutputArray nfa = noArray()) = 0;
   1003 
   1004     /** @brief Draws the line segments on a given image.
   1005     @param _image The image, where the liens will be drawn. Should be bigger or equal to the image,
   1006     where the lines were found.
   1007     @param lines A vector of the lines that needed to be drawn.
   1008      */
   1009     CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0;
   1010 
   1011     /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels.
   1012 
   1013     @param size The size of the image, where lines1 and lines2 were found.
   1014     @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color.
   1015     @param lines2 The second group of lines. They visualized in red color.
   1016     @param _image Optional image, where the lines will be drawn. The image should be color(3-channel)
   1017     in order for lines1 and lines2 to be drawn in the above mentioned colors.
   1018      */
   1019     CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0;
   1020 
   1021     virtual ~LineSegmentDetector() { }
   1022 };
   1023 
   1024 /** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it.
   1025 
   1026 The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want
   1027 to edit those, as to tailor it for their own application.
   1028 
   1029 @param _refine The way found lines will be refined, see cv::LineSegmentDetectorModes
   1030 @param _scale The scale of the image that will be used to find the lines. Range (0..1].
   1031 @param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale.
   1032 @param _quant Bound to the quantization error on the gradient norm.
   1033 @param _ang_th Gradient angle tolerance in degrees.
   1034 @param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advancent refinement
   1035 is chosen.
   1036 @param _density_th Minimal density of aligned region points in the enclosing rectangle.
   1037 @param _n_bins Number of bins in pseudo-ordering of gradient modulus.
   1038  */
   1039 CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(
   1040     int _refine = LSD_REFINE_STD, double _scale = 0.8,
   1041     double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5,
   1042     double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024);
   1043 
   1044 //! @} imgproc_feature
   1045 
   1046 //! @addtogroup imgproc_filter
   1047 //! @{
   1048 
   1049 /** @brief Returns Gaussian filter coefficients.
   1050 
   1051 The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter
   1052 coefficients:
   1053 
   1054 \f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f]
   1055 
   1056 where \f$i=0..\texttt{ksize}-1\f$ and \f$\alpha\f$ is the scale factor chosen so that \f$\sum_i G_i=1\f$.
   1057 
   1058 Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize
   1059 smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly.
   1060 You may also use the higher-level GaussianBlur.
   1061 @param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive.
   1062 @param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as
   1063 `sigma = 0.3\*((ksize-1)\*0.5 - 1) + 0.8`.
   1064 @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
   1065 @sa  sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur
   1066  */
   1067 CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F );
   1068 
   1069 /** @brief Returns filter coefficients for computing spatial image derivatives.
   1070 
   1071 The function computes and returns the filter coefficients for spatial image derivatives. When
   1072 `ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see cv::Scharr). Otherwise, Sobel
   1073 kernels are generated (see cv::Sobel). The filters are normally passed to sepFilter2D or to
   1074 
   1075 @param kx Output matrix of row filter coefficients. It has the type ktype .
   1076 @param ky Output matrix of column filter coefficients. It has the type ktype .
   1077 @param dx Derivative order in respect of x.
   1078 @param dy Derivative order in respect of y.
   1079 @param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7.
   1080 @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not.
   1081 Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are
   1082 going to filter floating-point images, you are likely to use the normalized kernels. But if you
   1083 compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve
   1084 all the fractional bits, you may want to set normalize=false .
   1085 @param ktype Type of filter coefficients. It can be CV_32f or CV_64F .
   1086  */
   1087 CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky,
   1088                                    int dx, int dy, int ksize,
   1089                                    bool normalize = false, int ktype = CV_32F );
   1090 
   1091 /** @brief Returns Gabor filter coefficients.
   1092 
   1093 For more details about gabor filter equations and parameters, see: [Gabor
   1094 Filter](http://en.wikipedia.org/wiki/Gabor_filter).
   1095 
   1096 @param ksize Size of the filter returned.
   1097 @param sigma Standard deviation of the gaussian envelope.
   1098 @param theta Orientation of the normal to the parallel stripes of a Gabor function.
   1099 @param lambd Wavelength of the sinusoidal factor.
   1100 @param gamma Spatial aspect ratio.
   1101 @param psi Phase offset.
   1102 @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
   1103  */
   1104 CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd,
   1105                                  double gamma, double psi = CV_PI*0.5, int ktype = CV_64F );
   1106 
   1107 //! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
   1108 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
   1109 
   1110 /** @brief Returns a structuring element of the specified size and shape for morphological operations.
   1111 
   1112 The function constructs and returns the structuring element that can be further passed to cv::erode,
   1113 cv::dilate or cv::morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as
   1114 the structuring element.
   1115 
   1116 @param shape Element shape that could be one of cv::MorphShapes
   1117 @param ksize Size of the structuring element.
   1118 @param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the
   1119 anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor
   1120 position. In other cases the anchor just regulates how much the result of the morphological
   1121 operation is shifted.
   1122  */
   1123 CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));
   1124 
   1125 /** @brief Blurs an image using the median filter.
   1126 
   1127 The function smoothes an image using the median filter with the \f$\texttt{ksize} \times
   1128 \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently.
   1129 In-place operation is supported.
   1130 
   1131 @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be
   1132 CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.
   1133 @param dst destination array of the same size and type as src.
   1134 @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
   1135 @sa  bilateralFilter, blur, boxFilter, GaussianBlur
   1136  */
   1137 CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize );
   1138 
   1139 /** @brief Blurs an image using a Gaussian filter.
   1140 
   1141 The function convolves the source image with the specified Gaussian kernel. In-place filtering is
   1142 supported.
   1143 
   1144 @param src input image; the image can have any number of channels, which are processed
   1145 independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
   1146 @param dst output image of the same size and type as src.
   1147 @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
   1148 positive and odd. Or, they can be zero's and then they are computed from sigma.
   1149 @param sigmaX Gaussian kernel standard deviation in X direction.
   1150 @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
   1151 equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
   1152 respectively (see cv::getGaussianKernel for details); to fully control the result regardless of
   1153 possible future modifications of all this semantics, it is recommended to specify all of ksize,
   1154 sigmaX, and sigmaY.
   1155 @param borderType pixel extrapolation method, see cv::BorderTypes
   1156 
   1157 @sa  sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur
   1158  */
   1159 CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize,
   1160                                 double sigmaX, double sigmaY = 0,
   1161                                 int borderType = BORDER_DEFAULT );
   1162 
   1163 /** @brief Applies the bilateral filter to an image.
   1164 
   1165 The function applies bilateral filtering to the input image, as described in
   1166 http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
   1167 bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
   1168 very slow compared to most filters.
   1169 
   1170 _Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<
   1171 10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very
   1172 strong effect, making the image look "cartoonish".
   1173 
   1174 _Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time
   1175 applications, and perhaps d=9 for offline applications that need heavy noise filtering.
   1176 
   1177 This filter does not work inplace.
   1178 @param src Source 8-bit or floating-point, 1-channel or 3-channel image.
   1179 @param dst Destination image of the same size and type as src .
   1180 @param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
   1181 it is computed from sigmaSpace.
   1182 @param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
   1183 farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
   1184 in larger areas of semi-equal color.
   1185 @param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that
   1186 farther pixels will influence each other as long as their colors are close enough (see sigmaColor
   1187 ). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
   1188 proportional to sigmaSpace.
   1189 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
   1190  */
   1191 CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,
   1192                                    double sigmaColor, double sigmaSpace,
   1193                                    int borderType = BORDER_DEFAULT );
   1194 
   1195 /** @brief Blurs an image using the box filter.
   1196 
   1197 The function smoothes an image using the kernel:
   1198 
   1199 \f[\texttt{K} =  \alpha \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1 \end{bmatrix}\f]
   1200 
   1201 where
   1202 
   1203 \f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f]
   1204 
   1205 Unnormalized box filter is useful for computing various integral characteristics over each pixel
   1206 neighborhood, such as covariance matrices of image derivatives (used in dense optical flow
   1207 algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral.
   1208 
   1209 @param src input image.
   1210 @param dst output image of the same size and type as src.
   1211 @param ddepth the output image depth (-1 to use src.depth()).
   1212 @param ksize blurring kernel size.
   1213 @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
   1214 center.
   1215 @param normalize flag, specifying whether the kernel is normalized by its area or not.
   1216 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
   1217 @sa  blur, bilateralFilter, GaussianBlur, medianBlur, integral
   1218  */
   1219 CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
   1220                              Size ksize, Point anchor = Point(-1,-1),
   1221                              bool normalize = true,
   1222                              int borderType = BORDER_DEFAULT );
   1223 
   1224 /** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter.
   1225 
   1226 For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring
   1227 pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$.
   1228 
   1229 The unnormalized square box filter can be useful in computing local image statistics such as the the local
   1230 variance and standard deviation around the neighborhood of a pixel.
   1231 
   1232 @param _src input image
   1233 @param _dst output image of the same size and type as _src
   1234 @param ddepth the output image depth (-1 to use src.depth())
   1235 @param ksize kernel size
   1236 @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel
   1237 center.
   1238 @param normalize flag, specifying whether the kernel is to be normalized by it's area or not.
   1239 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
   1240 @sa boxFilter
   1241 */
   1242 CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth,
   1243                                 Size ksize, Point anchor = Point(-1, -1),
   1244                                 bool normalize = true,
   1245                                 int borderType = BORDER_DEFAULT );
   1246 
   1247 /** @brief Blurs an image using the normalized box filter.
   1248 
   1249 The function smoothes an image using the kernel:
   1250 
   1251 \f[\texttt{K} =  \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \end{bmatrix}\f]
   1252 
   1253 The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(),
   1254 anchor, true, borderType)`.
   1255 
   1256 @param src input image; it can have any number of channels, which are processed independently, but
   1257 the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
   1258 @param dst output image of the same size and type as src.
   1259 @param ksize blurring kernel size.
   1260 @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
   1261 center.
   1262 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
   1263 @sa  boxFilter, bilateralFilter, GaussianBlur, medianBlur
   1264  */
   1265 CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
   1266                         Size ksize, Point anchor = Point(-1,-1),
   1267                         int borderType = BORDER_DEFAULT );
   1268 
   1269 /** @brief Convolves an image with the kernel.
   1270 
   1271 The function applies an arbitrary linear filter to an image. In-place operation is supported. When
   1272 the aperture is partially outside the image, the function interpolates outlier pixel values
   1273 according to the specified border mode.
   1274 
   1275 The function does actually compute correlation, not the convolution:
   1276 
   1277 \f[\texttt{dst} (x,y) =  \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} }  \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f]
   1278 
   1279 That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip
   1280 the kernel using cv::flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows -
   1281 anchor.y - 1)`.
   1282 
   1283 The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or
   1284 larger) and the direct algorithm for small kernels.
   1285 
   1286 @param src input image.
   1287 @param dst output image of the same size and the same number of channels as src.
   1288 @param ddepth desired depth of the destination image, see @ref filter_depths "combinations"
   1289 @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point
   1290 matrix; if you want to apply different kernels to different channels, split the image into
   1291 separate color planes using split and process them individually.
   1292 @param anchor anchor of the kernel that indicates the relative position of a filtered point within
   1293 the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor
   1294 is at the kernel center.
   1295 @param delta optional value added to the filtered pixels before storing them in dst.
   1296 @param borderType pixel extrapolation method, see cv::BorderTypes
   1297 @sa  sepFilter2D, dft, matchTemplate
   1298  */
   1299 CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth,
   1300                             InputArray kernel, Point anchor = Point(-1,-1),
   1301                             double delta = 0, int borderType = BORDER_DEFAULT );
   1302 
   1303 /** @brief Applies a separable linear filter to an image.
   1304 
   1305 The function applies a separable linear filter to the image. That is, first, every row of src is
   1306 filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D
   1307 kernel kernelY. The final result shifted by delta is stored in dst .
   1308 
   1309 @param src Source image.
   1310 @param dst Destination image of the same size and the same number of channels as src .
   1311 @param ddepth Destination image depth, see @ref filter_depths "combinations"
   1312 @param kernelX Coefficients for filtering each row.
   1313 @param kernelY Coefficients for filtering each column.
   1314 @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor
   1315 is at the kernel center.
   1316 @param delta Value added to the filtered results before storing them.
   1317 @param borderType Pixel extrapolation method, see cv::BorderTypes
   1318 @sa  filter2D, Sobel, GaussianBlur, boxFilter, blur
   1319  */
   1320 CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth,
   1321                                InputArray kernelX, InputArray kernelY,
   1322                                Point anchor = Point(-1,-1),
   1323                                double delta = 0, int borderType = BORDER_DEFAULT );
   1324 
   1325 /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
   1326 
   1327 In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to
   1328 calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$
   1329 kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first
   1330 or the second x- or y- derivatives.
   1331 
   1332 There is also the special value `ksize = CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr
   1333 filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is
   1334 
   1335 \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]
   1336 
   1337 for the x-derivative, or transposed for the y-derivative.
   1338 
   1339 The function calculates an image derivative by convolving the image with the appropriate kernel:
   1340 
   1341 \f[\texttt{dst} =  \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]
   1342 
   1343 The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less
   1344 resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)
   1345 or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first
   1346 case corresponds to a kernel of:
   1347 
   1348 \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]
   1349 
   1350 The second case corresponds to a kernel of:
   1351 
   1352 \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]
   1353 
   1354 @param src input image.
   1355 @param dst output image of the same size and the same number of channels as src .
   1356 @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
   1357     8-bit input images it will result in truncated derivatives.
   1358 @param dx order of the derivative x.
   1359 @param dy order of the derivative y.
   1360 @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
   1361 @param scale optional scale factor for the computed derivative values; by default, no scaling is
   1362 applied (see cv::getDerivKernels for details).
   1363 @param delta optional delta value that is added to the results prior to storing them in dst.
   1364 @param borderType pixel extrapolation method, see cv::BorderTypes
   1365 @sa  Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar
   1366  */
   1367 CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
   1368                          int dx, int dy, int ksize = 3,
   1369                          double scale = 1, double delta = 0,
   1370                          int borderType = BORDER_DEFAULT );
   1371 
   1372 /** @brief Calculates the first x- or y- image derivative using Scharr operator.
   1373 
   1374 The function computes the first x- or y- spatial image derivative using the Scharr operator. The
   1375 call
   1376 
   1377 \f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f]
   1378 
   1379 is equivalent to
   1380 
   1381 \f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV\_SCHARR, scale, delta, borderType)} .\f]
   1382 
   1383 @param src input image.
   1384 @param dst output image of the same size and the same number of channels as src.
   1385 @param ddepth output image depth, see @ref filter_depths "combinations"
   1386 @param dx order of the derivative x.
   1387 @param dy order of the derivative y.
   1388 @param scale optional scale factor for the computed derivative values; by default, no scaling is
   1389 applied (see getDerivKernels for details).
   1390 @param delta optional delta value that is added to the results prior to storing them in dst.
   1391 @param borderType pixel extrapolation method, see cv::BorderTypes
   1392 @sa  cartToPolar
   1393  */
   1394 CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth,
   1395                           int dx, int dy, double scale = 1, double delta = 0,
   1396                           int borderType = BORDER_DEFAULT );
   1397 
   1398 /** @example laplace.cpp
   1399   An example using Laplace transformations for edge detection
   1400 */
   1401 
   1402 /** @brief Calculates the Laplacian of an image.
   1403 
   1404 The function calculates the Laplacian of the source image by adding up the second x and y
   1405 derivatives calculated using the Sobel operator:
   1406 
   1407 \f[\texttt{dst} =  \Delta \texttt{src} =  \frac{\partial^2 \texttt{src}}{\partial x^2} +  \frac{\partial^2 \texttt{src}}{\partial y^2}\f]
   1408 
   1409 This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image
   1410 with the following \f$3 \times 3\f$ aperture:
   1411 
   1412 \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]
   1413 
   1414 @param src Source image.
   1415 @param dst Destination image of the same size and the same number of channels as src .
   1416 @param ddepth Desired depth of the destination image.
   1417 @param ksize Aperture size used to compute the second-derivative filters. See getDerivKernels for
   1418 details. The size must be positive and odd.
   1419 @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
   1420 applied. See getDerivKernels for details.
   1421 @param delta Optional delta value that is added to the results prior to storing them in dst .
   1422 @param borderType Pixel extrapolation method, see cv::BorderTypes
   1423 @sa  Sobel, Scharr
   1424  */
   1425 CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
   1426                              int ksize = 1, double scale = 1, double delta = 0,
   1427                              int borderType = BORDER_DEFAULT );
   1428 
   1429 //! @} imgproc_filter
   1430 
   1431 //! @addtogroup imgproc_feature
   1432 //! @{
   1433 
   1434 /** @example edge.cpp
   1435   An example on using the canny edge detector
   1436 */
   1437 
   1438 /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 .
   1439 
   1440 The function finds edges in the input image image and marks them in the output map edges using the
   1441 Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The
   1442 largest value is used to find initial segments of strong edges. See
   1443 <http://en.wikipedia.org/wiki/Canny_edge_detector>
   1444 
   1445 @param image 8-bit input image.
   1446 @param edges output edge map; single channels 8-bit image, which has the same size as image .
   1447 @param threshold1 first threshold for the hysteresis procedure.
   1448 @param threshold2 second threshold for the hysteresis procedure.
   1449 @param apertureSize aperture size for the Sobel operator.
   1450 @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
   1451 \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
   1452 L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
   1453 L2gradient=false ).
   1454  */
   1455 CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
   1456                          double threshold1, double threshold2,
   1457                          int apertureSize = 3, bool L2gradient = false );
   1458 
   1459 /** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection.
   1460 
   1461 The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal
   1462 eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms
   1463 of the formulae in the cornerEigenValsAndVecs description.
   1464 
   1465 @param src Input single-channel 8-bit or floating-point image.
   1466 @param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as
   1467 src .
   1468 @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ).
   1469 @param ksize Aperture parameter for the Sobel operator.
   1470 @param borderType Pixel extrapolation method. See cv::BorderTypes.
   1471  */
   1472 CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst,
   1473                                      int blockSize, int ksize = 3,
   1474                                      int borderType = BORDER_DEFAULT );
   1475 
   1476 /** @brief Harris corner detector.
   1477 
   1478 The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and
   1479 cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance
   1480 matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it
   1481 computes the following characteristic:
   1482 
   1483 \f[\texttt{dst} (x,y) =  \mathrm{det} M^{(x,y)} - k  \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f]
   1484 
   1485 Corners in the image can be found as the local maxima of this response map.
   1486 
   1487 @param src Input single-channel 8-bit or floating-point image.
   1488 @param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same
   1489 size as src .
   1490 @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ).
   1491 @param ksize Aperture parameter for the Sobel operator.
   1492 @param k Harris detector free parameter. See the formula below.
   1493 @param borderType Pixel extrapolation method. See cv::BorderTypes.
   1494  */
   1495 CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,
   1496                                 int ksize, double k,
   1497                                 int borderType = BORDER_DEFAULT );
   1498 
   1499 /** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection.
   1500 
   1501 For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize
   1502 neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as:
   1503 
   1504 \f[M =  \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 &  \sum _{S(p)}dI/dx dI/dy  \\ \sum _{S(p)}dI/dx dI/dy &  \sum _{S(p)}(dI/dy)^2 \end{bmatrix}\f]
   1505 
   1506 where the derivatives are computed using the Sobel operator.
   1507 
   1508 After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as
   1509 \f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where
   1510 
   1511 -   \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$
   1512 -   \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$
   1513 -   \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$
   1514 
   1515 The output of the function can be used for robust edge or corner detection.
   1516 
   1517 @param src Input single-channel 8-bit or floating-point image.
   1518 @param dst Image to store the results. It has the same size as src and the type CV_32FC(6) .
   1519 @param blockSize Neighborhood size (see details below).
   1520 @param ksize Aperture parameter for the Sobel operator.
   1521 @param borderType Pixel extrapolation method. See cv::BorderTypes.
   1522 
   1523 @sa  cornerMinEigenVal, cornerHarris, preCornerDetect
   1524  */
   1525 CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst,
   1526                                           int blockSize, int ksize,
   1527                                           int borderType = BORDER_DEFAULT );
   1528 
   1529 /** @brief Calculates a feature map for corner detection.
   1530 
   1531 The function calculates the complex spatial derivative-based function of the source image
   1532 
   1533 \f[\texttt{dst} = (D_x  \texttt{src} )^2  \cdot D_{yy}  \texttt{src} + (D_y  \texttt{src} )^2  \cdot D_{xx}  \texttt{src} - 2 D_x  \texttt{src} \cdot D_y  \texttt{src} \cdot D_{xy}  \texttt{src}\f]
   1534 
   1535 where \f$D_x\f$,\f$D_y\f$ are the first image derivatives, \f$D_{xx}\f$,\f$D_{yy}\f$ are the second image
   1536 derivatives, and \f$D_{xy}\f$ is the mixed derivative.
   1537 
   1538 The corners can be found as local maximums of the functions, as shown below:
   1539 @code
   1540     Mat corners, dilated_corners;
   1541     preCornerDetect(image, corners, 3);
   1542     // dilation with 3x3 rectangular structuring element
   1543     dilate(corners, dilated_corners, Mat(), 1);
   1544     Mat corner_mask = corners == dilated_corners;
   1545 @endcode
   1546 
   1547 @param src Source single-channel 8-bit of floating-point image.
   1548 @param dst Output image that has the type CV_32F and the same size as src .
   1549 @param ksize %Aperture size of the Sobel .
   1550 @param borderType Pixel extrapolation method. See cv::BorderTypes.
   1551  */
   1552 CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize,
   1553                                    int borderType = BORDER_DEFAULT );
   1554 
   1555 /** @brief Refines the corner locations.
   1556 
   1557 The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as
   1558 shown on the figure below.
   1559 
   1560 ![image](pics/cornersubpix.png)
   1561 
   1562 Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$
   1563 to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$
   1564 subject to image and measurement noise. Consider the expression:
   1565 
   1566 \f[\epsilon _i = {DI_{p_i}}^T  \cdot (q - p_i)\f]
   1567 
   1568 where \f${DI_{p_i}}\f$ is an image gradient at one of the points \f$p_i\f$ in a neighborhood of \f$q\f$ . The
   1569 value of \f$q\f$ is to be found so that \f$\epsilon_i\f$ is minimized. A system of equations may be set up
   1570 with \f$\epsilon_i\f$ set to zero:
   1571 
   1572 \f[\sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T) -  \sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T  \cdot p_i)\f]
   1573 
   1574 where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first
   1575 gradient term \f$G\f$ and the second gradient term \f$b\f$ gives:
   1576 
   1577 \f[q = G^{-1}  \cdot b\f]
   1578 
   1579 The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates
   1580 until the center stays within a set threshold.
   1581 
   1582 @param image Input image.
   1583 @param corners Initial coordinates of the input corners and refined coordinates provided for
   1584 output.
   1585 @param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) ,
   1586 then a \f$5*2+1 \times 5*2+1 = 11 \times 11\f$ search window is used.
   1587 @param zeroZone Half of the size of the dead region in the middle of the search zone over which
   1588 the summation in the formula below is not done. It is used sometimes to avoid possible
   1589 singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such
   1590 a size.
   1591 @param criteria Criteria for termination of the iterative process of corner refinement. That is,
   1592 the process of corner position refinement stops either after criteria.maxCount iterations or when
   1593 the corner position moves by less than criteria.epsilon on some iteration.
   1594  */
   1595 CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners,
   1596                                 Size winSize, Size zeroZone,
   1597                                 TermCriteria criteria );
   1598 
   1599 /** @brief Determines strong corners on an image.
   1600 
   1601 The function finds the most prominent corners in the image or in the specified image region, as
   1602 described in @cite Shi94
   1603 
   1604 -   Function calculates the corner quality measure at every source image pixel using the
   1605     cornerMinEigenVal or cornerHarris .
   1606 -   Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are
   1607     retained).
   1608 -   The corners with the minimal eigenvalue less than
   1609     \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.
   1610 -   The remaining corners are sorted by the quality measure in the descending order.
   1611 -   Function throws away each corner for which there is a stronger corner at a distance less than
   1612     maxDistance.
   1613 
   1614 The function can be used to initialize a point-based tracker of an object.
   1615 
   1616 @note If the function is called with different values A and B of the parameter qualityLevel , and
   1617 A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector
   1618 with qualityLevel=B .
   1619 
   1620 @param image Input 8-bit or floating-point 32-bit, single-channel image.
   1621 @param corners Output vector of detected corners.
   1622 @param maxCorners Maximum number of corners to return. If there are more corners than are found,
   1623 the strongest of them is returned.
   1624 @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
   1625 parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
   1626 (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the
   1627 quality measure less than the product are rejected. For example, if the best corner has the
   1628 quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
   1629 less than 15 are rejected.
   1630 @param minDistance Minimum possible Euclidean distance between the returned corners.
   1631 @param mask Optional region of interest. If the image is not empty (it needs to have the type
   1632 CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
   1633 @param blockSize Size of an average block for computing a derivative covariation matrix over each
   1634 pixel neighborhood. See cornerEigenValsAndVecs .
   1635 @param useHarrisDetector Parameter indicating whether to use a Harris detector (see cornerHarris)
   1636 or cornerMinEigenVal.
   1637 @param k Free parameter of the Harris detector.
   1638 
   1639 @sa  cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,
   1640  */
   1641 CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
   1642                                      int maxCorners, double qualityLevel, double minDistance,
   1643                                      InputArray mask = noArray(), int blockSize = 3,
   1644                                      bool useHarrisDetector = false, double k = 0.04 );
   1645 
   1646 /** @example houghlines.cpp
   1647 An example using the Hough line detector
   1648 */
   1649 
   1650 /** @brief Finds lines in a binary image using the standard Hough transform.
   1651 
   1652 The function implements the standard or standard multi-scale Hough transform algorithm for line
   1653 detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough
   1654 transform.
   1655 
   1656 @param image 8-bit, single-channel binary source image. The image may be modified by the function.
   1657 @param lines Output vector of lines. Each line is represented by a two-element vector
   1658 \f$(\rho, \theta)\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of
   1659 the image). \f$\theta\f$ is the line rotation angle in radians (
   1660 \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).
   1661 @param rho Distance resolution of the accumulator in pixels.
   1662 @param theta Angle resolution of the accumulator in radians.
   1663 @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
   1664 votes ( \f$>\texttt{threshold}\f$ ).
   1665 @param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho .
   1666 The coarse accumulator distance resolution is rho and the accurate accumulator resolution is
   1667 rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these
   1668 parameters should be positive.
   1669 @param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
   1670 @param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines.
   1671 Must fall between 0 and max_theta.
   1672 @param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines.
   1673 Must fall between min_theta and CV_PI.
   1674  */
   1675 CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,
   1676                               double rho, double theta, int threshold,
   1677                               double srn = 0, double stn = 0,
   1678                               double min_theta = 0, double max_theta = CV_PI );
   1679 
   1680 /** @brief Finds line segments in a binary image using the probabilistic Hough transform.
   1681 
   1682 The function implements the probabilistic Hough transform algorithm for line detection, described
   1683 in @cite Matas00
   1684 
   1685 See the line detection example below:
   1686 
   1687 @code
   1688     #include <opencv2/imgproc.hpp>
   1689     #include <opencv2/highgui.hpp>
   1690 
   1691     using namespace cv;
   1692 
   1693     int main(int argc, char** argv)
   1694     {
   1695         Mat src, dst, color_dst;
   1696         if( argc != 2 || !(src=imread(argv[1], 0)).data)
   1697             return -1;
   1698 
   1699         Canny( src, dst, 50, 200, 3 );
   1700         cvtColor( dst, color_dst, COLOR_GRAY2BGR );
   1701 
   1702     #if 0
   1703         vector<Vec2f> lines;
   1704         HoughLines( dst, lines, 1, CV_PI/180, 100 );
   1705 
   1706         for( size_t i = 0; i < lines.size(); i++ )
   1707         {
   1708             float rho = lines[i][0];
   1709             float theta = lines[i][1];
   1710             double a = cos(theta), b = sin(theta);
   1711             double x0 = a*rho, y0 = b*rho;
   1712             Point pt1(cvRound(x0 + 1000*(-b)),
   1713                       cvRound(y0 + 1000*(a)));
   1714             Point pt2(cvRound(x0 - 1000*(-b)),
   1715                       cvRound(y0 - 1000*(a)));
   1716             line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 );
   1717         }
   1718     #else
   1719         vector<Vec4i> lines;
   1720         HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
   1721         for( size_t i = 0; i < lines.size(); i++ )
   1722         {
   1723             line( color_dst, Point(lines[i][0], lines[i][1]),
   1724                 Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
   1725         }
   1726     #endif
   1727         namedWindow( "Source", 1 );
   1728         imshow( "Source", src );
   1729 
   1730         namedWindow( "Detected Lines", 1 );
   1731         imshow( "Detected Lines", color_dst );
   1732 
   1733         waitKey(0);
   1734         return 0;
   1735     }
   1736 @endcode
   1737 This is a sample picture the function parameters have been tuned for:
   1738 
   1739 ![image](pics/building.jpg)
   1740 
   1741 And this is the output of the above program in case of the probabilistic Hough transform:
   1742 
   1743 ![image](pics/houghp.png)
   1744 
   1745 @param image 8-bit, single-channel binary source image. The image may be modified by the function.
   1746 @param lines Output vector of lines. Each line is represented by a 4-element vector
   1747 \f$(x_1, y_1, x_2, y_2)\f$ , where \f$(x_1,y_1)\f$ and \f$(x_2, y_2)\f$ are the ending points of each detected
   1748 line segment.
   1749 @param rho Distance resolution of the accumulator in pixels.
   1750 @param theta Angle resolution of the accumulator in radians.
   1751 @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
   1752 votes ( \f$>\texttt{threshold}\f$ ).
   1753 @param minLineLength Minimum line length. Line segments shorter than that are rejected.
   1754 @param maxLineGap Maximum allowed gap between points on the same line to link them.
   1755 
   1756 @sa LineSegmentDetector
   1757  */
   1758 CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,
   1759                                double rho, double theta, int threshold,
   1760                                double minLineLength = 0, double maxLineGap = 0 );
   1761 
   1762 /** @example houghcircles.cpp
   1763 An example using the Hough circle detector
   1764 */
   1765 
   1766 /** @brief Finds circles in a grayscale image using the Hough transform.
   1767 
   1768 The function finds circles in a grayscale image using a modification of the Hough transform.
   1769 
   1770 Example: :
   1771 @code
   1772     #include <opencv2/imgproc.hpp>
   1773     #include <opencv2/highgui.hpp>
   1774     #include <math.h>
   1775 
   1776     using namespace cv;
   1777 
   1778     int main(int argc, char** argv)
   1779     {
   1780         Mat img, gray;
   1781         if( argc != 2 && !(img=imread(argv[1], 1)).data)
   1782             return -1;
   1783         cvtColor(img, gray, COLOR_BGR2GRAY);
   1784         // smooth it, otherwise a lot of false circles may be detected
   1785         GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
   1786         vector<Vec3f> circles;
   1787         HoughCircles(gray, circles, HOUGH_GRADIENT,
   1788                      2, gray->rows/4, 200, 100 );
   1789         for( size_t i = 0; i < circles.size(); i++ )
   1790         {
   1791              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
   1792              int radius = cvRound(circles[i][2]);
   1793              // draw the circle center
   1794              circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
   1795              // draw the circle outline
   1796              circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
   1797         }
   1798         namedWindow( "circles", 1 );
   1799         imshow( "circles", img );
   1800         return 0;
   1801     }
   1802 @endcode
   1803 
   1804 @note Usually the function detects the centers of circles well. However, it may fail to find correct
   1805 radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if
   1806 you know it. Or, you may ignore the returned radius, use only the center, and find the correct
   1807 radius using an additional procedure.
   1808 
   1809 @param image 8-bit, single-channel, grayscale input image.
   1810 @param circles Output vector of found circles. Each vector is encoded as a 3-element
   1811 floating-point vector \f$(x, y, radius)\f$ .
   1812 @param method Detection method, see cv::HoughModes. Currently, the only implemented method is HOUGH_GRADIENT
   1813 @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if
   1814 dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has
   1815 half as big width and height.
   1816 @param minDist Minimum distance between the centers of the detected circles. If the parameter is
   1817 too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is
   1818 too large, some circles may be missed.
   1819 @param param1 First method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the higher
   1820 threshold of the two passed to the Canny edge detector (the lower one is twice smaller).
   1821 @param param2 Second method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the
   1822 accumulator threshold for the circle centers at the detection stage. The smaller it is, the more
   1823 false circles may be detected. Circles, corresponding to the larger accumulator values, will be
   1824 returned first.
   1825 @param minRadius Minimum circle radius.
   1826 @param maxRadius Maximum circle radius.
   1827 
   1828 @sa fitEllipse, minEnclosingCircle
   1829  */
   1830 CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles,
   1831                                int method, double dp, double minDist,
   1832                                double param1 = 100, double param2 = 100,
   1833                                int minRadius = 0, int maxRadius = 0 );
   1834 
   1835 //! @} imgproc_feature
   1836 
   1837 //! @addtogroup imgproc_filter
   1838 //! @{
   1839 
   1840 /** @example morphology2.cpp
   1841   An example using the morphological operations
   1842 */
   1843 
   1844 /** @brief Erodes an image by using a specific structuring element.
   1845 
   1846 The function erodes the source image using the specified structuring element that determines the
   1847 shape of a pixel neighborhood over which the minimum is taken:
   1848 
   1849 \f[\texttt{dst} (x,y) =  \min _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
   1850 
   1851 The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In
   1852 case of multi-channel images, each channel is processed independently.
   1853 
   1854 @param src input image; the number of channels can be arbitrary, but the depth should be one of
   1855 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
   1856 @param dst output image of the same size and type as src.
   1857 @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
   1858 structuring element is used. Kernel can be created using getStructuringElement.
   1859 @param anchor position of the anchor within the element; default value (-1, -1) means that the
   1860 anchor is at the element center.
   1861 @param iterations number of times erosion is applied.
   1862 @param borderType pixel extrapolation method, see cv::BorderTypes
   1863 @param borderValue border value in case of a constant border
   1864 @sa  dilate, morphologyEx, getStructuringElement
   1865  */
   1866 CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
   1867                          Point anchor = Point(-1,-1), int iterations = 1,
   1868                          int borderType = BORDER_CONSTANT,
   1869                          const Scalar& borderValue = morphologyDefaultBorderValue() );
   1870 
   1871 /** @brief Dilates an image by using a specific structuring element.
   1872 
   1873 The function dilates the source image using the specified structuring element that determines the
   1874 shape of a pixel neighborhood over which the maximum is taken:
   1875 \f[\texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
   1876 
   1877 The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In
   1878 case of multi-channel images, each channel is processed independently.
   1879 
   1880 @param src input image; the number of channels can be arbitrary, but the depth should be one of
   1881 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
   1882 @param dst output image of the same size and type as src\`.
   1883 @param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
   1884 structuring element is used. Kernel can be created using getStructuringElement
   1885 @param anchor position of the anchor within the element; default value (-1, -1) means that the
   1886 anchor is at the element center.
   1887 @param iterations number of times dilation is applied.
   1888 @param borderType pixel extrapolation method, see cv::BorderTypes
   1889 @param borderValue border value in case of a constant border
   1890 @sa  erode, morphologyEx, getStructuringElement
   1891  */
   1892 CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
   1893                           Point anchor = Point(-1,-1), int iterations = 1,
   1894                           int borderType = BORDER_CONSTANT,
   1895                           const Scalar& borderValue = morphologyDefaultBorderValue() );
   1896 
   1897 /** @brief Performs advanced morphological transformations.
   1898 
   1899 The function can perform advanced morphological transformations using an erosion and dilation as
   1900 basic operations.
   1901 
   1902 Any of the operations can be done in-place. In case of multi-channel images, each channel is
   1903 processed independently.
   1904 
   1905 @param src Source image. The number of channels can be arbitrary. The depth should be one of
   1906 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
   1907 @param dst Destination image of the same size and type as  src\` .
   1908 @param kernel Structuring element. It can be created using getStructuringElement.
   1909 @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the
   1910 kernel center.
   1911 @param op Type of a morphological operation, see cv::MorphTypes
   1912 @param iterations Number of times erosion and dilation are applied.
   1913 @param borderType Pixel extrapolation method, see cv::BorderTypes
   1914 @param borderValue Border value in case of a constant border. The default value has a special
   1915 meaning.
   1916 @sa  dilate, erode, getStructuringElement
   1917  */
   1918 CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
   1919                                 int op, InputArray kernel,
   1920                                 Point anchor = Point(-1,-1), int iterations = 1,
   1921                                 int borderType = BORDER_CONSTANT,
   1922                                 const Scalar& borderValue = morphologyDefaultBorderValue() );
   1923 
   1924 //! @} imgproc_filter
   1925 
   1926 //! @addtogroup imgproc_transform
   1927 //! @{
   1928 
   1929 /** @brief Resizes an image.
   1930 
   1931 The function resize resizes the image src down to or up to the specified size. Note that the
   1932 initial dst type or size are not taken into account. Instead, the size and type are derived from
   1933 the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst,
   1934 you may call the function as follows:
   1935 @code
   1936     // explicitly specify dsize=dst.size(); fx and fy will be computed from that.
   1937     resize(src, dst, dst.size(), 0, 0, interpolation);
   1938 @endcode
   1939 If you want to decimate the image by factor of 2 in each direction, you can call the function this
   1940 way:
   1941 @code
   1942     // specify fx and fy and let the function compute the destination image size.
   1943     resize(src, dst, Size(), 0.5, 0.5, interpolation);
   1944 @endcode
   1945 To shrink an image, it will generally look best with CV_INTER_AREA interpolation, whereas to
   1946 enlarge an image, it will generally look best with CV_INTER_CUBIC (slow) or CV_INTER_LINEAR
   1947 (faster but still looks OK).
   1948 
   1949 @param src input image.
   1950 @param dst output image; it has the size dsize (when it is non-zero) or the size computed from
   1951 src.size(), fx, and fy; the type of dst is the same as of src.
   1952 @param dsize output image size; if it equals zero, it is computed as:
   1953  \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
   1954  Either dsize or both fx and fy must be non-zero.
   1955 @param fx scale factor along the horizontal axis; when it equals 0, it is computed as
   1956 \f[\texttt{(double)dsize.width/src.cols}\f]
   1957 @param fy scale factor along the vertical axis; when it equals 0, it is computed as
   1958 \f[\texttt{(double)dsize.height/src.rows}\f]
   1959 @param interpolation interpolation method, see cv::InterpolationFlags
   1960 
   1961 @sa  warpAffine, warpPerspective, remap
   1962  */
   1963 CV_EXPORTS_W void resize( InputArray src, OutputArray dst,
   1964                           Size dsize, double fx = 0, double fy = 0,
   1965                           int interpolation = INTER_LINEAR );
   1966 
   1967 /** @brief Applies an affine transformation to an image.
   1968 
   1969 The function warpAffine transforms the source image using the specified matrix:
   1970 
   1971 \f[\texttt{dst} (x,y) =  \texttt{src} ( \texttt{M} _{11} x +  \texttt{M} _{12} y +  \texttt{M} _{13}, \texttt{M} _{21} x +  \texttt{M} _{22} y +  \texttt{M} _{23})\f]
   1972 
   1973 when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted
   1974 with cv::invertAffineTransform and then put in the formula above instead of M. The function cannot
   1975 operate in-place.
   1976 
   1977 @param src input image.
   1978 @param dst output image that has the size dsize and the same type as src .
   1979 @param M \f$2\times 3\f$ transformation matrix.
   1980 @param dsize size of the output image.
   1981 @param flags combination of interpolation methods (see cv::InterpolationFlags) and the optional
   1982 flag WARP_INVERSE_MAP that means that M is the inverse transformation (
   1983 \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
   1984 @param borderMode pixel extrapolation method (see cv::BorderTypes); when
   1985 borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to
   1986 the "outliers" in the source image are not modified by the function.
   1987 @param borderValue value used in case of a constant border; by default, it is 0.
   1988 
   1989 @sa  warpPerspective, resize, remap, getRectSubPix, transform
   1990  */
   1991 CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,
   1992                               InputArray M, Size dsize,
   1993                               int flags = INTER_LINEAR,
   1994                               int borderMode = BORDER_CONSTANT,
   1995                               const Scalar& borderValue = Scalar());
   1996 
   1997 /** @brief Applies a perspective transformation to an image.
   1998 
   1999 The function warpPerspective transforms the source image using the specified matrix:
   2000 
   2001 \f[\texttt{dst} (x,y) =  \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
   2002      \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f]
   2003 
   2004 when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert
   2005 and then put in the formula above instead of M. The function cannot operate in-place.
   2006 
   2007 @param src input image.
   2008 @param dst output image that has the size dsize and the same type as src .
   2009 @param M \f$3\times 3\f$ transformation matrix.
   2010 @param dsize size of the output image.
   2011 @param flags combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the
   2012 optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (
   2013 \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
   2014 @param borderMode pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).
   2015 @param borderValue value used in case of a constant border; by default, it equals 0.
   2016 
   2017 @sa  warpAffine, resize, remap, getRectSubPix, perspectiveTransform
   2018  */
   2019 CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst,
   2020                                    InputArray M, Size dsize,
   2021                                    int flags = INTER_LINEAR,
   2022                                    int borderMode = BORDER_CONSTANT,
   2023                                    const Scalar& borderValue = Scalar());
   2024 
   2025 /** @brief Applies a generic geometrical transformation to an image.
   2026 
   2027 The function remap transforms the source image using the specified map:
   2028 
   2029 \f[\texttt{dst} (x,y) =  \texttt{src} (map_x(x,y),map_y(x,y))\f]
   2030 
   2031 where values of pixels with non-integer coordinates are computed using one of available
   2032 interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps
   2033 in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in
   2034 \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to
   2035 convert from floating to fixed-point representations of a map is that they can yield much faster
   2036 (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),
   2037 cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.
   2038 
   2039 This function cannot operate in-place.
   2040 
   2041 @param src Source image.
   2042 @param dst Destination image. It has the same size as map1 and the same type as src .
   2043 @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 ,
   2044 CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point
   2045 representation to fixed-point for speed.
   2046 @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map
   2047 if map1 is (x,y) points), respectively.
   2048 @param interpolation Interpolation method (see cv::InterpolationFlags). The method INTER_AREA is
   2049 not supported by this function.
   2050 @param borderMode Pixel extrapolation method (see cv::BorderTypes). When
   2051 borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that
   2052 corresponds to the "outliers" in the source image are not modified by the function.
   2053 @param borderValue Value used in case of a constant border. By default, it is 0.
   2054  */
   2055 CV_EXPORTS_W void remap( InputArray src, OutputArray dst,
   2056                          InputArray map1, InputArray map2,
   2057                          int interpolation, int borderMode = BORDER_CONSTANT,
   2058                          const Scalar& borderValue = Scalar());
   2059 
   2060 /** @brief Converts image transformation maps from one representation to another.
   2061 
   2062 The function converts a pair of maps for remap from one representation to another. The following
   2063 options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are
   2064 supported:
   2065 
   2066 - \f$\texttt{(CV\_32FC1, CV\_32FC1)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}\f$. This is the
   2067 most frequently used conversion operation, in which the original floating-point maps (see remap )
   2068 are converted to a more compact and much faster fixed-point representation. The first output array
   2069 contains the rounded coordinates and the second array (created only when nninterpolation=false )
   2070 contains indices in the interpolation tables.
   2071 
   2072 - \f$\texttt{(CV\_32FC2)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}\f$. The same as above but
   2073 the original maps are stored in one 2-channel matrix.
   2074 
   2075 - Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same
   2076 as the originals.
   2077 
   2078 @param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 .
   2079 @param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix),
   2080 respectively.
   2081 @param dstmap1 The first output map that has the type dstmap1type and the same size as src .
   2082 @param dstmap2 The second output map.
   2083 @param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or
   2084 CV_32FC2 .
   2085 @param nninterpolation Flag indicating whether the fixed-point maps are used for the
   2086 nearest-neighbor or for a more complex interpolation.
   2087 
   2088 @sa  remap, undistort, initUndistortRectifyMap
   2089  */
   2090 CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2,
   2091                                OutputArray dstmap1, OutputArray dstmap2,
   2092                                int dstmap1type, bool nninterpolation = false );
   2093 
   2094 /** @brief Calculates an affine matrix of 2D rotation.
   2095 
   2096 The function calculates the following matrix:
   2097 
   2098 \f[\begin{bmatrix} \alpha &  \beta & (1- \alpha )  \cdot \texttt{center.x} -  \beta \cdot \texttt{center.y} \\ - \beta &  \alpha &  \beta \cdot \texttt{center.x} + (1- \alpha )  \cdot \texttt{center.y} \end{bmatrix}\f]
   2099 
   2100 where
   2101 
   2102 \f[\begin{array}{l} \alpha =  \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta =  \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f]
   2103 
   2104 The transformation maps the rotation center to itself. If this is not the target, adjust the shift.
   2105 
   2106 @param center Center of the rotation in the source image.
   2107 @param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the
   2108 coordinate origin is assumed to be the top-left corner).
   2109 @param scale Isotropic scale factor.
   2110 
   2111 @sa  getAffineTransform, warpAffine, transform
   2112  */
   2113 CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale );
   2114 
   2115 //! returns 3x3 perspective transformation for the corresponding 4 point pairs.
   2116 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
   2117 
   2118 /** @brief Calculates an affine transform from three pairs of the corresponding points.
   2119 
   2120 The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that:
   2121 
   2122 \f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]
   2123 
   2124 where
   2125 
   2126 \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f]
   2127 
   2128 @param src Coordinates of triangle vertices in the source image.
   2129 @param dst Coordinates of the corresponding triangle vertices in the destination image.
   2130 
   2131 @sa  warpAffine, transform
   2132  */
   2133 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
   2134 
   2135 /** @brief Inverts an affine transformation.
   2136 
   2137 The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M:
   2138 
   2139 \f[\begin{bmatrix} a_{11} & a_{12} & b_1  \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f]
   2140 
   2141 The result is also a \f$2 \times 3\f$ matrix of the same type as M.
   2142 
   2143 @param M Original affine transformation.
   2144 @param iM Output reverse affine transformation.
   2145  */
   2146 CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );
   2147 
   2148 /** @brief Calculates a perspective transform from four pairs of the corresponding points.
   2149 
   2150 The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that:
   2151 
   2152 \f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]
   2153 
   2154 where
   2155 
   2156 \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f]
   2157 
   2158 @param src Coordinates of quadrangle vertices in the source image.
   2159 @param dst Coordinates of the corresponding quadrangle vertices in the destination image.
   2160 
   2161 @sa  findHomography, warpPerspective, perspectiveTransform
   2162  */
   2163 CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst );
   2164 
   2165 CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
   2166 
   2167 /** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy.
   2168 
   2169 The function getRectSubPix extracts pixels from src:
   2170 
   2171 \f[dst(x, y) = src(x +  \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y +  \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f]
   2172 
   2173 where the values of the pixels at non-integer coordinates are retrieved using bilinear
   2174 interpolation. Every channel of multi-channel images is processed independently. While the center of
   2175 the rectangle must be inside the image, parts of the rectangle may be outside. In this case, the
   2176 replication border mode (see cv::BorderTypes) is used to extrapolate the pixel values outside of
   2177 the image.
   2178 
   2179 @param image Source image.
   2180 @param patchSize Size of the extracted patch.
   2181 @param center Floating point coordinates of the center of the extracted rectangle within the
   2182 source image. The center must be inside the image.
   2183 @param patch Extracted patch that has the size patchSize and the same number of channels as src .
   2184 @param patchType Depth of the extracted pixels. By default, they have the same depth as src .
   2185 
   2186 @sa  warpAffine, warpPerspective
   2187  */
   2188 CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
   2189                                  Point2f center, OutputArray patch, int patchType = -1 );
   2190 
   2191 /** @example polar_transforms.cpp
   2192 An example using the cv::linearPolar and cv::logPolar operations
   2193 */
   2194 
   2195 /** @brief Remaps an image to log-polar space.
   2196 
   2197 transforms the source image using the following transformation:
   2198 \f[dst( \phi , \rho ) = src(x,y)\f]
   2199 where
   2200 \f[\rho = M  \cdot \log{\sqrt{x^2 + y^2}} , \phi =atan(y/x)\f]
   2201 
   2202 The function emulates the human "foveal" vision and can be used for fast scale and
   2203 rotation-invariant template matching, for object tracking and so forth. The function can not operate
   2204 in-place.
   2205 
   2206 @param src Source image
   2207 @param dst Destination image
   2208 @param center The transformation center; where the output precision is maximal
   2209 @param M Magnitude scale parameter.
   2210 @param flags A combination of interpolation methods, see cv::InterpolationFlags
   2211  */
   2212 CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,
   2213                             Point2f center, double M, int flags );
   2214 
   2215 /** @brief Remaps an image to polar space.
   2216 
   2217 transforms the source image using the following transformation:
   2218 \f[dst( \phi , \rho ) = src(x,y)\f]
   2219 where
   2220 \f[\rho = (src.width/maxRadius)  \cdot \sqrt{x^2 + y^2} , \phi =atan(y/x)\f]
   2221 
   2222 The function can not operate in-place.
   2223 
   2224 @param src Source image
   2225 @param dst Destination image
   2226 @param center The transformation center;
   2227 @param maxRadius Inverse magnitude scale parameter
   2228 @param flags A combination of interpolation methods, see cv::InterpolationFlags
   2229  */
   2230 CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,
   2231                                Point2f center, double maxRadius, int flags );
   2232 
   2233 //! @} imgproc_transform
   2234 
   2235 //! @addtogroup imgproc_misc
   2236 //! @{
   2237 
   2238 /** @overload */
   2239 CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );
   2240 
   2241 /** @overload */
   2242 CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,
   2243                                         OutputArray sqsum, int sdepth = -1, int sqdepth = -1 );
   2244 
   2245 /** @brief Calculates the integral of an image.
   2246 
   2247 The functions calculate one or more integral images for the source image as follows:
   2248 
   2249 \f[\texttt{sum} (X,Y) =  \sum _{x<X,y<Y}  \texttt{image} (x,y)\f]
   2250 
   2251 \f[\texttt{sqsum} (X,Y) =  \sum _{x<X,y<Y}  \texttt{image} (x,y)^2\f]
   2252 
   2253 \f[\texttt{tilted} (X,Y) =  \sum _{y<Y,abs(x-X+1) \leq Y-y-1}  \texttt{image} (x,y)\f]
   2254 
   2255 Using these integral images, you can calculate sum, mean, and standard deviation over a specific
   2256 up-right or rotated rectangular region of the image in a constant time, for example:
   2257 
   2258 \f[\sum _{x_1 \leq x < x_2,  \, y_1  \leq y < y_2}  \texttt{image} (x,y) =  \texttt{sum} (x_2,y_2)- \texttt{sum} (x_1,y_2)- \texttt{sum} (x_2,y_1)+ \texttt{sum} (x_1,y_1)\f]
   2259 
   2260 It makes possible to do a fast blurring or fast block correlation with a variable window size, for
   2261 example. In case of multi-channel images, sums for each channel are accumulated independently.
   2262 
   2263 As a practical example, the next figure shows the calculation of the integral of a straight
   2264 rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the
   2265 original image are shown, as well as the relative pixels in the integral images sum and tilted .
   2266 
   2267 ![integral calculation example](pics/integral.png)
   2268 
   2269 @param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f).
   2270 @param sum integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f).
   2271 @param sqsum integral image for squared pixel values; it is \f$(W+1)\times (H+1)\f$, double-precision
   2272 floating-point (64f) array.
   2273 @param tilted integral for the image rotated by 45 degrees; it is \f$(W+1)\times (H+1)\f$ array with
   2274 the same data type as sum.
   2275 @param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or
   2276 CV_64F.
   2277 @param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.
   2278  */
   2279 CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum,
   2280                                         OutputArray sqsum, OutputArray tilted,
   2281                                         int sdepth = -1, int sqdepth = -1 );
   2282 
   2283 //! @} imgproc_misc
   2284 
   2285 //! @addtogroup imgproc_motion
   2286 //! @{
   2287 
   2288 /** @brief Adds an image to the accumulator.
   2289 
   2290 The function adds src or some of its elements to dst :
   2291 
   2292 \f[\texttt{dst} (x,y)  \leftarrow \texttt{dst} (x,y) +  \texttt{src} (x,y)  \quad \text{if} \quad \texttt{mask} (x,y)  \ne 0\f]
   2293 
   2294 The function supports multi-channel images. Each channel is processed independently.
   2295 
   2296 The functions accumulate\* can be used, for example, to collect statistics of a scene background
   2297 viewed by a still camera and for the further foreground-background segmentation.
   2298 
   2299 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
   2300 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit
   2301 floating-point.
   2302 @param mask Optional operation mask.
   2303 
   2304 @sa  accumulateSquare, accumulateProduct, accumulateWeighted
   2305  */
   2306 CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,
   2307                               InputArray mask = noArray() );
   2308 
   2309 /** @brief Adds the square of a source image to the accumulator.
   2310 
   2311 The function adds the input image src or its selected region, raised to a power of 2, to the
   2312 accumulator dst :
   2313 
   2314 \f[\texttt{dst} (x,y)  \leftarrow \texttt{dst} (x,y) +  \texttt{src} (x,y)^2  \quad \text{if} \quad \texttt{mask} (x,y)  \ne 0\f]
   2315 
   2316 The function supports multi-channel images. Each channel is processed independently.
   2317 
   2318 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
   2319 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit
   2320 floating-point.
   2321 @param mask Optional operation mask.
   2322 
   2323 @sa  accumulateSquare, accumulateProduct, accumulateWeighted
   2324  */
   2325 CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst,
   2326                                     InputArray mask = noArray() );
   2327 
   2328 /** @brief Adds the per-element product of two input images to the accumulator.
   2329 
   2330 The function adds the product of two images or their selected regions to the accumulator dst :
   2331 
   2332 \f[\texttt{dst} (x,y)  \leftarrow \texttt{dst} (x,y) +  \texttt{src1} (x,y)  \cdot \texttt{src2} (x,y)  \quad \text{if} \quad \texttt{mask} (x,y)  \ne 0\f]
   2333 
   2334 The function supports multi-channel images. Each channel is processed independently.
   2335 
   2336 @param src1 First input image, 1- or 3-channel, 8-bit or 32-bit floating point.
   2337 @param src2 Second input image of the same type and the same size as src1 .
   2338 @param dst %Accumulator with the same number of channels as input images, 32-bit or 64-bit
   2339 floating-point.
   2340 @param mask Optional operation mask.
   2341 
   2342 @sa  accumulate, accumulateSquare, accumulateWeighted
   2343  */
   2344 CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,
   2345                                      InputOutputArray dst, InputArray mask=noArray() );
   2346 
   2347 /** @brief Updates a running average.
   2348 
   2349 The function calculates the weighted sum of the input image src and the accumulator dst so that dst
   2350 becomes a running average of a frame sequence:
   2351 
   2352 \f[\texttt{dst} (x,y)  \leftarrow (1- \texttt{alpha} )  \cdot \texttt{dst} (x,y) +  \texttt{alpha} \cdot \texttt{src} (x,y)  \quad \text{if} \quad \texttt{mask} (x,y)  \ne 0\f]
   2353 
   2354 That is, alpha regulates the update speed (how fast the accumulator "forgets" about earlier images).
   2355 The function supports multi-channel images. Each channel is processed independently.
   2356 
   2357 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
   2358 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit
   2359 floating-point.
   2360 @param alpha Weight of the input image.
   2361 @param mask Optional operation mask.
   2362 
   2363 @sa  accumulate, accumulateSquare, accumulateProduct
   2364  */
   2365 CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
   2366                                       double alpha, InputArray mask = noArray() );
   2367 
   2368 /** @brief The function is used to detect translational shifts that occur between two images.
   2369 
   2370 The operation takes advantage of the Fourier shift theorem for detecting the translational shift in
   2371 the frequency domain. It can be used for fast image registration as well as motion estimation. For
   2372 more information please see <http://en.wikipedia.org/wiki/Phase_correlation>
   2373 
   2374 Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed
   2375 with getOptimalDFTSize.
   2376 
   2377 The function performs the following equations:
   2378 - First it applies a Hanning window (see <http://en.wikipedia.org/wiki/Hann_function>) to each
   2379 image to remove possible edge effects. This window is cached until the array size changes to speed
   2380 up processing time.
   2381 - Next it computes the forward DFTs of each source array:
   2382 \f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f]
   2383 where \f$\mathcal{F}\f$ is the forward DFT.
   2384 - It then computes the cross-power spectrum of each frequency domain array:
   2385 \f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f]
   2386 - Next the cross-correlation is converted back into the time domain via the inverse DFT:
   2387 \f[r = \mathcal{F}^{-1}\{R\}\f]
   2388 - Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to
   2389 achieve sub-pixel accuracy.
   2390 \f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f]
   2391 - If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5
   2392 centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single
   2393 peak) and will be smaller when there are multiple peaks.
   2394 
   2395 @param src1 Source floating point array (CV_32FC1 or CV_64FC1)
   2396 @param src2 Source floating point array (CV_32FC1 or CV_64FC1)
   2397 @param window Floating point array with windowing coefficients to reduce edge effects (optional).
   2398 @param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional).
   2399 @returns detected phase shift (sub-pixel) between the two arrays.
   2400 
   2401 @sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow
   2402  */
   2403 CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2,
   2404                                     InputArray window = noArray(), CV_OUT double* response = 0);
   2405 
   2406 /** @brief This function computes a Hanning window coefficients in two dimensions.
   2407 
   2408 See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function)
   2409 for more information.
   2410 
   2411 An example is shown below:
   2412 @code
   2413     // create hanning window of size 100x100 and type CV_32F
   2414     Mat hann;
   2415     createHanningWindow(hann, Size(100, 100), CV_32F);
   2416 @endcode
   2417 @param dst Destination array to place Hann coefficients in
   2418 @param winSize The window size specifications
   2419 @param type Created array type
   2420  */
   2421 CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);
   2422 
   2423 //! @} imgproc_motion
   2424 
   2425 //! @addtogroup imgproc_misc
   2426 //! @{
   2427 
   2428 /** @brief Applies a fixed-level threshold to each array element.
   2429 
   2430 The function applies fixed-level thresholding to a single-channel array. The function is typically
   2431 used to get a bi-level (binary) image out of a grayscale image ( cv::compare could be also used for
   2432 this purpose) or for removing a noise, that is, filtering out pixels with too small or too large
   2433 values. There are several types of thresholding supported by the function. They are determined by
   2434 type parameter.
   2435 
   2436 Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the
   2437 above values. In these cases, the function determines the optimal threshold value using the Otsu's
   2438 or Triangle algorithm and uses it instead of the specified thresh . The function returns the
   2439 computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit
   2440 images.
   2441 
   2442 @param src input array (single-channel, 8-bit or 32-bit floating point).
   2443 @param dst output array of the same size and type as src.
   2444 @param thresh threshold value.
   2445 @param maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding
   2446 types.
   2447 @param type thresholding type (see the cv::ThresholdTypes).
   2448 
   2449 @sa  adaptiveThreshold, findContours, compare, min, max
   2450  */
   2451 CV_EXPORTS_W double threshold( InputArray src, OutputArray dst,
   2452                                double thresh, double maxval, int type );
   2453 
   2454 
   2455 /** @brief Applies an adaptive threshold to an array.
   2456 
   2457 The function transforms a grayscale image to a binary image according to the formulae:
   2458 -   **THRESH_BINARY**
   2459     \f[dst(x,y) =  \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f]
   2460 -   **THRESH_BINARY_INV**
   2461     \f[dst(x,y) =  \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f]
   2462 where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter).
   2463 
   2464 The function can process the image in-place.
   2465 
   2466 @param src Source 8-bit single-channel image.
   2467 @param dst Destination image of the same size and the same type as src.
   2468 @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
   2469 @param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes
   2470 @param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV,
   2471 see cv::ThresholdTypes.
   2472 @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the
   2473 pixel: 3, 5, 7, and so on.
   2474 @param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it
   2475 is positive but may be zero or negative as well.
   2476 
   2477 @sa  threshold, blur, GaussianBlur
   2478  */
   2479 CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst,
   2480                                      double maxValue, int adaptiveMethod,
   2481                                      int thresholdType, int blockSize, double C );
   2482 
   2483 //! @} imgproc_misc
   2484 
   2485 //! @addtogroup imgproc_filter
   2486 //! @{
   2487 
   2488 /** @brief Blurs an image and downsamples it.
   2489 
   2490 By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in
   2491 any case, the following conditions should be satisfied:
   2492 
   2493 \f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f]
   2494 
   2495 The function performs the downsampling step of the Gaussian pyramid construction. First, it
   2496 convolves the source image with the kernel:
   2497 
   2498 \f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1  \\ 4 & 16 & 24 & 16 & 4  \\ 6 & 24 & 36 & 24 & 6  \\ 4 & 16 & 24 & 16 & 4  \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f]
   2499 
   2500 Then, it downsamples the image by rejecting even rows and columns.
   2501 
   2502 @param src input image.
   2503 @param dst output image; it has the specified size and the same type as src.
   2504 @param dstsize size of the output image.
   2505 @param borderType Pixel extrapolation method, see cv::BorderTypes (BORDER_CONSTANT isn't supported)
   2506  */
   2507 CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst,
   2508                            const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );
   2509 
   2510 /** @brief Upsamples an image and then blurs it.
   2511 
   2512 By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any
   2513 case, the following conditions should be satisfied:
   2514 
   2515 \f[\begin{array}{l} | \texttt{dstsize.width} -src.cols*2| \leq  ( \texttt{dstsize.width}   \mod  2)  \\ | \texttt{dstsize.height} -src.rows*2| \leq  ( \texttt{dstsize.height}   \mod  2) \end{array}\f]
   2516 
   2517 The function performs the upsampling step of the Gaussian pyramid construction, though it can
   2518 actually be used to construct the Laplacian pyramid. First, it upsamples the source image by
   2519 injecting even zero rows and columns and then convolves the result with the same kernel as in
   2520 pyrDown multiplied by 4.
   2521 
   2522 @param src input image.
   2523 @param dst output image. It has the specified size and the same type as src .
   2524 @param dstsize size of the output image.
   2525 @param borderType Pixel extrapolation method, see cv::BorderTypes (only BORDER_DEFAULT is supported)
   2526  */
   2527 CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst,
   2528                          const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );
   2529 
   2530 /** @brief Constructs the Gaussian pyramid for an image.
   2531 
   2532 The function constructs a vector of images and builds the Gaussian pyramid by recursively applying
   2533 pyrDown to the previously built pyramid layers, starting from `dst[0]==src`.
   2534 
   2535 @param src Source image. Check pyrDown for the list of supported types.
   2536 @param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the
   2537 same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on.
   2538 @param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative.
   2539 @param borderType Pixel extrapolation method, see cv::BorderTypes (BORDER_CONSTANT isn't supported)
   2540  */
   2541 CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst,
   2542                               int maxlevel, int borderType = BORDER_DEFAULT );
   2543 
   2544 //! @} imgproc_filter
   2545 
   2546 //! @addtogroup imgproc_transform
   2547 //! @{
   2548 
   2549 /** @brief Transforms an image to compensate for lens distortion.
   2550 
   2551 The function transforms an image to compensate radial and tangential lens distortion.
   2552 
   2553 The function is simply a combination of cv::initUndistortRectifyMap (with unity R ) and cv::remap
   2554 (with bilinear interpolation). See the former function for details of the transformation being
   2555 performed.
   2556 
   2557 Those pixels in the destination image, for which there is no correspondent pixels in the source
   2558 image, are filled with zeros (black color).
   2559 
   2560 A particular subset of the source image that will be visible in the corrected image can be regulated
   2561 by newCameraMatrix. You can use cv::getOptimalNewCameraMatrix to compute the appropriate
   2562 newCameraMatrix depending on your requirements.
   2563 
   2564 The camera matrix and the distortion parameters can be determined using cv::calibrateCamera. If
   2565 the resolution of images is different from the resolution used at the calibration stage, \f$f_x,
   2566 f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain
   2567 the same.
   2568 
   2569 @param src Input (distorted) image.
   2570 @param dst Output (corrected) image that has the same size and type as src .
   2571 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
   2572 @param distCoeffs Input vector of distortion coefficients
   2573 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])\f$ of 4, 5, or 8 elements. If the vector is
   2574 NULL/empty, the zero distortion coefficients are assumed.
   2575 @param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as
   2576 cameraMatrix but you may additionally scale and shift the result by using a different matrix.
   2577  */
   2578 CV_EXPORTS_W void undistort( InputArray src, OutputArray dst,
   2579                              InputArray cameraMatrix,
   2580                              InputArray distCoeffs,
   2581                              InputArray newCameraMatrix = noArray() );
   2582 
   2583 /** @brief Computes the undistortion and rectification transformation map.
   2584 
   2585 The function computes the joint undistortion and rectification transformation and represents the
   2586 result in the form of maps for remap. The undistorted image looks like original, as if it is
   2587 captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a
   2588 monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by
   2589 cv::getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera,
   2590 newCameraMatrix is normally set to P1 or P2 computed by cv::stereoRectify .
   2591 
   2592 Also, this new camera is oriented differently in the coordinate space, according to R. That, for
   2593 example, helps to align two heads of a stereo camera so that the epipolar lines on both images
   2594 become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera).
   2595 
   2596 The function actually builds the maps for the inverse mapping algorithm that is used by remap. That
   2597 is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function
   2598 computes the corresponding coordinates in the source image (that is, in the original image from
   2599 camera). The following process is applied:
   2600 \f[\begin{array}{l} x  \leftarrow (u - {c'}_x)/{f'}_x  \\ y  \leftarrow (v - {c'}_y)/{f'}_y  \\{[X\,Y\,W]} ^T  \leftarrow R^{-1}*[x \, y \, 1]^T  \\ x'  \leftarrow X/W  \\ y'  \leftarrow Y/W  \\ x"  \leftarrow x' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 x' y' + p_2(r^2 + 2 x'^2)  \\ y"  \leftarrow y' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y'  \\ map_x(u,v)  \leftarrow x" f_x + c_x  \\ map_y(u,v)  \leftarrow y" f_y + c_y \end{array}\f]
   2601 where \f$(k_1, k_2, p_1, p_2[, k_3])\f$ are the distortion coefficients.
   2602 
   2603 In case of a stereo camera, this function is called twice: once for each camera head, after
   2604 stereoRectify, which in its turn is called after cv::stereoCalibrate. But if the stereo camera
   2605 was not calibrated, it is still possible to compute the rectification transformations directly from
   2606 the fundamental matrix using cv::stereoRectifyUncalibrated. For each camera, the function computes
   2607 homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D
   2608 space. R can be computed from H as
   2609 \f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f]
   2610 where cameraMatrix can be chosen arbitrarily.
   2611 
   2612 @param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
   2613 @param distCoeffs Input vector of distortion coefficients
   2614 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])\f$ of 4, 5, or 8 elements. If the vector is
   2615 NULL/empty, the zero distortion coefficients are assumed.
   2616 @param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 ,
   2617 computed by stereoRectify can be passed here. If the matrix is empty, the identity transformation
   2618 is assumed. In cvInitUndistortMap R assumed to be an identity matrix.
   2619 @param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$.
   2620 @param size Undistorted image size.
   2621 @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2, see cv::convertMaps
   2622 @param map1 The first output map.
   2623 @param map2 The second output map.
   2624  */
   2625 CV_EXPORTS_W void initUndistortRectifyMap( InputArray cameraMatrix, InputArray distCoeffs,
   2626                            InputArray R, InputArray newCameraMatrix,
   2627                            Size size, int m1type, OutputArray map1, OutputArray map2 );
   2628 
   2629 //! initializes maps for cv::remap() for wide-angle
   2630 CV_EXPORTS_W float initWideAngleProjMap( InputArray cameraMatrix, InputArray distCoeffs,
   2631                                          Size imageSize, int destImageWidth,
   2632                                          int m1type, OutputArray map1, OutputArray map2,
   2633                                          int projType = PROJ_SPHERICAL_EQRECT, double alpha = 0);
   2634 
   2635 /** @brief Returns the default new camera matrix.
   2636 
   2637 The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when
   2638 centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true).
   2639 
   2640 In the latter case, the new camera matrix will be:
   2641 
   2642 \f[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5  \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5  \\ 0 && 0 && 1 \end{bmatrix} ,\f]
   2643 
   2644 where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively.
   2645 
   2646 By default, the undistortion functions in OpenCV (see initUndistortRectifyMap, undistort) do not
   2647 move the principal point. However, when you work with stereo, it is important to move the principal
   2648 points in both views to the same y-coordinate (which is required by most of stereo correspondence
   2649 algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for
   2650 each view where the principal points are located at the center.
   2651 
   2652 @param cameraMatrix Input camera matrix.
   2653 @param imgsize Camera view image size in pixels.
   2654 @param centerPrincipalPoint Location of the principal point in the new camera matrix. The
   2655 parameter indicates whether this location should be at the image center or not.
   2656  */
   2657 CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsize = Size(),
   2658                                             bool centerPrincipalPoint = false );
   2659 
   2660 /** @brief Computes the ideal point coordinates from the observed point coordinates.
   2661 
   2662 The function is similar to cv::undistort and cv::initUndistortRectifyMap but it operates on a
   2663 sparse set of points instead of a raster image. Also the function performs a reverse transformation
   2664 to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a
   2665 planar object, it does, up to a translation vector, if the proper R is specified.
   2666 @code
   2667     // (u,v) is the input point, (u', v') is the output point
   2668     // camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1]
   2669     // P=[fx' 0 cx' tx; 0 fy' cy' ty; 0 0 1 tz]
   2670     x" = (u - cx)/fx
   2671     y" = (v - cy)/fy
   2672     (x',y') = undistort(x",y",dist_coeffs)
   2673     [X,Y,W]T = R*[x' y' 1]T
   2674     x = X/W, y = Y/W
   2675     // only performed if P=[fx' 0 cx' [tx]; 0 fy' cy' [ty]; 0 0 1 [tz]] is specified
   2676     u' = x*fx' + cx'
   2677     v' = y*fy' + cy',
   2678 @endcode
   2679 where cv::undistort is an approximate iterative algorithm that estimates the normalized original
   2680 point coordinates out of the normalized distorted point coordinates ("normalized" means that the
   2681 coordinates do not depend on the camera matrix).
   2682 
   2683 The function can be used for both a stereo camera head or a monocular camera (when R is empty).
   2684 
   2685 @param src Observed point coordinates, 1xN or Nx1 2-channel (CV_32FC2 or CV_64FC2).
   2686 @param dst Output ideal point coordinates after undistortion and reverse perspective
   2687 transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates.
   2688 @param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
   2689 @param distCoeffs Input vector of distortion coefficients
   2690 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]])\f$ of 4, 5, or 8 elements. If the vector is
   2691 NULL/empty, the zero distortion coefficients are assumed.
   2692 @param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by
   2693 cv::stereoRectify can be passed here. If the matrix is empty, the identity transformation is used.
   2694 @param P New camera matrix (3x3) or new projection matrix (3x4). P1 or P2 computed by
   2695 cv::stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used.
   2696  */
   2697 CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst,
   2698                                    InputArray cameraMatrix, InputArray distCoeffs,
   2699                                    InputArray R = noArray(), InputArray P = noArray());
   2700 
   2701 //! @} imgproc_transform
   2702 
   2703 //! @addtogroup imgproc_hist
   2704 //! @{
   2705 
   2706 /** @example demhist.cpp
   2707 An example for creating histograms of an image
   2708 */
   2709 
   2710 /** @brief Calculates a histogram of a set of arrays.
   2711 
   2712 The functions calcHist calculate the histogram of one or more arrays. The elements of a tuple used
   2713 to increment a histogram bin are taken from the corresponding input arrays at the same location. The
   2714 sample below shows how to compute a 2D Hue-Saturation histogram for a color image. :
   2715 @code
   2716     #include <opencv2/imgproc.hpp>
   2717     #include <opencv2/highgui.hpp>
   2718 
   2719     using namespace cv;
   2720 
   2721     int main( int argc, char** argv )
   2722     {
   2723         Mat src, hsv;
   2724         if( argc != 2 || !(src=imread(argv[1], 1)).data )
   2725             return -1;
   2726 
   2727         cvtColor(src, hsv, COLOR_BGR2HSV);
   2728 
   2729         // Quantize the hue to 30 levels
   2730         // and the saturation to 32 levels
   2731         int hbins = 30, sbins = 32;
   2732         int histSize[] = {hbins, sbins};
   2733         // hue varies from 0 to 179, see cvtColor
   2734         float hranges[] = { 0, 180 };
   2735         // saturation varies from 0 (black-gray-white) to
   2736         // 255 (pure spectrum color)
   2737         float sranges[] = { 0, 256 };
   2738         const float* ranges[] = { hranges, sranges };
   2739         MatND hist;
   2740         // we compute the histogram from the 0-th and 1-st channels
   2741         int channels[] = {0, 1};
   2742 
   2743         calcHist( &hsv, 1, channels, Mat(), // do not use mask
   2744                  hist, 2, histSize, ranges,
   2745                  true, // the histogram is uniform
   2746                  false );
   2747         double maxVal=0;
   2748         minMaxLoc(hist, 0, &maxVal, 0, 0);
   2749 
   2750         int scale = 10;
   2751         Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);
   2752 
   2753         for( int h = 0; h < hbins; h++ )
   2754             for( int s = 0; s < sbins; s++ )
   2755             {
   2756                 float binVal = hist.at<float>(h, s);
   2757                 int intensity = cvRound(binVal*255/maxVal);
   2758                 rectangle( histImg, Point(h*scale, s*scale),
   2759                             Point( (h+1)*scale - 1, (s+1)*scale - 1),
   2760                             Scalar::all(intensity),
   2761                             CV_FILLED );
   2762             }
   2763 
   2764         namedWindow( "Source", 1 );
   2765         imshow( "Source", src );
   2766 
   2767         namedWindow( "H-S Histogram", 1 );
   2768         imshow( "H-S Histogram", histImg );
   2769         waitKey();
   2770     }
   2771 @endcode
   2772 
   2773 @param images Source arrays. They all should have the same depth, CV_8U or CV_32F , and the same
   2774 size. Each of them can have an arbitrary number of channels.
   2775 @param nimages Number of source images.
   2776 @param channels List of the dims channels used to compute the histogram. The first array channels
   2777 are numerated from 0 to images[0].channels()-1 , the second array channels are counted from
   2778 images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.
   2779 @param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size
   2780 as images[i] . The non-zero mask elements mark the array elements counted in the histogram.
   2781 @param hist Output histogram, which is a dense or sparse dims -dimensional array.
   2782 @param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS
   2783 (equal to 32 in the current OpenCV version).
   2784 @param histSize Array of histogram sizes in each dimension.
   2785 @param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the
   2786 histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower
   2787 (inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary
   2788 \f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a
   2789 uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform (
   2790 uniform=false ), then each of ranges[i] contains histSize[i]+1 elements:
   2791 \f$L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}\f$
   2792 . The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not
   2793 counted in the histogram.
   2794 @param uniform Flag indicating whether the histogram is uniform or not (see above).
   2795 @param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning
   2796 when it is allocated. This feature enables you to compute a single histogram from several sets of
   2797 arrays, or to update the histogram in time.
   2798 */
   2799 CV_EXPORTS void calcHist( const Mat* images, int nimages,
   2800                           const int* channels, InputArray mask,
   2801                           OutputArray hist, int dims, const int* histSize,
   2802                           const float** ranges, bool uniform = true, bool accumulate = false );
   2803 
   2804 /** @overload
   2805 
   2806 this variant uses cv::SparseMat for output
   2807 */
   2808 CV_EXPORTS void calcHist( const Mat* images, int nimages,
   2809                           const int* channels, InputArray mask,
   2810                           SparseMat& hist, int dims,
   2811                           const int* histSize, const float** ranges,
   2812                           bool uniform = true, bool accumulate = false );
   2813 
   2814 /** @overload */
   2815 CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
   2816                             const std::vector<int>& channels,
   2817                             InputArray mask, OutputArray hist,
   2818                             const std::vector<int>& histSize,
   2819                             const std::vector<float>& ranges,
   2820                             bool accumulate = false );
   2821 
   2822 /** @brief Calculates the back projection of a histogram.
   2823 
   2824 The functions calcBackProject calculate the back project of the histogram. That is, similarly to
   2825 cv::calcHist , at each location (x, y) the function collects the values from the selected channels
   2826 in the input images and finds the corresponding histogram bin. But instead of incrementing it, the
   2827 function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of
   2828 statistics, the function computes probability of each element value in respect with the empirical
   2829 probability distribution represented by the histogram. See how, for example, you can find and track
   2830 a bright-colored object in a scene:
   2831 
   2832 - Before tracking, show the object to the camera so that it covers almost the whole frame.
   2833 Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant
   2834 colors in the object.
   2835 
   2836 - When tracking, calculate a back projection of a hue plane of each input video frame using that
   2837 pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make
   2838 sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.
   2839 
   2840 - Find connected components in the resulting picture and choose, for example, the largest
   2841 component.
   2842 
   2843 This is an approximate algorithm of the CamShift color object tracker.
   2844 
   2845 @param images Source arrays. They all should have the same depth, CV_8U or CV_32F , and the same
   2846 size. Each of them can have an arbitrary number of channels.
   2847 @param nimages Number of source images.
   2848 @param channels The list of channels used to compute the back projection. The number of channels
   2849 must match the histogram dimensionality. The first array channels are numerated from 0 to
   2850 images[0].channels()-1 , the second array channels are counted from images[0].channels() to
   2851 images[0].channels() + images[1].channels()-1, and so on.
   2852 @param hist Input histogram that can be dense or sparse.
   2853 @param backProject Destination back projection array that is a single-channel array of the same
   2854 size and depth as images[0] .
   2855 @param ranges Array of arrays of the histogram bin boundaries in each dimension. See calcHist .
   2856 @param scale Optional scale factor for the output back projection.
   2857 @param uniform Flag indicating whether the histogram is uniform or not (see above).
   2858 
   2859 @sa cv::calcHist, cv::compareHist
   2860  */
   2861 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
   2862                                  const int* channels, InputArray hist,
   2863                                  OutputArray backProject, const float** ranges,
   2864                                  double scale = 1, bool uniform = true );
   2865 
   2866 /** @overload */
   2867 CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
   2868                                  const int* channels, const SparseMat& hist,
   2869                                  OutputArray backProject, const float** ranges,
   2870                                  double scale = 1, bool uniform = true );
   2871 
   2872 /** @overload */
   2873 CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector<int>& channels,
   2874                                    InputArray hist, OutputArray dst,
   2875                                    const std::vector<float>& ranges,
   2876                                    double scale );
   2877 
   2878 /** @brief Compares two histograms.
   2879 
   2880 The function compare two dense or two sparse histograms using the specified method.
   2881 
   2882 The function returns \f$d(H_1, H_2)\f$ .
   2883 
   2884 While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable
   2885 for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling
   2886 problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms
   2887 or more general sparse configurations of weighted points, consider using the cv::EMD function.
   2888 
   2889 @param H1 First compared histogram.
   2890 @param H2 Second compared histogram of the same size as H1 .
   2891 @param method Comparison method, see cv::HistCompMethods
   2892  */
   2893 CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method );
   2894 
   2895 /** @overload */
   2896 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );
   2897 
   2898 /** @brief Equalizes the histogram of a grayscale image.
   2899 
   2900 The function equalizes the histogram of the input image using the following algorithm:
   2901 
   2902 - Calculate the histogram \f$H\f$ for src .
   2903 - Normalize the histogram so that the sum of histogram bins is 255.
   2904 - Compute the integral of the histogram:
   2905 \f[H'_i =  \sum _{0  \le j < i} H(j)\f]
   2906 - Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$
   2907 
   2908 The algorithm normalizes the brightness and increases the contrast of the image.
   2909 
   2910 @param src Source 8-bit single channel image.
   2911 @param dst Destination image of the same size and type as src .
   2912  */
   2913 CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );
   2914 
   2915 /** @brief Computes the "minimal work" distance between two weighted point configurations.
   2916 
   2917 The function computes the earth mover distance and/or a lower boundary of the distance between the
   2918 two weighted point configurations. One of the applications described in @cite RubnerSept98,
   2919 @cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation
   2920 problem that is solved using some modification of a simplex algorithm, thus the complexity is
   2921 exponential in the worst case, though, on average it is much faster. In the case of a real metric
   2922 the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used
   2923 to determine roughly whether the two signatures are far enough so that they cannot relate to the
   2924 same object.
   2925 
   2926 @param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix.
   2927 Each row stores the point weight followed by the point coordinates. The matrix is allowed to have
   2928 a single column (weights only) if the user-defined cost matrix is used.
   2929 @param signature2 Second signature of the same format as signature1 , though the number of rows
   2930 may be different. The total weights may be different. In this case an extra "dummy" point is added
   2931 to either signature1 or signature2 .
   2932 @param distType Used metric. See cv::DistanceTypes.
   2933 @param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix
   2934 is used, lower boundary lowerBound cannot be calculated because it needs a metric function.
   2935 @param lowerBound Optional input/output parameter: lower boundary of a distance between the two
   2936 signatures that is a distance between mass centers. The lower boundary may not be calculated if
   2937 the user-defined cost matrix is used, the total weights of point configurations are not equal, or
   2938 if the signatures consist of weights only (the signature matrices have a single column). You
   2939 **must** initialize \*lowerBound . If the calculated distance between mass centers is greater or
   2940 equal to \*lowerBound (it means that the signatures are far enough), the function does not
   2941 calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on
   2942 return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound
   2943 should be set to 0.
   2944 @param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is
   2945 a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 .
   2946  */
   2947 CV_EXPORTS float EMD( InputArray signature1, InputArray signature2,
   2948                       int distType, InputArray cost=noArray(),
   2949                       float* lowerBound = 0, OutputArray flow = noArray() );
   2950 
   2951 //! @} imgproc_hist
   2952 
   2953 /** @example watershed.cpp
   2954 An example using the watershed algorithm
   2955  */
   2956 
   2957 /** @brief Performs a marker-based image segmentation using the watershed algorithm.
   2958 
   2959 The function implements one of the variants of watershed, non-parametric marker-based segmentation
   2960 algorithm, described in @cite Meyer92 .
   2961 
   2962 Before passing the image to the function, you have to roughly outline the desired regions in the
   2963 image markers with positive (\>0) indices. So, every region is represented as one or more connected
   2964 components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary
   2965 mask using findContours and drawContours (see the watershed.cpp demo). The markers are "seeds" of
   2966 the future image regions. All the other pixels in markers , whose relation to the outlined regions
   2967 is not known and should be defined by the algorithm, should be set to 0's. In the function output,
   2968 each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the
   2969 regions.
   2970 
   2971 @note Any two neighbor connected components are not necessarily separated by a watershed boundary
   2972 (-1's pixels); for example, they can touch each other in the initial marker image passed to the
   2973 function.
   2974 
   2975 @param image Input 8-bit 3-channel image.
   2976 @param markers Input/output 32-bit single-channel image (map) of markers. It should have the same
   2977 size as image .
   2978 
   2979 @sa findContours
   2980 
   2981 @ingroup imgproc_misc
   2982  */
   2983 CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers );
   2984 
   2985 //! @addtogroup imgproc_filter
   2986 //! @{
   2987 
   2988 /** @brief Performs initial step of meanshift segmentation of an image.
   2989 
   2990 The function implements the filtering stage of meanshift segmentation, that is, the output of the
   2991 function is the filtered "posterized" image with color gradients and fine-grain texture flattened.
   2992 At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes
   2993 meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is
   2994 considered:
   2995 
   2996 \f[(x,y): X- \texttt{sp} \le x  \le X+ \texttt{sp} , Y- \texttt{sp} \le y  \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)||   \le \texttt{sr}\f]
   2997 
   2998 where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively
   2999 (though, the algorithm does not depend on the color space used, so any 3-component color space can
   3000 be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector
   3001 (R',G',B') are found and they act as the neighborhood center on the next iteration:
   3002 
   3003 \f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f]
   3004 
   3005 After the iterations over, the color components of the initial pixel (that is, the pixel from where
   3006 the iterations started) are set to the final value (average color at the last iteration):
   3007 
   3008 \f[I(X,Y) <- (R*,G*,B*)\f]
   3009 
   3010 When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is
   3011 run on the smallest layer first. After that, the results are propagated to the larger layer and the
   3012 iterations are run again only on those pixels where the layer colors differ by more than sr from the
   3013 lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the
   3014 results will be actually different from the ones obtained by running the meanshift procedure on the
   3015 whole original image (i.e. when maxLevel==0).
   3016 
   3017 @param src The source 8-bit, 3-channel image.
   3018 @param dst The destination image of the same format and the same size as the source.
   3019 @param sp The spatial window radius.
   3020 @param sr The color window radius.
   3021 @param maxLevel Maximum level of the pyramid for the segmentation.
   3022 @param termcrit Termination criteria: when to stop meanshift iterations.
   3023  */
   3024 CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst,
   3025                                          double sp, double sr, int maxLevel = 1,
   3026                                          TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) );
   3027 
   3028 //! @}
   3029 
   3030 //! @addtogroup imgproc_misc
   3031 //! @{
   3032 
   3033 /** @example grabcut.cpp
   3034 An example using the GrabCut algorithm
   3035  */
   3036 
   3037 /** @brief Runs the GrabCut algorithm.
   3038 
   3039 The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut).
   3040 
   3041 @param img Input 8-bit 3-channel image.
   3042 @param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when
   3043 mode is set to GC_INIT_WITH_RECT. Its elements may have one of the cv::GrabCutClasses.
   3044 @param rect ROI containing a segmented object. The pixels outside of the ROI are marked as
   3045 "obvious background". The parameter is only used when mode==GC_INIT_WITH_RECT .
   3046 @param bgdModel Temporary array for the background model. Do not modify it while you are
   3047 processing the same image.
   3048 @param fgdModel Temporary arrays for the foreground model. Do not modify it while you are
   3049 processing the same image.
   3050 @param iterCount Number of iterations the algorithm should make before returning the result. Note
   3051 that the result can be refined with further calls with mode==GC_INIT_WITH_MASK or
   3052 mode==GC_EVAL .
   3053 @param mode Operation mode that could be one of the cv::GrabCutModes
   3054  */
   3055 CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect,
   3056                            InputOutputArray bgdModel, InputOutputArray fgdModel,
   3057                            int iterCount, int mode = GC_EVAL );
   3058 
   3059 /** @example distrans.cpp
   3060 An example on using the distance transform\
   3061 */
   3062 
   3063 
   3064 /** @brief Calculates the distance to the closest zero pixel for each pixel of the source image.
   3065 
   3066 The functions distanceTransform calculate the approximate or precise distance from every binary
   3067 image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero.
   3068 
   3069 When maskSize == DIST_MASK_PRECISE and distanceType == DIST_L2 , the function runs the
   3070 algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library.
   3071 
   3072 In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function
   3073 finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical,
   3074 diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall
   3075 distance is calculated as a sum of these basic distances. Since the distance function should be
   3076 symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all
   3077 the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the
   3078 same cost (denoted as `c`). For the cv::DIST_C and cv::DIST_L1 types, the distance is calculated
   3079 precisely, whereas for cv::DIST_L2 (Euclidean distance) the distance can be calculated only with a
   3080 relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV
   3081 uses the values suggested in the original paper:
   3082 - DIST_L1: `a = 1, b = 2`
   3083 - DIST_L2:
   3084     - `3 x 3`: `a=0.955, b=1.3693`
   3085     - `5 x 5`: `a=1, b=1.4, c=2.1969`
   3086 - DIST_C: `a = 1, b = 1`
   3087 
   3088 Typically, for a fast, coarse distance estimation DIST_L2, a \f$3\times 3\f$ mask is used. For a
   3089 more accurate distance estimation DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used.
   3090 Note that both the precise and the approximate algorithms are linear on the number of pixels.
   3091 
   3092 This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$
   3093 but also identifies the nearest connected component consisting of zero pixels
   3094 (labelType==DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==DIST_LABEL_PIXEL). Index of the
   3095 component/pixel is stored in `labels(x, y)`. When labelType==DIST_LABEL_CCOMP, the function
   3096 automatically finds connected components of zero pixels in the input image and marks them with
   3097 distinct labels. When labelType==DIST_LABEL_CCOMP, the function scans through the input image and
   3098 marks all the zero pixels with distinct labels.
   3099 
   3100 In this mode, the complexity is still linear. That is, the function provides a very fast way to
   3101 compute the Voronoi diagram for a binary image. Currently, the second variant can use only the
   3102 approximate distance transform algorithm, i.e. maskSize=DIST_MASK_PRECISE is not supported
   3103 yet.
   3104 
   3105 @param src 8-bit, single-channel (binary) source image.
   3106 @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,
   3107 single-channel image of the same size as src.
   3108 @param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type
   3109 CV_32SC1 and the same size as src.
   3110 @param distanceType Type of distance, see cv::DistanceTypes
   3111 @param maskSize Size of the distance transform mask, see cv::DistanceTransformMasks.
   3112 DIST_MASK_PRECISE is not supported by this variant. In case of the DIST_L1 or DIST_C distance type,
   3113 the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times
   3114 5\f$ or any larger aperture.
   3115 @param labelType Type of the label array to build, see cv::DistanceTransformLabelTypes.
   3116  */
   3117 CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst,
   3118                                      OutputArray labels, int distanceType, int maskSize,
   3119                                      int labelType = DIST_LABEL_CCOMP );
   3120 
   3121 /** @overload
   3122 @param src 8-bit, single-channel (binary) source image.
   3123 @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,
   3124 single-channel image of the same size as src .
   3125 @param distanceType Type of distance, see cv::DistanceTypes
   3126 @param maskSize Size of the distance transform mask, see cv::DistanceTransformMasks. In case of the
   3127 DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives
   3128 the same result as \f$5\times 5\f$ or any larger aperture.
   3129 @param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for
   3130 the first variant of the function and distanceType == DIST_L1.
   3131 */
   3132 CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst,
   3133                                      int distanceType, int maskSize, int dstType=CV_32F);
   3134 
   3135 /** @example ffilldemo.cpp
   3136   An example using the FloodFill technique
   3137 */
   3138 
   3139 /** @overload
   3140 
   3141 variant without `mask` parameter
   3142 */
   3143 CV_EXPORTS int floodFill( InputOutputArray image,
   3144                           Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0,
   3145                           Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),
   3146                           int flags = 4 );
   3147 
   3148 /** @brief Fills a connected component with the given color.
   3149 
   3150 The functions floodFill fill a connected component starting from the seed point with the specified
   3151 color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The
   3152 pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if:
   3153 
   3154 - in case of a grayscale image and floating range
   3155 \f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y)  \leq \texttt{src} (x',y')+ \texttt{upDiff}\f]
   3156 
   3157 
   3158 - in case of a grayscale image and fixed range
   3159 \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)- \texttt{loDiff} \leq \texttt{src} (x,y)  \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)+ \texttt{upDiff}\f]
   3160 
   3161 
   3162 - in case of a color image and floating range
   3163 \f[\texttt{src} (x',y')_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} (x',y')_r+ \texttt{upDiff} _r,\f]
   3164 \f[\texttt{src} (x',y')_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} (x',y')_g+ \texttt{upDiff} _g\f]
   3165 and
   3166 \f[\texttt{src} (x',y')_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} (x',y')_b+ \texttt{upDiff} _b\f]
   3167 
   3168 
   3169 - in case of a color image and fixed range
   3170 \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r+ \texttt{upDiff} _r,\f]
   3171 \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g+ \texttt{upDiff} _g\f]
   3172 and
   3173 \f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b+ \texttt{upDiff} _b\f]
   3174 
   3175 
   3176 where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the
   3177 component. That is, to be added to the connected component, a color/brightness of the pixel should
   3178 be close enough to:
   3179 - Color/brightness of one of its neighbors that already belong to the connected component in case
   3180 of a floating range.
   3181 - Color/brightness of the seed point in case of a fixed range.
   3182 
   3183 Use these functions to either mark a connected component with the specified color in-place, or build
   3184 a mask and then extract the contour, or copy the region to another image, and so on.
   3185 
   3186 @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the
   3187 function unless the FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See
   3188 the details below.
   3189 @param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels
   3190 taller than image. Since this is both an input and output parameter, you must take responsibility
   3191 of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example,
   3192 an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the
   3193 mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags
   3194 as described below. It is therefore possible to use the same mask in multiple calls to the function
   3195 to make sure the filled areas do not overlap.
   3196 @param seedPoint Starting point.
   3197 @param newVal New value of the repainted domain pixels.
   3198 @param loDiff Maximal lower brightness/color difference between the currently observed pixel and
   3199 one of its neighbors belonging to the component, or a seed pixel being added to the component.
   3200 @param upDiff Maximal upper brightness/color difference between the currently observed pixel and
   3201 one of its neighbors belonging to the component, or a seed pixel being added to the component.
   3202 @param rect Optional output parameter set by the function to the minimum bounding rectangle of the
   3203 repainted domain.
   3204 @param flags Operation flags. The first 8 bits contain a connectivity value. The default value of
   3205 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A
   3206 connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner)
   3207 will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill
   3208 the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest
   3209 neighbours and fill the mask with a value of 255. The following additional options occupy higher
   3210 bits and therefore may be further combined with the connectivity and mask fill values using
   3211 bit-wise or (|), see cv::FloodFillFlags.
   3212 
   3213 @note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the
   3214 pixel \f$(x+1, y+1)\f$ in the mask .
   3215 
   3216 @sa findContours
   3217  */
   3218 CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
   3219                             Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0,
   3220                             Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),
   3221                             int flags = 4 );
   3222 
   3223 /** @brief Converts an image from one color space to another.
   3224 
   3225 The function converts an input image from one color space to another. In case of a transformation
   3226 to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note
   3227 that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the
   3228 bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue
   3229 component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and
   3230 sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
   3231 
   3232 The conventional ranges for R, G, and B channel values are:
   3233 -   0 to 255 for CV_8U images
   3234 -   0 to 65535 for CV_16U images
   3235 -   0 to 1 for CV_32F images
   3236 
   3237 In case of linear transformations, the range does not matter. But in case of a non-linear
   3238 transformation, an input RGB image should be normalized to the proper value range to get the correct
   3239 results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a
   3240 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will
   3241 have the 0..255 value range instead of 0..1 assumed by the function. So, before calling cvtColor ,
   3242 you need first to scale the image down:
   3243 @code
   3244     img *= 1./255;
   3245     cvtColor(img, img, COLOR_BGR2Luv);
   3246 @endcode
   3247 If you use cvtColor with 8-bit images, the conversion will have some information lost. For many
   3248 applications, this will not be noticeable but it is recommended to use 32-bit images in applications
   3249 that need the full range of colors or that convert an image before an operation and then convert
   3250 back.
   3251 
   3252 If conversion adds the alpha channel, its value will set to the maximum of corresponding channel
   3253 range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
   3254 
   3255 @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision
   3256 floating-point.
   3257 @param dst output image of the same size and depth as src.
   3258 @param code color space conversion code (see cv::ColorConversionCodes).
   3259 @param dstCn number of channels in the destination image; if the parameter is 0, the number of the
   3260 channels is derived automatically from src and code.
   3261 
   3262 @see @ref imgproc_color_conversions
   3263  */
   3264 CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
   3265 
   3266 //! @} imgproc_misc
   3267 
   3268 // main function for all demosaicing procceses
   3269 CV_EXPORTS_W void demosaicing(InputArray _src, OutputArray _dst, int code, int dcn = 0);
   3270 
   3271 //! @addtogroup imgproc_shape
   3272 //! @{
   3273 
   3274 /** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape.
   3275 
   3276 The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The
   3277 results are returned in the structure cv::Moments.
   3278 
   3279 @param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array (
   3280 \f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ).
   3281 @param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is
   3282 used for images only.
   3283 @returns moments.
   3284 
   3285 @sa  contourArea, arcLength
   3286  */
   3287 CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false );
   3288 
   3289 /** @brief Calculates seven Hu invariants.
   3290 
   3291 The function calculates seven Hu invariants (introduced in @cite Hu62; see also
   3292 <http://en.wikipedia.org/wiki/Image_moment>) defined as:
   3293 
   3294 \f[\begin{array}{l} hu[0]= \eta _{20}+ \eta _{02} \\ hu[1]=( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2} \\ hu[2]=( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2} \\ hu[3]=( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2} \\ hu[4]=( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ hu[5]=( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03}) \\ hu[6]=(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ \end{array}\f]
   3295 
   3296 where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ .
   3297 
   3298 These values are proved to be invariants to the image scale, rotation, and reflection except the
   3299 seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of
   3300 infinite image resolution. In case of raster images, the computed Hu invariants for the original and
   3301 transformed images are a bit different.
   3302 
   3303 @param moments Input moments computed with moments .
   3304 @param hu Output Hu invariants.
   3305 
   3306 @sa matchShapes
   3307  */
   3308 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
   3309 
   3310 /** @overload */
   3311 CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu );
   3312 
   3313 //! @} imgproc_shape
   3314 
   3315 //! @addtogroup imgproc_object
   3316 //! @{
   3317 
   3318 //! type of the template matching operation
   3319 enum TemplateMatchModes {
   3320     TM_SQDIFF        = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]
   3321     TM_SQDIFF_NORMED = 1, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
   3322     TM_CCORR         = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')  \cdot I(x+x',y+y'))\f]
   3323     TM_CCORR_NORMED  = 3, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
   3324     TM_CCOEFF        = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y')  \cdot I'(x+x',y+y'))\f]
   3325                           //!< where
   3326                           //!< \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w  \cdot h)  \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w  \cdot h)  \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f]
   3327     TM_CCOEFF_NORMED = 5  //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f]
   3328 };
   3329 
   3330 /** @brief Compares a template against overlapped image regions.
   3331 
   3332 The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against
   3333 templ using the specified method and stores the comparison results in result . Here are the formulae
   3334 for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation
   3335 is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$
   3336 
   3337 After the function finishes the comparison, the best matches can be found as global minimums (when
   3338 TM_SQDIFF was used) or maximums (when TM_CCORR or TM_CCOEFF was used) using the
   3339 minMaxLoc function. In case of a color image, template summation in the numerator and each sum in
   3340 the denominator is done over all of the channels and separate mean values are used for each channel.
   3341 That is, the function can take a color template and a color image. The result will still be a
   3342 single-channel image, which is easier to analyze.
   3343 
   3344 @param image Image where the search is running. It must be 8-bit or 32-bit floating-point.
   3345 @param templ Searched template. It must be not greater than the source image and have the same
   3346 data type.
   3347 @param result Map of comparison results. It must be single-channel 32-bit floating-point. If image
   3348 is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ .
   3349 @param method Parameter specifying the comparison method, see cv::TemplateMatchModes
   3350 @param mask Mask of searched template. It must have the same datatype and size with templ. It is
   3351 not set by default.
   3352  */
   3353 CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,
   3354                                  OutputArray result, int method, InputArray mask = noArray() );
   3355 
   3356 //! @}
   3357 
   3358 //! @addtogroup imgproc_shape
   3359 //! @{
   3360 
   3361 /** @brief computes the connected components labeled image of boolean image
   3362 
   3363 image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0
   3364 represents the background label. ltype specifies the output label image type, an important
   3365 consideration based on the total number of labels or alternatively the total number of pixels in
   3366 the source image.
   3367 
   3368 @param image the image to be labeled
   3369 @param labels destination labeled image
   3370 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
   3371 @param ltype output image label type. Currently CV_32S and CV_16U are supported.
   3372  */
   3373 CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels,
   3374                                      int connectivity = 8, int ltype = CV_32S);
   3375 
   3376 /** @overload
   3377 @param image the image to be labeled
   3378 @param labels destination labeled image
   3379 @param stats statistics output for each label, including the background label, see below for
   3380 available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
   3381 cv::ConnectedComponentsTypes
   3382 @param centroids floating point centroid (x,y) output for each label, including the background label
   3383 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
   3384 @param ltype output image label type. Currently CV_32S and CV_16U are supported.
   3385 */
   3386 CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels,
   3387                                               OutputArray stats, OutputArray centroids,
   3388                                               int connectivity = 8, int ltype = CV_32S);
   3389 
   3390 
   3391 /** @brief Finds contours in a binary image.
   3392 
   3393 The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours
   3394 are a useful tool for shape analysis and object detection and recognition. See squares.c in the
   3395 OpenCV sample directory.
   3396 
   3397 @note Source image is modified by this function. Also, the function does not take into account
   3398 1-pixel border of the image (it's filled with 0's and used for neighbor analysis in the algorithm),
   3399 therefore the contours touching the image border will be clipped.
   3400 
   3401 @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero
   3402 pixels remain 0's, so the image is treated as binary . You can use compare , inRange , threshold ,
   3403 adaptiveThreshold , Canny , and others to create a binary image out of a grayscale or color one.
   3404 The function modifies the image while extracting the contours. If mode equals to RETR_CCOMP
   3405 or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
   3406 @param contours Detected contours. Each contour is stored as a vector of points.
   3407 @param hierarchy Optional output vector, containing information about the image topology. It has
   3408 as many elements as the number of contours. For each i-th contour contours[i] , the elements
   3409 hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices
   3410 in contours of the next and previous contours at the same hierarchical level, the first child
   3411 contour and the parent contour, respectively. If for the contour i there are no next, previous,
   3412 parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
   3413 @param mode Contour retrieval mode, see cv::RetrievalModes
   3414 @param method Contour approximation method, see cv::ContourApproximationModes
   3415 @param offset Optional offset by which every contour point is shifted. This is useful if the
   3416 contours are extracted from the image ROI and then they should be analyzed in the whole image
   3417 context.
   3418  */
   3419 CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours,
   3420                               OutputArray hierarchy, int mode,
   3421                               int method, Point offset = Point());
   3422 
   3423 /** @overload */
   3424 CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours,
   3425                               int mode, int method, Point offset = Point());
   3426 
   3427 /** @brief Approximates a polygonal curve(s) with the specified precision.
   3428 
   3429 The functions approxPolyDP approximate a curve or a polygon with another curve/polygon with less
   3430 vertices so that the distance between them is less or equal to the specified precision. It uses the
   3431 Douglas-Peucker algorithm <http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm>
   3432 
   3433 @param curve Input vector of a 2D point stored in std::vector or Mat
   3434 @param approxCurve Result of the approximation. The type should match the type of the input curve.
   3435 @param epsilon Parameter specifying the approximation accuracy. This is the maximum distance
   3436 between the original curve and its approximation.
   3437 @param closed If true, the approximated curve is closed (its first and last vertices are
   3438 connected). Otherwise, it is not closed.
   3439  */
   3440 CV_EXPORTS_W void approxPolyDP( InputArray curve,
   3441                                 OutputArray approxCurve,
   3442                                 double epsilon, bool closed );
   3443 
   3444 /** @brief Calculates a contour perimeter or a curve length.
   3445 
   3446 The function computes a curve length or a closed contour perimeter.
   3447 
   3448 @param curve Input vector of 2D points, stored in std::vector or Mat.
   3449 @param closed Flag indicating whether the curve is closed or not.
   3450  */
   3451 CV_EXPORTS_W double arcLength( InputArray curve, bool closed );
   3452 
   3453 /** @brief Calculates the up-right bounding rectangle of a point set.
   3454 
   3455 The function calculates and returns the minimal up-right bounding rectangle for the specified point set.
   3456 
   3457 @param points Input 2D point set, stored in std::vector or Mat.
   3458  */
   3459 CV_EXPORTS_W Rect boundingRect( InputArray points );
   3460 
   3461 /** @brief Calculates a contour area.
   3462 
   3463 The function computes a contour area. Similarly to moments , the area is computed using the Green
   3464 formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using
   3465 drawContours or fillPoly , can be different. Also, the function will most certainly give a wrong
   3466 results for contours with self-intersections.
   3467 
   3468 Example:
   3469 @code
   3470     vector<Point> contour;
   3471     contour.push_back(Point2f(0, 0));
   3472     contour.push_back(Point2f(10, 0));
   3473     contour.push_back(Point2f(10, 10));
   3474     contour.push_back(Point2f(5, 4));
   3475 
   3476     double area0 = contourArea(contour);
   3477     vector<Point> approx;
   3478     approxPolyDP(contour, approx, 5, true);
   3479     double area1 = contourArea(approx);
   3480 
   3481     cout << "area0 =" << area0 << endl <<
   3482             "area1 =" << area1 << endl <<
   3483             "approx poly vertices" << approx.size() << endl;
   3484 @endcode
   3485 @param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat.
   3486 @param oriented Oriented area flag. If it is true, the function returns a signed area value,
   3487 depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can
   3488 determine orientation of a contour by taking the sign of an area. By default, the parameter is
   3489 false, which means that the absolute value is returned.
   3490  */
   3491 CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false );
   3492 
   3493 /** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
   3494 
   3495 The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a
   3496 specified point set. See the OpenCV sample minarea.cpp . Developer should keep in mind that the
   3497 returned rotatedRect can contain negative indices when data is close to the containing Mat element
   3498 boundary.
   3499 
   3500 @param points Input vector of 2D points, stored in std::vector\<\> or Mat
   3501  */
   3502 CV_EXPORTS_W RotatedRect minAreaRect( InputArray points );
   3503 
   3504 /** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.
   3505 
   3506 The function finds the four vertices of a rotated rectangle. This function is useful to draw the
   3507 rectangle. In C++, instead of using this function, you can directly use box.points() method. Please
   3508 visit the [tutorial on bounding
   3509 rectangle](http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html#bounding-rects-circles)
   3510 for more information.
   3511 
   3512 @param box The input rotated rectangle. It may be the output of
   3513 @param points The output array of four vertices of rectangles.
   3514  */
   3515 CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points);
   3516 
   3517 /** @brief Finds a circle of the minimum area enclosing a 2D point set.
   3518 
   3519 The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. See
   3520 the OpenCV sample minarea.cpp .
   3521 
   3522 @param points Input vector of 2D points, stored in std::vector\<\> or Mat
   3523 @param center Output center of the circle.
   3524 @param radius Output radius of the circle.
   3525  */
   3526 CV_EXPORTS_W void minEnclosingCircle( InputArray points,
   3527                                       CV_OUT Point2f& center, CV_OUT float& radius );
   3528 
   3529 /** @example minarea.cpp
   3530   */
   3531 
   3532 /** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area.
   3533 
   3534 The function finds a triangle of minimum area enclosing the given set of 2D points and returns its
   3535 area. The output for a given 2D point set is shown in the image below. 2D points are depicted in
   3536 *red* and the enclosing triangle in *yellow*.
   3537 
   3538 ![Sample output of the minimum enclosing triangle function](pics/minenclosingtriangle.png)
   3539 
   3540 The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's
   3541 @cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal
   3542 enclosing triangle of a 2D convex polygon with n vertices. Since the minEnclosingTriangle function
   3543 takes a 2D point set as input an additional preprocessing step of computing the convex hull of the
   3544 2D point set is required. The complexity of the convexHull function is \f$O(n log(n))\f$ which is higher
   3545 than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$.
   3546 
   3547 @param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat
   3548 @param triangle Output vector of three 2D points defining the vertices of the triangle. The depth
   3549 of the OutputArray must be CV_32F.
   3550  */
   3551 CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle );
   3552 
   3553 /** @brief Compares two shapes.
   3554 
   3555 The function compares two shapes. All three implemented methods use the Hu invariants (see cv::HuMoments)
   3556 
   3557 @param contour1 First contour or grayscale image.
   3558 @param contour2 Second contour or grayscale image.
   3559 @param method Comparison method, see ::ShapeMatchModes
   3560 @param parameter Method-specific parameter (not supported now).
   3561  */
   3562 CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,
   3563                                  int method, double parameter );
   3564 
   3565 /** @example convexhull.cpp
   3566 An example using the convexHull functionality
   3567 */
   3568 
   3569 /** @brief Finds the convex hull of a point set.
   3570 
   3571 The functions find the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82
   3572 that has *O(N logN)* complexity in the current implementation. See the OpenCV sample convexhull.cpp
   3573 that demonstrates the usage of different function variants.
   3574 
   3575 @param points Input 2D point set, stored in std::vector or Mat.
   3576 @param hull Output convex hull. It is either an integer vector of indices or vector of points. In
   3577 the first case, the hull elements are 0-based indices of the convex hull points in the original
   3578 array (since the set of convex hull points is a subset of the original point set). In the second
   3579 case, hull elements are the convex hull points themselves.
   3580 @param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise.
   3581 Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing
   3582 to the right, and its Y axis pointing upwards.
   3583 @param returnPoints Operation flag. In case of a matrix, when the flag is true, the function
   3584 returns convex hull points. Otherwise, it returns indices of the convex hull points. When the
   3585 output array is std::vector, the flag is ignored, and the output depends on the type of the
   3586 vector: std::vector\<int\> implies returnPoints=true, std::vector\<Point\> implies
   3587 returnPoints=false.
   3588  */
   3589 CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull,
   3590                               bool clockwise = false, bool returnPoints = true );
   3591 
   3592 /** @brief Finds the convexity defects of a contour.
   3593 
   3594 The figure below displays convexity defects of a hand contour:
   3595 
   3596 ![image](pics/defects.png)
   3597 
   3598 @param contour Input contour.
   3599 @param convexhull Convex hull obtained using convexHull that should contain indices of the contour
   3600 points that make the hull.
   3601 @param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java
   3602 interface each convexity defect is represented as 4-element integer vector (a.k.a. cv::Vec4i):
   3603 (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices
   3604 in the original contour of the convexity defect beginning, end and the farthest point, and
   3605 fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the
   3606 farthest contour point and the hull. That is, to get the floating-point value of the depth will be
   3607 fixpt_depth/256.0.
   3608  */
   3609 CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects );
   3610 
   3611 /** @brief Tests a contour convexity.
   3612 
   3613 The function tests whether the input contour is convex or not. The contour must be simple, that is,
   3614 without self-intersections. Otherwise, the function output is undefined.
   3615 
   3616 @param contour Input vector of 2D points, stored in std::vector\<\> or Mat
   3617  */
   3618 CV_EXPORTS_W bool isContourConvex( InputArray contour );
   3619 
   3620 //! finds intersection of two convex polygons
   3621 CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2,
   3622                                           OutputArray _p12, bool handleNested = true );
   3623 
   3624 /** @example fitellipse.cpp
   3625   An example using the fitEllipse technique
   3626 */
   3627 
   3628 /** @brief Fits an ellipse around a set of 2D points.
   3629 
   3630 The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of
   3631 all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon95
   3632 is used. Developer should keep in mind that it is possible that the returned
   3633 ellipse/rotatedRect data contains negative indices, due to the data points being close to the
   3634 border of the containing Mat element.
   3635 
   3636 @param points Input 2D point set, stored in std::vector\<\> or Mat
   3637  */
   3638 CV_EXPORTS_W RotatedRect fitEllipse( InputArray points );
   3639 
   3640 /** @brief Fits a line to a 2D or 3D point set.
   3641 
   3642 The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where
   3643 \f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance function, one
   3644 of the following:
   3645 -  DIST_L2
   3646 \f[\rho (r) = r^2/2  \quad \text{(the simplest and the fastest least-squares method)}\f]
   3647 - DIST_L1
   3648 \f[\rho (r) = r\f]
   3649 - DIST_L12
   3650 \f[\rho (r) = 2  \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f]
   3651 - DIST_FAIR
   3652 \f[\rho \left (r \right ) = C^2  \cdot \left (  \frac{r}{C} -  \log{\left(1 + \frac{r}{C}\right)} \right )  \quad \text{where} \quad C=1.3998\f]
   3653 - DIST_WELSCH
   3654 \f[\rho \left (r \right ) =  \frac{C^2}{2} \cdot \left ( 1 -  \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right )  \quad \text{where} \quad C=2.9846\f]
   3655 - DIST_HUBER
   3656 \f[\rho (r) =  \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f]
   3657 
   3658 The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique
   3659 that iteratively fits the line using the weighted least-squares algorithm. After each iteration the
   3660 weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ .
   3661 
   3662 @param points Input vector of 2D or 3D points, stored in std::vector\<\> or Mat.
   3663 @param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements
   3664 (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and
   3665 (x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like
   3666 Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line
   3667 and (x0, y0, z0) is a point on the line.
   3668 @param distType Distance used by the M-estimator, see cv::DistanceTypes
   3669 @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value
   3670 is chosen.
   3671 @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line).
   3672 @param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps.
   3673  */
   3674 CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType,
   3675                            double param, double reps, double aeps );
   3676 
   3677 /** @brief Performs a point-in-contour test.
   3678 
   3679 The function determines whether the point is inside a contour, outside, or lies on an edge (or
   3680 coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge)
   3681 value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively.
   3682 Otherwise, the return value is a signed distance between the point and the nearest contour edge.
   3683 
   3684 See below a sample output of the function where each image pixel is tested against the contour:
   3685 
   3686 ![sample output](pics/pointpolygon.png)
   3687 
   3688 @param contour Input contour.
   3689 @param pt Point tested against the contour.
   3690 @param measureDist If true, the function estimates the signed distance from the point to the
   3691 nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.
   3692  */
   3693 CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist );
   3694 
   3695 /** @brief Finds out if there is any intersection between two rotated rectangles.
   3696 
   3697 If there is then the vertices of the interesecting region are returned as well.
   3698 
   3699 Below are some examples of intersection configurations. The hatched pattern indicates the
   3700 intersecting region and the red vertices are returned by the function.
   3701 
   3702 ![intersection examples](pics/intersection.png)
   3703 
   3704 @param rect1 First rectangle
   3705 @param rect2 Second rectangle
   3706 @param intersectingRegion The output array of the verticies of the intersecting region. It returns
   3707 at most 8 vertices. Stored as std::vector\<cv::Point2f\> or cv::Mat as Mx1 of type CV_32FC2.
   3708 @returns One of cv::RectanglesIntersectTypes
   3709  */
   3710 CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion  );
   3711 
   3712 //! @} imgproc_shape
   3713 
   3714 CV_EXPORTS_W Ptr<CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8));
   3715 
   3716 //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.
   3717 //! Detects position only without traslation and rotation
   3718 CV_EXPORTS Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard();
   3719 
   3720 //! Guil, N., Gonzlez-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.
   3721 //! Detects position, traslation and rotation
   3722 CV_EXPORTS Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil();
   3723 
   3724 //! Performs linear blending of two images
   3725 CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst);
   3726 
   3727 //! @addtogroup imgproc_colormap
   3728 //! @{
   3729 
   3730 //! GNU Octave/MATLAB equivalent colormaps
   3731 enum ColormapTypes
   3732 {
   3733     COLORMAP_AUTUMN = 0, //!< ![autumn](pics/colormaps/colorscale_autumn.jpg)
   3734     COLORMAP_BONE = 1, //!< ![bone](pics/colormaps/colorscale_bone.jpg)
   3735     COLORMAP_JET = 2, //!< ![jet](pics/colormaps/colorscale_jet.jpg)
   3736     COLORMAP_WINTER = 3, //!< ![winter](pics/colormaps/colorscale_winter.jpg)
   3737     COLORMAP_RAINBOW = 4, //!< ![rainbow](pics/colormaps/colorscale_rainbow.jpg)
   3738     COLORMAP_OCEAN = 5, //!< ![ocean](pics/colormaps/colorscale_ocean.jpg)
   3739     COLORMAP_SUMMER = 6, //!< ![summer](pics/colormaps/colorscale_summer.jpg)
   3740     COLORMAP_SPRING = 7, //!< ![spring](pics/colormaps/colorscale_spring.jpg)
   3741     COLORMAP_COOL = 8, //!< ![cool](pics/colormaps/colorscale_cool.jpg)
   3742     COLORMAP_HSV = 9, //!< ![HSV](pics/colormaps/colorscale_hsv.jpg)
   3743     COLORMAP_PINK = 10, //!< ![pink](pics/colormaps/colorscale_pink.jpg)
   3744     COLORMAP_HOT = 11, //!< ![hot](pics/colormaps/colorscale_hot.jpg)
   3745     COLORMAP_PARULA = 12 //!< ![hot](pics/colormaps/colorscale_parula.jpg)
   3746 };
   3747 
   3748 /** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image.
   3749 
   3750 @param src The source image, grayscale or colored does not matter.
   3751 @param dst The result is the colormapped source image. Note: Mat::create is called on dst.
   3752 @param colormap The colormap to apply, see cv::ColormapTypes
   3753  */
   3754 CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap);
   3755 
   3756 //! @} imgproc_colormap
   3757 
   3758 //! @addtogroup imgproc_draw
   3759 //! @{
   3760 
   3761 /** @brief Draws a line segment connecting two points.
   3762 
   3763 The function line draws the line segment between pt1 and pt2 points in the image. The line is
   3764 clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected
   3765 or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased
   3766 lines are drawn using Gaussian filtering.
   3767 
   3768 @param img Image.
   3769 @param pt1 First point of the line segment.
   3770 @param pt2 Second point of the line segment.
   3771 @param color Line color.
   3772 @param thickness Line thickness.
   3773 @param lineType Type of the line, see cv::LineTypes.
   3774 @param shift Number of fractional bits in the point coordinates.
   3775  */
   3776 CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
   3777                      int thickness = 1, int lineType = LINE_8, int shift = 0);
   3778 
   3779 /** @brief Draws a arrow segment pointing from the first point to the second one.
   3780 
   3781 The function arrowedLine draws an arrow between pt1 and pt2 points in the image. See also cv::line.
   3782 
   3783 @param img Image.
   3784 @param pt1 The point the arrow starts from.
   3785 @param pt2 The point the arrow points to.
   3786 @param color Line color.
   3787 @param thickness Line thickness.
   3788 @param line_type Type of the line, see cv::LineTypes
   3789 @param shift Number of fractional bits in the point coordinates.
   3790 @param tipLength The length of the arrow tip in relation to the arrow length
   3791  */
   3792 CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
   3793                      int thickness=1, int line_type=8, int shift=0, double tipLength=0.1);
   3794 
   3795 /** @brief Draws a simple, thick, or filled up-right rectangle.
   3796 
   3797 The function rectangle draws a rectangle outline or a filled rectangle whose two opposite corners
   3798 are pt1 and pt2.
   3799 
   3800 @param img Image.
   3801 @param pt1 Vertex of the rectangle.
   3802 @param pt2 Vertex of the rectangle opposite to pt1 .
   3803 @param color Rectangle color or brightness (grayscale image).
   3804 @param thickness Thickness of lines that make up the rectangle. Negative values, like CV_FILLED ,
   3805 mean that the function has to draw a filled rectangle.
   3806 @param lineType Type of the line. See the line description.
   3807 @param shift Number of fractional bits in the point coordinates.
   3808  */
   3809 CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
   3810                           const Scalar& color, int thickness = 1,
   3811                           int lineType = LINE_8, int shift = 0);
   3812 
   3813 /** @overload
   3814 
   3815 use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and
   3816 r.br()-Point(1,1)` are opposite corners
   3817 */
   3818 CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
   3819                           const Scalar& color, int thickness = 1,
   3820                           int lineType = LINE_8, int shift = 0);
   3821 
   3822 /** @brief Draws a circle.
   3823 
   3824 The function circle draws a simple or filled circle with a given center and radius.
   3825 @param img Image where the circle is drawn.
   3826 @param center Center of the circle.
   3827 @param radius Radius of the circle.
   3828 @param color Circle color.
   3829 @param thickness Thickness of the circle outline, if positive. Negative thickness means that a
   3830 filled circle is to be drawn.
   3831 @param lineType Type of the circle boundary. See the line description.
   3832 @param shift Number of fractional bits in the coordinates of the center and in the radius value.
   3833  */
   3834 CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius,
   3835                        const Scalar& color, int thickness = 1,
   3836                        int lineType = LINE_8, int shift = 0);
   3837 
   3838 /** @brief Draws a simple or thick elliptic arc or fills an ellipse sector.
   3839 
   3840 The functions ellipse with less parameters draw an ellipse outline, a filled ellipse, an elliptic
   3841 arc, or a filled ellipse sector. A piecewise-linear curve is used to approximate the elliptic arc
   3842 boundary. If you need more control of the ellipse rendering, you can retrieve the curve using
   3843 ellipse2Poly and then render it with polylines or fill it with fillPoly . If you use the first
   3844 variant of the function and want to draw the whole ellipse, not an arc, pass startAngle=0 and
   3845 endAngle=360 . The figure below explains the meaning of the parameters.
   3846 
   3847 ![Parameters of Elliptic Arc](pics/ellipse.png)
   3848 
   3849 @param img Image.
   3850 @param center Center of the ellipse.
   3851 @param axes Half of the size of the ellipse main axes.
   3852 @param angle Ellipse rotation angle in degrees.
   3853 @param startAngle Starting angle of the elliptic arc in degrees.
   3854 @param endAngle Ending angle of the elliptic arc in degrees.
   3855 @param color Ellipse color.
   3856 @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
   3857 a filled ellipse sector is to be drawn.
   3858 @param lineType Type of the ellipse boundary. See the line description.
   3859 @param shift Number of fractional bits in the coordinates of the center and values of axes.
   3860  */
   3861 CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,
   3862                         double angle, double startAngle, double endAngle,
   3863                         const Scalar& color, int thickness = 1,
   3864                         int lineType = LINE_8, int shift = 0);
   3865 
   3866 /** @overload
   3867 @param img Image.
   3868 @param box Alternative ellipse representation via RotatedRect. This means that the function draws
   3869 an ellipse inscribed in the rotated rectangle.
   3870 @param color Ellipse color.
   3871 @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
   3872 a filled ellipse sector is to be drawn.
   3873 @param lineType Type of the ellipse boundary. See the line description.
   3874 */
   3875 CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color,
   3876                         int thickness = 1, int lineType = LINE_8);
   3877 
   3878 /** @overload */
   3879 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
   3880                                const Scalar& color, int lineType = LINE_8,
   3881                                int shift = 0);
   3882 
   3883 /** @brief Fills a convex polygon.
   3884 
   3885 The function fillConvexPoly draws a filled convex polygon. This function is much faster than the
   3886 function cv::fillPoly . It can fill not only convex polygons but any monotonic polygon without
   3887 self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line)
   3888 twice at the most (though, its top-most and/or the bottom edge could be horizontal).
   3889 
   3890 @param img Image.
   3891 @param points Polygon vertices.
   3892 @param color Polygon color.
   3893 @param lineType Type of the polygon boundaries. See the line description.
   3894 @param shift Number of fractional bits in the vertex coordinates.
   3895  */
   3896 CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
   3897                                  const Scalar& color, int lineType = LINE_8,
   3898                                  int shift = 0);
   3899 
   3900 /** @overload */
   3901 CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
   3902                          const int* npts, int ncontours,
   3903                          const Scalar& color, int lineType = LINE_8, int shift = 0,
   3904                          Point offset = Point() );
   3905 
   3906 /** @brief Fills the area bounded by one or more polygons.
   3907 
   3908 The function fillPoly fills an area bounded by several polygonal contours. The function can fill
   3909 complex areas, for example, areas with holes, contours with self-intersections (some of their
   3910 parts), and so forth.
   3911 
   3912 @param img Image.
   3913 @param pts Array of polygons where each polygon is represented as an array of points.
   3914 @param color Polygon color.
   3915 @param lineType Type of the polygon boundaries. See the line description.
   3916 @param shift Number of fractional bits in the vertex coordinates.
   3917 @param offset Optional offset of all points of the contours.
   3918  */
   3919 CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
   3920                            const Scalar& color, int lineType = LINE_8, int shift = 0,
   3921                            Point offset = Point() );
   3922 
   3923 /** @overload */
   3924 CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts,
   3925                           int ncontours, bool isClosed, const Scalar& color,
   3926                           int thickness = 1, int lineType = LINE_8, int shift = 0 );
   3927 
   3928 /** @brief Draws several polygonal curves.
   3929 
   3930 @param img Image.
   3931 @param pts Array of polygonal curves.
   3932 @param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed,
   3933 the function draws a line from the last vertex of each curve to its first vertex.
   3934 @param color Polyline color.
   3935 @param thickness Thickness of the polyline edges.
   3936 @param lineType Type of the line segments. See the line description.
   3937 @param shift Number of fractional bits in the vertex coordinates.
   3938 
   3939 The function polylines draws one or more polygonal curves.
   3940  */
   3941 CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
   3942                             bool isClosed, const Scalar& color,
   3943                             int thickness = 1, int lineType = LINE_8, int shift = 0 );
   3944 
   3945 /** @example contours2.cpp
   3946   An example using the drawContour functionality
   3947 */
   3948 
   3949 /** @example segment_objects.cpp
   3950 An example using drawContours to clean up a background segmentation result
   3951  */
   3952 
   3953 /** @brief Draws contours outlines or filled contours.
   3954 
   3955 The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area
   3956 bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve
   3957 connected components from the binary image and label them: :
   3958 @code
   3959     #include "opencv2/imgproc.hpp"
   3960     #include "opencv2/highgui.hpp"
   3961 
   3962     using namespace cv;
   3963     using namespace std;
   3964 
   3965     int main( int argc, char** argv )
   3966     {
   3967         Mat src;
   3968         // the first command-line parameter must be a filename of the binary
   3969         // (black-n-white) image
   3970         if( argc != 2 || !(src=imread(argv[1], 0)).data)
   3971             return -1;
   3972 
   3973         Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
   3974 
   3975         src = src > 1;
   3976         namedWindow( "Source", 1 );
   3977         imshow( "Source", src );
   3978 
   3979         vector<vector<Point> > contours;
   3980         vector<Vec4i> hierarchy;
   3981 
   3982         findContours( src, contours, hierarchy,
   3983             RETR_CCOMP, CHAIN_APPROX_SIMPLE );
   3984 
   3985         // iterate through all the top-level contours,
   3986         // draw each connected component with its own random color
   3987         int idx = 0;
   3988         for( ; idx >= 0; idx = hierarchy[idx][0] )
   3989         {
   3990             Scalar color( rand()&255, rand()&255, rand()&255 );
   3991             drawContours( dst, contours, idx, color, FILLED, 8, hierarchy );
   3992         }
   3993 
   3994         namedWindow( "Components", 1 );
   3995         imshow( "Components", dst );
   3996         waitKey(0);
   3997     }
   3998 @endcode
   3999 
   4000 @param image Destination image.
   4001 @param contours All the input contours. Each contour is stored as a point vector.
   4002 @param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn.
   4003 @param color Color of the contours.
   4004 @param thickness Thickness of lines the contours are drawn with. If it is negative (for example,
   4005 thickness=CV_FILLED ), the contour interiors are drawn.
   4006 @param lineType Line connectivity. See cv::LineTypes.
   4007 @param hierarchy Optional information about hierarchy. It is only needed if you want to draw only
   4008 some of the contours (see maxLevel ).
   4009 @param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn.
   4010 If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function
   4011 draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This
   4012 parameter is only taken into account when there is hierarchy available.
   4013 @param offset Optional contour shift parameter. Shift all the drawn contours by the specified
   4014 \f$\texttt{offset}=(dx,dy)\f$ .
   4015  */
   4016 CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours,
   4017                               int contourIdx, const Scalar& color,
   4018                               int thickness = 1, int lineType = LINE_8,
   4019                               InputArray hierarchy = noArray(),
   4020                               int maxLevel = INT_MAX, Point offset = Point() );
   4021 
   4022 /** @brief Clips the line against the image rectangle.
   4023 
   4024 The functions clipLine calculate a part of the line segment that is entirely within the specified
   4025 rectangle. They return false if the line segment is completely outside the rectangle. Otherwise,
   4026 they return true .
   4027 @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
   4028 @param pt1 First line point.
   4029 @param pt2 Second line point.
   4030  */
   4031 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
   4032 
   4033 /** @overload
   4034 @param imgRect Image rectangle.
   4035 @param pt1 First line point.
   4036 @param pt2 Second line point.
   4037 */
   4038 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
   4039 
   4040 /** @brief Approximates an elliptic arc with a polyline.
   4041 
   4042 The function ellipse2Poly computes the vertices of a polyline that approximates the specified
   4043 elliptic arc. It is used by cv::ellipse.
   4044 
   4045 @param center Center of the arc.
   4046 @param axes Half of the size of the ellipse main axes. See the ellipse for details.
   4047 @param angle Rotation angle of the ellipse in degrees. See the ellipse for details.
   4048 @param arcStart Starting angle of the elliptic arc in degrees.
   4049 @param arcEnd Ending angle of the elliptic arc in degrees.
   4050 @param delta Angle between the subsequent polyline vertices. It defines the approximation
   4051 accuracy.
   4052 @param pts Output vector of polyline vertices.
   4053  */
   4054 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
   4055                                 int arcStart, int arcEnd, int delta,
   4056                                 CV_OUT std::vector<Point>& pts );
   4057 
   4058 /** @brief Draws a text string.
   4059 
   4060 The function putText renders the specified text string in the image. Symbols that cannot be rendered
   4061 using the specified font are replaced by question marks. See getTextSize for a text rendering code
   4062 example.
   4063 
   4064 @param img Image.
   4065 @param text Text string to be drawn.
   4066 @param org Bottom-left corner of the text string in the image.
   4067 @param fontFace Font type, see cv::HersheyFonts.
   4068 @param fontScale Font scale factor that is multiplied by the font-specific base size.
   4069 @param color Text color.
   4070 @param thickness Thickness of the lines used to draw a text.
   4071 @param lineType Line type. See the line for details.
   4072 @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,
   4073 it is at the top-left corner.
   4074  */
   4075 CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org,
   4076                          int fontFace, double fontScale, Scalar color,
   4077                          int thickness = 1, int lineType = LINE_8,
   4078                          bool bottomLeftOrigin = false );
   4079 
   4080 /** @brief Calculates the width and height of a text string.
   4081 
   4082 The function getTextSize calculates and returns the size of a box that contains the specified text.
   4083 That is, the following code renders some text, the tight box surrounding it, and the baseline: :
   4084 @code
   4085     String text = "Funny text inside the box";
   4086     int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
   4087     double fontScale = 2;
   4088     int thickness = 3;
   4089 
   4090     Mat img(600, 800, CV_8UC3, Scalar::all(0));
   4091 
   4092     int baseline=0;
   4093     Size textSize = getTextSize(text, fontFace,
   4094                                 fontScale, thickness, &baseline);
   4095     baseline += thickness;
   4096 
   4097     // center the text
   4098     Point textOrg((img.cols - textSize.width)/2,
   4099                   (img.rows + textSize.height)/2);
   4100 
   4101     // draw the box
   4102     rectangle(img, textOrg + Point(0, baseline),
   4103               textOrg + Point(textSize.width, -textSize.height),
   4104               Scalar(0,0,255));
   4105     // ... and the baseline first
   4106     line(img, textOrg + Point(0, thickness),
   4107          textOrg + Point(textSize.width, thickness),
   4108          Scalar(0, 0, 255));
   4109 
   4110     // then put the text itself
   4111     putText(img, text, textOrg, fontFace, fontScale,
   4112             Scalar::all(255), thickness, 8);
   4113 @endcode
   4114 
   4115 @param text Input text string.
   4116 @param fontFace Font to use, see cv::HersheyFonts.
   4117 @param fontScale Font scale factor that is multiplied by the font-specific base size.
   4118 @param thickness Thickness of lines used to render the text. See putText for details.
   4119 @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text
   4120 point.
   4121 @return The size of a box that contains the specified text.
   4122 
   4123 @see cv::putText
   4124  */
   4125 CV_EXPORTS_W Size getTextSize(const String& text, int fontFace,
   4126                             double fontScale, int thickness,
   4127                             CV_OUT int* baseLine);
   4128 
   4129 /** @brief Line iterator
   4130 
   4131 The class is used to iterate over all the pixels on the raster line
   4132 segment connecting two specified points.
   4133 
   4134 The class LineIterator is used to get each pixel of a raster line. It
   4135 can be treated as versatile implementation of the Bresenham algorithm
   4136 where you can stop at each pixel and do some extra processing, for
   4137 example, grab pixel values along the line or draw a line with an effect
   4138 (for example, with XOR operation).
   4139 
   4140 The number of pixels along the line is stored in LineIterator::count.
   4141 The method LineIterator::pos returns the current position in the image:
   4142 
   4143 @code{.cpp}
   4144 // grabs pixels along the line (pt1, pt2)
   4145 // from 8-bit 3-channel image to the buffer
   4146 LineIterator it(img, pt1, pt2, 8);
   4147 LineIterator it2 = it;
   4148 vector<Vec3b> buf(it.count);
   4149 
   4150 for(int i = 0; i < it.count; i++, ++it)
   4151     buf[i] = *(const Vec3b)*it;
   4152 
   4153 // alternative way of iterating through the line
   4154 for(int i = 0; i < it2.count; i++, ++it2)
   4155 {
   4156     Vec3b val = img.at<Vec3b>(it2.pos());
   4157     CV_Assert(buf[i] == val);
   4158 }
   4159 @endcode
   4160 */
   4161 class CV_EXPORTS LineIterator
   4162 {
   4163 public:
   4164     /** @brief intializes the iterator
   4165 
   4166     creates iterators for the line connecting pt1 and pt2
   4167     the line will be clipped on the image boundaries
   4168     the line is 8-connected or 4-connected
   4169     If leftToRight=true, then the iteration is always done
   4170     from the left-most point to the right most,
   4171     not to depend on the ordering of pt1 and pt2 parameters
   4172     */
   4173     LineIterator( const Mat& img, Point pt1, Point pt2,
   4174                   int connectivity = 8, bool leftToRight = false );
   4175     /** @brief returns pointer to the current pixel
   4176     */
   4177     uchar* operator *();
   4178     /** @brief prefix increment operator (++it). shifts iterator to the next pixel
   4179     */
   4180     LineIterator& operator ++();
   4181     /** @brief postfix increment operator (it++). shifts iterator to the next pixel
   4182     */
   4183     LineIterator operator ++(int);
   4184     /** @brief returns coordinates of the current pixel
   4185     */
   4186     Point pos() const;
   4187 
   4188     uchar* ptr;
   4189     const uchar* ptr0;
   4190     int step, elemSize;
   4191     int err, count;
   4192     int minusDelta, plusDelta;
   4193     int minusStep, plusStep;
   4194 };
   4195 
   4196 //! @cond IGNORED
   4197 
   4198 // === LineIterator implementation ===
   4199 
   4200 inline
   4201 uchar* LineIterator::operator *()
   4202 {
   4203     return ptr;
   4204 }
   4205 
   4206 inline
   4207 LineIterator& LineIterator::operator ++()
   4208 {
   4209     int mask = err < 0 ? -1 : 0;
   4210     err += minusDelta + (plusDelta & mask);
   4211     ptr += minusStep + (plusStep & mask);
   4212     return *this;
   4213 }
   4214 
   4215 inline
   4216 LineIterator LineIterator::operator ++(int)
   4217 {
   4218     LineIterator it = *this;
   4219     ++(*this);
   4220     return it;
   4221 }
   4222 
   4223 inline
   4224 Point LineIterator::pos() const
   4225 {
   4226     Point p;
   4227     p.y = (int)((ptr - ptr0)/step);
   4228     p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize);
   4229     return p;
   4230 }
   4231 
   4232 //! @endcond
   4233 
   4234 //! @} imgproc_draw
   4235 
   4236 //! @} imgproc
   4237 
   4238 } // cv
   4239 
   4240 #ifndef DISABLE_OPENCV_24_COMPATIBILITY
   4241 #include "opencv2/imgproc/imgproc_c.h"
   4242 #endif
   4243 
   4244 #endif
   4245