Path: blob/master/modules/imgproc/include/opencv2/imgproc.hpp
16339 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.15//16// Redistribution and use in source and binary forms, with or without modification,17// are permitted provided that the following conditions are met:18//19// * Redistribution's of source code must retain the above copyright notice,20// this list of conditions and the following disclaimer.21//22// * Redistribution's in binary form must reproduce the above copyright notice,23// this list of conditions and the following disclaimer in the documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// warranties of merchantability and fitness for a particular purpose are disclaimed.32// In no event shall the Intel Corporation or contributors be liable for any direct,33// indirect, incidental, special, exemplary, or consequential damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#ifndef OPENCV_IMGPROC_HPP43#define OPENCV_IMGPROC_HPP4445#include "opencv2/core.hpp"4647/**48@defgroup imgproc Image processing49@{50@defgroup imgproc_filter Image Filtering5152Functions and classes described in this section are used to perform various linear or non-linear53filtering operations on 2D images (represented as Mat's). It means that for each pixel location54\f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to55compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of56morphological operations, it is the minimum or maximum values, and so on. The computed response is57stored in the destination image at the same location \f$(x,y)\f$. It means that the output image58will be of the same size as the input image. Normally, the functions support multi-channel arrays,59in which case every channel is processed independently. Therefore, the output image will also have60the same number of channels as the input one.6162Another common feature of the functions and classes described in this section is that, unlike63simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For64example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when65processing the left-most pixels in each row, you need pixels to the left of them, that is, outside66of the image. You can let these pixels be the same as the left-most image pixels ("replicated67border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant68border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method.69For details, see #BorderTypes7071@anchor filter_depths72### Depth combinations73Input depth (src.depth()) | Output depth (ddepth)74--------------------------|----------------------75CV_8U | -1/CV_16S/CV_32F/CV_64F76CV_16U/CV_16S | -1/CV_32F/CV_64F77CV_32F | -1/CV_32F/CV_64F78CV_64F | -1/CV_64F7980@note when ddepth=-1, the output image will have the same depth as the source.8182@defgroup imgproc_transform Geometric Image Transformations8384The functions in this section perform various geometrical transformations of 2D images. They do not85change the image content but deform the pixel grid and map this deformed grid to the destination86image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from87destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the88functions compute coordinates of the corresponding "donor" pixel in the source image and copy the89pixel value:9091\f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f]9293In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow94\texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping95\f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula.9697The actual implementations of the geometrical transformations, from the most generic remap and to98the simplest and the fastest resize, need to solve two main problems with the above formula:99100- Extrapolation of non-existing pixels. Similarly to the filtering functions described in the101previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both102of them may fall outside of the image. In this case, an extrapolation method needs to be used.103OpenCV provides the same selection of extrapolation methods as in the filtering functions. In104addition, it provides the method #BORDER_TRANSPARENT. This means that the corresponding pixels in105the destination image will not be modified at all.106107- Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point108numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective109transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional110coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the111nearest integer coordinates and the corresponding pixel can be used. This is called a112nearest-neighbor interpolation. However, a better result can be achieved by using more113sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) ,114where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y),115f_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 the116interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See117resize for details.118119@note The geometrical transformations do not work with `CV_8S` or `CV_32S` images.120121@defgroup imgproc_misc Miscellaneous Image Transformations122@defgroup imgproc_draw Drawing Functions123124Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be125rendered with antialiasing (implemented only for 8-bit images for now). All the functions include126the parameter color that uses an RGB value (that may be constructed with the Scalar constructor )127for color images and brightness for grayscale images. For color images, the channel ordering is128normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a129color using the Scalar constructor, it should look like:130131\f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f]132133If you are using your own image rendering and I/O functions, you can use any channel ordering. The134drawing functions process each channel independently and do not depend on the channel order or even135on the used color space. The whole image can be converted from BGR to RGB or to a different color136space using cvtColor .137138If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also,139many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means140that the coordinates can be passed as fixed-point numbers encoded as integers. The number of141fractional bits is specified by the shift parameter and the real point coordinates are calculated as142\f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is143especially effective when rendering antialiased shapes.144145@note The functions do not support alpha-transparency when the target image is 4-channel. In this146case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint147semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main148image.149150@defgroup imgproc_colormap ColorMaps in OpenCV151152The human perception isn't built for observing fine changes in grayscale images. Human eyes are more153sensitive to observing changes between colors, so you often need to recolor your grayscale images to154get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your155computer vision application.156157In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample158code reads the path to an image from command line, applies a Jet colormap on it and shows the159result:160161@include snippets/imgproc_applyColorMap.cpp162163@see #ColormapTypes164165@defgroup imgproc_subdiv2d Planar Subdivision166167The Subdiv2D class described in this section is used to perform various planar subdivision on168a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles169using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram.170In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi171diagram with red lines.172173174175The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast176location of points on the plane, building special graphs (such as NNG,RNG), and so forth.177178@defgroup imgproc_hist Histograms179@defgroup imgproc_shape Structural Analysis and Shape Descriptors180@defgroup imgproc_motion Motion Analysis and Object Tracking181@defgroup imgproc_feature Feature Detection182@defgroup imgproc_object Object Detection183@defgroup imgproc_c C API184@defgroup imgproc_hal Hardware Acceleration Layer185@{186@defgroup imgproc_hal_functions Functions187@defgroup imgproc_hal_interface Interface188@}189@}190*/191192namespace cv193{194195/** @addtogroup imgproc196@{197*/198199//! @addtogroup imgproc_filter200//! @{201202//! type of morphological operation203enum MorphTypes{204MORPH_ERODE = 0, //!< see #erode205MORPH_DILATE = 1, //!< see #dilate206MORPH_OPEN = 2, //!< an opening operation207//!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f]208MORPH_CLOSE = 3, //!< a closing operation209//!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f]210MORPH_GRADIENT = 4, //!< a morphological gradient211//!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f]212MORPH_TOPHAT = 5, //!< "top hat"213//!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f]214MORPH_BLACKHAT = 6, //!< "black hat"215//!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f]216MORPH_HITMISS = 7 //!< "hit or miss"217//!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation218};219220//! shape of the structuring element221enum MorphShapes {222MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f]223MORPH_CROSS = 1, //!< a cross-shaped structuring element:224//!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f]225MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed226//!< into the rectangle Rect(0, 0, esize.width, 0.esize.height)227};228229//! @} imgproc_filter230231//! @addtogroup imgproc_transform232//! @{233234//! interpolation algorithm235enum InterpolationFlags{236/** nearest neighbor interpolation */237INTER_NEAREST = 0,238/** bilinear interpolation */239INTER_LINEAR = 1,240/** bicubic interpolation */241INTER_CUBIC = 2,242/** resampling using pixel area relation. It may be a preferred method for image decimation, as243it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST244method. */245INTER_AREA = 3,246/** Lanczos interpolation over 8x8 neighborhood */247INTER_LANCZOS4 = 4,248/** Bit exact bilinear interpolation */249INTER_LINEAR_EXACT = 5,250/** mask for interpolation codes */251INTER_MAX = 7,252/** flag, fills all of the destination image pixels. If some of them correspond to outliers in the253source image, they are set to zero */254WARP_FILL_OUTLIERS = 8,255/** flag, inverse transformation256257For example, #linearPolar or #logPolar transforms:258- flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$259- flag is set: \f$dst(x,y) = src( \rho , \phi )\f$260*/261WARP_INVERSE_MAP = 16262};263264/** \brief Specify the polar mapping mode265@sa warpPolar266*/267enum WarpPolarMode268{269WARP_POLAR_LINEAR = 0, ///< Remaps an image to/from polar space.270WARP_POLAR_LOG = 256 ///< Remaps an image to/from semilog-polar space.271};272273enum InterpolationMasks {274INTER_BITS = 5,275INTER_BITS2 = INTER_BITS * 2,276INTER_TAB_SIZE = 1 << INTER_BITS,277INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE278};279280//! @} imgproc_transform281282//! @addtogroup imgproc_misc283//! @{284285//! Distance types for Distance Transform and M-estimators286//! @see distanceTransform, fitLine287enum DistanceTypes {288DIST_USER = -1, //!< User defined distance289DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2|290DIST_L2 = 2, //!< the simple euclidean distance291DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|)292DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))293DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998294DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846295DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345296};297298//! Mask size for distance transform299enum DistanceTransformMasks {300DIST_MASK_3 = 3, //!< mask=3301DIST_MASK_5 = 5, //!< mask=5302DIST_MASK_PRECISE = 0 //!<303};304305//! type of the threshold operation306//! 307enum ThresholdTypes {308THRESH_BINARY = 0, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]309THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f]310THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]311THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]312THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]313THRESH_MASK = 7,314THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value315THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value316};317318//! adaptive threshold algorithm319//! @see adaptiveThreshold320enum AdaptiveThresholdTypes {321/** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times322\texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */323ADAPTIVE_THRESH_MEAN_C = 0,324/** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian325window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$326minus C . The default sigma (standard deviation) is used for the specified blockSize . See327#getGaussianKernel*/328ADAPTIVE_THRESH_GAUSSIAN_C = 1329};330331//! class of the pixel in GrabCut algorithm332enum GrabCutClasses {333GC_BGD = 0, //!< an obvious background pixels334GC_FGD = 1, //!< an obvious foreground (object) pixel335GC_PR_BGD = 2, //!< a possible background pixel336GC_PR_FGD = 3 //!< a possible foreground pixel337};338339//! GrabCut algorithm flags340enum GrabCutModes {341/** The function initializes the state and the mask using the provided rectangle. After that it342runs iterCount iterations of the algorithm. */343GC_INIT_WITH_RECT = 0,344/** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT345and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are346automatically initialized with GC_BGD .*/347GC_INIT_WITH_MASK = 1,348/** The value means that the algorithm should just resume. */349GC_EVAL = 2,350/** The value means that the algorithm should just run the grabCut algorithm (a single iteration) with the fixed model */351GC_EVAL_FREEZE_MODEL = 3352};353354//! distanceTransform algorithm flags355enum DistanceTransformLabelTypes {356/** each connected component of zeros in src (as well as all the non-zero pixels closest to the357connected component) will be assigned the same label */358DIST_LABEL_CCOMP = 0,359/** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */360DIST_LABEL_PIXEL = 1361};362363//! floodfill algorithm flags364enum FloodFillFlags {365/** If set, the difference between the current pixel and seed pixel is considered. Otherwise,366the difference between neighbor pixels is considered (that is, the range is floating). */367FLOODFILL_FIXED_RANGE = 1 << 16,368/** If set, the function does not change the image ( newVal is ignored), and only fills the369mask with the value specified in bits 8-16 of flags as described above. This option only make370sense in function variants that have the mask parameter. */371FLOODFILL_MASK_ONLY = 1 << 17372};373374//! @} imgproc_misc375376//! @addtogroup imgproc_shape377//! @{378379//! connected components algorithm output formats380enum ConnectedComponentsTypes {381CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding382//!< box in the horizontal direction.383CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding384//!< box in the vertical direction.385CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box386CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box387CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component388CC_STAT_MAX = 5389};390391//! connected components algorithm392enum ConnectedComponentsAlgorithmsTypes {393CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity394CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity395CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity396};397398//! mode of the contour retrieval algorithm399enum RetrievalModes {400/** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for401all the contours. */402RETR_EXTERNAL = 0,403/** retrieves all of the contours without establishing any hierarchical relationships. */404RETR_LIST = 1,405/** retrieves all of the contours and organizes them into a two-level hierarchy. At the top406level, there are external boundaries of the components. At the second level, there are407boundaries of the holes. If there is another contour inside a hole of a connected component, it408is still put at the top level. */409RETR_CCOMP = 2,410/** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/411RETR_TREE = 3,412RETR_FLOODFILL = 4 //!<413};414415//! the contour approximation algorithm416enum ContourApproximationModes {417/** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and418(x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is,419max(abs(x1-x2),abs(y2-y1))==1. */420CHAIN_APPROX_NONE = 1,421/** compresses horizontal, vertical, and diagonal segments and leaves only their end points.422For example, an up-right rectangular contour is encoded with 4 points. */423CHAIN_APPROX_SIMPLE = 2,424/** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */425CHAIN_APPROX_TC89_L1 = 3,426/** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */427CHAIN_APPROX_TC89_KCOS = 4428};429430/** @brief Shape matching methods431432\f$A\f$ denotes object1,\f$B\f$ denotes object2433434\f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$435436and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively.437*/438enum ShapeMatchModes {439CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f]440CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f]441CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f]442};443444//! @} imgproc_shape445446//! Variants of a Hough transform447enum HoughModes {448449/** classical or standard Hough transform. Every line is represented by two floating-point450numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line,451and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must452be (the created sequence will be) of CV_32FC2 type */453HOUGH_STANDARD = 0,454/** probabilistic Hough transform (more efficient in case if the picture contains a few long455linear segments). It returns line segments rather than the whole line. Each segment is456represented by starting and ending points, and the matrix must be (the created sequence will457be) of the CV_32SC4 type. */458HOUGH_PROBABILISTIC = 1,459/** multi-scale variant of the classical Hough transform. The lines are encoded the same way as460HOUGH_STANDARD. */461HOUGH_MULTI_SCALE = 2,462HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90463};464465//! Variants of Line Segment %Detector466//! @ingroup imgproc_feature467enum LineSegmentDetectorModes {468LSD_REFINE_NONE = 0, //!< No refinement applied469LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations.470LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are471//!< refined through increase of precision, decrement in size, etc.472};473474/** Histogram comparison methods475@ingroup imgproc_hist476*/477enum HistCompMethods {478/** Correlation479\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]480where481\f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f]482and \f$N\f$ is a total number of histogram bins. */483HISTCMP_CORREL = 0,484/** Chi-Square485\f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */486HISTCMP_CHISQR = 1,487/** Intersection488\f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */489HISTCMP_INTERSECT = 2,490/** Bhattacharyya distance491(In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.)492\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] */493HISTCMP_BHATTACHARYYA = 3,494HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA495/** Alternative Chi-Square496\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]497This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */498HISTCMP_CHISQR_ALT = 4,499/** Kullback-Leibler divergence500\f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */501HISTCMP_KL_DIV = 5502};503504/** the color conversion code505@see @ref imgproc_color_conversions506@ingroup imgproc_misc507*/508enum ColorConversionCodes {509COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image510COLOR_RGB2RGBA = COLOR_BGR2BGRA,511512COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image513COLOR_RGBA2RGB = COLOR_BGRA2BGR,514515COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)516COLOR_RGB2BGRA = COLOR_BGR2RGBA,517518COLOR_RGBA2BGR = 3,519COLOR_BGRA2RGB = COLOR_RGBA2BGR,520521COLOR_BGR2RGB = 4,522COLOR_RGB2BGR = COLOR_BGR2RGB,523524COLOR_BGRA2RGBA = 5,525COLOR_RGBA2BGRA = COLOR_BGRA2RGBA,526527COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"528COLOR_RGB2GRAY = 7,529COLOR_GRAY2BGR = 8,530COLOR_GRAY2RGB = COLOR_GRAY2BGR,531COLOR_GRAY2BGRA = 9,532COLOR_GRAY2RGBA = COLOR_GRAY2BGRA,533COLOR_BGRA2GRAY = 10,534COLOR_RGBA2GRAY = 11,535536COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images)537COLOR_RGB2BGR565 = 13,538COLOR_BGR5652BGR = 14,539COLOR_BGR5652RGB = 15,540COLOR_BGRA2BGR565 = 16,541COLOR_RGBA2BGR565 = 17,542COLOR_BGR5652BGRA = 18,543COLOR_BGR5652RGBA = 19,544545COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images)546COLOR_BGR5652GRAY = 21,547548COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images)549COLOR_RGB2BGR555 = 23,550COLOR_BGR5552BGR = 24,551COLOR_BGR5552RGB = 25,552COLOR_BGRA2BGR555 = 26,553COLOR_RGBA2BGR555 = 27,554COLOR_BGR5552BGRA = 28,555COLOR_BGR5552RGBA = 29,556557COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images)558COLOR_BGR5552GRAY = 31,559560COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"561COLOR_RGB2XYZ = 33,562COLOR_XYZ2BGR = 34,563COLOR_XYZ2RGB = 35,564565COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions"566COLOR_RGB2YCrCb = 37,567COLOR_YCrCb2BGR = 38,568COLOR_YCrCb2RGB = 39,569570COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"571COLOR_RGB2HSV = 41,572573COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"574COLOR_RGB2Lab = 45,575576COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"577COLOR_RGB2Luv = 51,578COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"579COLOR_RGB2HLS = 53,580581COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR582COLOR_HSV2RGB = 55,583584COLOR_Lab2BGR = 56,585COLOR_Lab2RGB = 57,586COLOR_Luv2BGR = 58,587COLOR_Luv2RGB = 59,588COLOR_HLS2BGR = 60,589COLOR_HLS2RGB = 61,590591COLOR_BGR2HSV_FULL = 66, //!<592COLOR_RGB2HSV_FULL = 67,593COLOR_BGR2HLS_FULL = 68,594COLOR_RGB2HLS_FULL = 69,595596COLOR_HSV2BGR_FULL = 70,597COLOR_HSV2RGB_FULL = 71,598COLOR_HLS2BGR_FULL = 72,599COLOR_HLS2RGB_FULL = 73,600601COLOR_LBGR2Lab = 74,602COLOR_LRGB2Lab = 75,603COLOR_LBGR2Luv = 76,604COLOR_LRGB2Luv = 77,605606COLOR_Lab2LBGR = 78,607COLOR_Lab2LRGB = 79,608COLOR_Luv2LBGR = 80,609COLOR_Luv2LRGB = 81,610611COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV612COLOR_RGB2YUV = 83,613COLOR_YUV2BGR = 84,614COLOR_YUV2RGB = 85,615616//! YUV 4:2:0 family to RGB617COLOR_YUV2RGB_NV12 = 90,618COLOR_YUV2BGR_NV12 = 91,619COLOR_YUV2RGB_NV21 = 92,620COLOR_YUV2BGR_NV21 = 93,621COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,622COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,623624COLOR_YUV2RGBA_NV12 = 94,625COLOR_YUV2BGRA_NV12 = 95,626COLOR_YUV2RGBA_NV21 = 96,627COLOR_YUV2BGRA_NV21 = 97,628COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,629COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,630631COLOR_YUV2RGB_YV12 = 98,632COLOR_YUV2BGR_YV12 = 99,633COLOR_YUV2RGB_IYUV = 100,634COLOR_YUV2BGR_IYUV = 101,635COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,636COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,637COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,638COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,639640COLOR_YUV2RGBA_YV12 = 102,641COLOR_YUV2BGRA_YV12 = 103,642COLOR_YUV2RGBA_IYUV = 104,643COLOR_YUV2BGRA_IYUV = 105,644COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,645COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,646COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,647COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,648649COLOR_YUV2GRAY_420 = 106,650COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,651COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,652COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,653COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,654COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,655COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,656COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,657658//! YUV 4:2:2 family to RGB659COLOR_YUV2RGB_UYVY = 107,660COLOR_YUV2BGR_UYVY = 108,661//COLOR_YUV2RGB_VYUY = 109,662//COLOR_YUV2BGR_VYUY = 110,663COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,664COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,665COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,666COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,667668COLOR_YUV2RGBA_UYVY = 111,669COLOR_YUV2BGRA_UYVY = 112,670//COLOR_YUV2RGBA_VYUY = 113,671//COLOR_YUV2BGRA_VYUY = 114,672COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,673COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,674COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,675COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,676677COLOR_YUV2RGB_YUY2 = 115,678COLOR_YUV2BGR_YUY2 = 116,679COLOR_YUV2RGB_YVYU = 117,680COLOR_YUV2BGR_YVYU = 118,681COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,682COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,683COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,684COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,685686COLOR_YUV2RGBA_YUY2 = 119,687COLOR_YUV2BGRA_YUY2 = 120,688COLOR_YUV2RGBA_YVYU = 121,689COLOR_YUV2BGRA_YVYU = 122,690COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,691COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,692COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,693COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,694695COLOR_YUV2GRAY_UYVY = 123,696COLOR_YUV2GRAY_YUY2 = 124,697//CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY,698COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,699COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,700COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,701COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,702COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,703704//! alpha premultiplication705COLOR_RGBA2mRGBA = 125,706COLOR_mRGBA2RGBA = 126,707708//! RGB to YUV 4:2:0 family709COLOR_RGB2YUV_I420 = 127,710COLOR_BGR2YUV_I420 = 128,711COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420,712COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420,713714COLOR_RGBA2YUV_I420 = 129,715COLOR_BGRA2YUV_I420 = 130,716COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,717COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,718COLOR_RGB2YUV_YV12 = 131,719COLOR_BGR2YUV_YV12 = 132,720COLOR_RGBA2YUV_YV12 = 133,721COLOR_BGRA2YUV_YV12 = 134,722723//! Demosaicing724COLOR_BayerBG2BGR = 46,725COLOR_BayerGB2BGR = 47,726COLOR_BayerRG2BGR = 48,727COLOR_BayerGR2BGR = 49,728729COLOR_BayerBG2RGB = COLOR_BayerRG2BGR,730COLOR_BayerGB2RGB = COLOR_BayerGR2BGR,731COLOR_BayerRG2RGB = COLOR_BayerBG2BGR,732COLOR_BayerGR2RGB = COLOR_BayerGB2BGR,733734COLOR_BayerBG2GRAY = 86,735COLOR_BayerGB2GRAY = 87,736COLOR_BayerRG2GRAY = 88,737COLOR_BayerGR2GRAY = 89,738739//! Demosaicing using Variable Number of Gradients740COLOR_BayerBG2BGR_VNG = 62,741COLOR_BayerGB2BGR_VNG = 63,742COLOR_BayerRG2BGR_VNG = 64,743COLOR_BayerGR2BGR_VNG = 65,744745COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG,746COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG,747COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG,748COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG,749750//! Edge-Aware Demosaicing751COLOR_BayerBG2BGR_EA = 135,752COLOR_BayerGB2BGR_EA = 136,753COLOR_BayerRG2BGR_EA = 137,754COLOR_BayerGR2BGR_EA = 138,755756COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA,757COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA,758COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA,759COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA,760761//! Demosaicing with alpha channel762COLOR_BayerBG2BGRA = 139,763COLOR_BayerGB2BGRA = 140,764COLOR_BayerRG2BGRA = 141,765COLOR_BayerGR2BGRA = 142,766767COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA,768COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA,769COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA,770COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA,771772COLOR_COLORCVT_MAX = 143773};774775/** types of intersection between rectangles776@ingroup imgproc_shape777*/778enum RectanglesIntersectTypes {779INTERSECT_NONE = 0, //!< No intersection780INTERSECT_PARTIAL = 1, //!< There is a partial intersection781INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other782};783784785/** types of line786@ingroup imgproc_draw787*/788enum LineTypes {789FILLED = -1,790LINE_4 = 4, //!< 4-connected line791LINE_8 = 8, //!< 8-connected line792LINE_AA = 16 //!< antialiased line793};794795/** Only a subset of Hershey fonts <https://en.wikipedia.org/wiki/Hershey_fonts> are supported796@ingroup imgproc_draw797*/798enum HersheyFonts {799FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font800FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font801FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)802FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font803FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX)804FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX805FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font806FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX807FONT_ITALIC = 16 //!< flag for italic font808};809810/** Possible set of marker types used for the cv::drawMarker function811@ingroup imgproc_draw812*/813enum MarkerTypes814{815MARKER_CROSS = 0, //!< A crosshair marker shape816MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape817MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross818MARKER_DIAMOND = 3, //!< A diamond marker shape819MARKER_SQUARE = 4, //!< A square marker shape820MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape821MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape822};823824//! finds arbitrary template in the grayscale image using Generalized Hough Transform825class CV_EXPORTS_W GeneralizedHough : public Algorithm826{827public:828//! set template to search829CV_WRAP virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0;830CV_WRAP virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0;831832//! find template on image833CV_WRAP virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0;834CV_WRAP virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0;835836//! Canny low threshold.837CV_WRAP virtual void setCannyLowThresh(int cannyLowThresh) = 0;838CV_WRAP virtual int getCannyLowThresh() const = 0;839840//! Canny high threshold.841CV_WRAP virtual void setCannyHighThresh(int cannyHighThresh) = 0;842CV_WRAP virtual int getCannyHighThresh() const = 0;843844//! Minimum distance between the centers of the detected objects.845CV_WRAP virtual void setMinDist(double minDist) = 0;846CV_WRAP virtual double getMinDist() const = 0;847848//! Inverse ratio of the accumulator resolution to the image resolution.849CV_WRAP virtual void setDp(double dp) = 0;850CV_WRAP virtual double getDp() const = 0;851852//! Maximal size of inner buffers.853CV_WRAP virtual void setMaxBufferSize(int maxBufferSize) = 0;854CV_WRAP virtual int getMaxBufferSize() const = 0;855};856857//! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.858//! Detects position only without translation and rotation859class CV_EXPORTS_W GeneralizedHoughBallard : public GeneralizedHough860{861public:862//! R-Table levels.863CV_WRAP virtual void setLevels(int levels) = 0;864CV_WRAP virtual int getLevels() const = 0;865866//! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected.867CV_WRAP virtual void setVotesThreshold(int votesThreshold) = 0;868CV_WRAP virtual int getVotesThreshold() const = 0;869};870871//! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.872//! Detects position, translation and rotation873class CV_EXPORTS_W GeneralizedHoughGuil : public GeneralizedHough874{875public:876//! Angle difference in degrees between two points in feature.877virtual void setXi(double xi) = 0;878virtual double getXi() const = 0;879880//! Feature table levels.881virtual void setLevels(int levels) = 0;882virtual int getLevels() const = 0;883884//! Maximal difference between angles that treated as equal.885virtual void setAngleEpsilon(double angleEpsilon) = 0;886virtual double getAngleEpsilon() const = 0;887888//! Minimal rotation angle to detect in degrees.889virtual void setMinAngle(double minAngle) = 0;890virtual double getMinAngle() const = 0;891892//! Maximal rotation angle to detect in degrees.893virtual void setMaxAngle(double maxAngle) = 0;894virtual double getMaxAngle() const = 0;895896//! Angle step in degrees.897virtual void setAngleStep(double angleStep) = 0;898virtual double getAngleStep() const = 0;899900//! Angle votes threshold.901virtual void setAngleThresh(int angleThresh) = 0;902virtual int getAngleThresh() const = 0;903904//! Minimal scale to detect.905virtual void setMinScale(double minScale) = 0;906virtual double getMinScale() const = 0;907908//! Maximal scale to detect.909virtual void setMaxScale(double maxScale) = 0;910virtual double getMaxScale() const = 0;911912//! Scale step.913virtual void setScaleStep(double scaleStep) = 0;914virtual double getScaleStep() const = 0;915916//! Scale votes threshold.917virtual void setScaleThresh(int scaleThresh) = 0;918virtual int getScaleThresh() const = 0;919920//! Position votes threshold.921virtual void setPosThresh(int posThresh) = 0;922virtual int getPosThresh() const = 0;923};924925/** @brief Base class for Contrast Limited Adaptive Histogram Equalization. :926*/927class CV_EXPORTS_W CLAHE : public Algorithm928{929public:930/** @brief Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization.931932@param src Source image with CV_8UC1 type.933@param dst Destination image.934*/935CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0;936937/** @brief Sets threshold for contrast limiting.938939@param clipLimit threshold value.940*/941CV_WRAP virtual void setClipLimit(double clipLimit) = 0;942943//! Returns threshold value for contrast limiting.944CV_WRAP virtual double getClipLimit() const = 0;945946/** @brief Sets size of grid for histogram equalization. Input image will be divided into947equally sized rectangular tiles.948949@param tileGridSize defines the number of tiles in row and column.950*/951CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0;952953//!@brief Returns Size defines the number of tiles in row and column.954CV_WRAP virtual Size getTilesGridSize() const = 0;955956CV_WRAP virtual void collectGarbage() = 0;957};958959960//! @addtogroup imgproc_subdiv2d961//! @{962963class CV_EXPORTS_W Subdiv2D964{965public:966/** Subdiv2D point location cases */967enum { PTLOC_ERROR = -2, //!< Point location error968PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect969PTLOC_INSIDE = 0, //!< Point inside some facet970PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices971PTLOC_ON_EDGE = 2 //!< Point on some edge972};973974/** Subdiv2D edge type navigation (see: getEdge()) */975enum { NEXT_AROUND_ORG = 0x00,976NEXT_AROUND_DST = 0x22,977PREV_AROUND_ORG = 0x11,978PREV_AROUND_DST = 0x33,979NEXT_AROUND_LEFT = 0x13,980NEXT_AROUND_RIGHT = 0x31,981PREV_AROUND_LEFT = 0x20,982PREV_AROUND_RIGHT = 0x02983};984985/** creates an empty Subdiv2D object.986To create a new empty Delaunay subdivision you need to use the #initDelaunay function.987*/988CV_WRAP Subdiv2D();989990/** @overload991992@param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.993994The function creates an empty Delaunay subdivision where 2D points can be added using the function995insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime996error is raised.997*/998CV_WRAP Subdiv2D(Rect rect);9991000/** @brief Creates a new empty Delaunay subdivision10011002@param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.10031004*/1005CV_WRAP void initDelaunay(Rect rect);10061007/** @brief Insert a single point into a Delaunay triangulation.10081009@param pt Point to insert.10101011The function inserts a single point into a subdivision and modifies the subdivision topology1012appropriately. If a point with the same coordinates exists already, no new point is added.1013@returns the ID of the point.10141015@note If the point is outside of the triangulation specified rect a runtime error is raised.1016*/1017CV_WRAP int insert(Point2f pt);10181019/** @brief Insert multiple points into a Delaunay triangulation.10201021@param ptvec Points to insert.10221023The function inserts a vector of points into a subdivision and modifies the subdivision topology1024appropriately.1025*/1026CV_WRAP void insert(const std::vector<Point2f>& ptvec);10271028/** @brief Returns the location of a point within a Delaunay triangulation.10291030@param pt Point to locate.1031@param edge Output edge that the point belongs to or is located to the right of it.1032@param vertex Optional output vertex the input point coincides with.10331034The function locates the input point within the subdivision and gives one of the triangle edges1035or vertices.10361037@returns an integer which specify one of the following five cases for point location:1038- The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of1039edges of the facet.1040- The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge.1041- The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and1042vertex will contain a pointer to the vertex.1043- The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT1044and no pointers are filled.1045- One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error1046processing mode is selected, #PTLOC_ERROR is returned.1047*/1048CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex);10491050/** @brief Finds the subdivision vertex closest to the given point.10511052@param pt Input point.1053@param nearestPt Output subdivision vertex point.10541055The function is another function that locates the input point within the subdivision. It finds the1056subdivision vertex that is the closest to the input point. It is not necessarily one of vertices1057of the facet containing the input point, though the facet (located using locate() ) is used as a1058starting point.10591060@returns vertex ID.1061*/1062CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0);10631064/** @brief Returns a list of all edges.10651066@param edgeList Output vector.10671068The function gives each edge as a 4 numbers vector, where each two are one of the edge1069vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].1070*/1071CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const;10721073/** @brief Returns a list of the leading edge ID connected to each triangle.10741075@param leadingEdgeList Output vector.10761077The function gives one edge ID for each triangle.1078*/1079CV_WRAP void getLeadingEdgeList(CV_OUT std::vector<int>& leadingEdgeList) const;10801081/** @brief Returns a list of all triangles.10821083@param triangleList Output vector.10841085The function gives each triangle as a 6 numbers vector, where each two are one of the triangle1086vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5].1087*/1088CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const;10891090/** @brief Returns a list of all Voroni facets.10911092@param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector.1093@param facetList Output vector of the Voroni facets.1094@param facetCenters Output vector of the Voroni facets center points.10951096*/1097CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList,1098CV_OUT std::vector<Point2f>& facetCenters);10991100/** @brief Returns vertex location from vertex ID.11011102@param vertex vertex ID.1103@param firstEdge Optional. The first edge ID which is connected to the vertex.1104@returns vertex (x,y)11051106*/1107CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const;11081109/** @brief Returns one of the edges related to the given edge.11101111@param edge Subdivision edge ID.1112@param nextEdgeType Parameter specifying which of the related edges to return.1113The following values are possible:1114- NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)1115- NEXT_AROUND_DST next around the edge vertex ( eDnext )1116- PREV_AROUND_ORG previous around the edge origin (reversed eRnext )1117- PREV_AROUND_DST previous around the edge destination (reversed eLnext )1118- NEXT_AROUND_LEFT next around the left facet ( eLnext )1119- NEXT_AROUND_RIGHT next around the right facet ( eRnext )1120- PREV_AROUND_LEFT previous around the left facet (reversed eOnext )1121- PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )1122112311241125@returns edge ID related to the input edge.1126*/1127CV_WRAP int getEdge( int edge, int nextEdgeType ) const;11281129/** @brief Returns next edge around the edge origin.11301131@param edge Subdivision edge ID.11321133@returns an integer which is next edge ID around the edge origin: eOnext on the1134picture above if e is the input edge).1135*/1136CV_WRAP int nextEdge(int edge) const;11371138/** @brief Returns another edge of the same quad-edge.11391140@param edge Subdivision edge ID.1141@param rotate Parameter specifying which of the edges of the same quad-edge as the input1142one to return. The following values are possible:1143- 0 - the input edge ( e on the picture below if e is the input edge)1144- 1 - the rotated edge ( eRot )1145- 2 - the reversed edge (reversed e (in green))1146- 3 - the reversed rotated edge (reversed eRot (in green))11471148@returns one of the edges ID of the same quad-edge as the input edge.1149*/1150CV_WRAP int rotateEdge(int edge, int rotate) const;1151CV_WRAP int symEdge(int edge) const;11521153/** @brief Returns the edge origin.11541155@param edge Subdivision edge ID.1156@param orgpt Output vertex location.11571158@returns vertex ID.1159*/1160CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const;11611162/** @brief Returns the edge destination.11631164@param edge Subdivision edge ID.1165@param dstpt Output vertex location.11661167@returns vertex ID.1168*/1169CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const;11701171protected:1172int newEdge();1173void deleteEdge(int edge);1174int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0);1175void deletePoint(int vtx);1176void setEdgePoints( int edge, int orgPt, int dstPt );1177void splice( int edgeA, int edgeB );1178int connectEdges( int edgeA, int edgeB );1179void swapEdges( int edge );1180int isRightOf(Point2f pt, int edge) const;1181void calcVoronoi();1182void clearVoronoi();1183void checkSubdiv() const;11841185struct CV_EXPORTS Vertex1186{1187Vertex();1188Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0);1189bool isvirtual() const;1190bool isfree() const;11911192int firstEdge;1193int type;1194Point2f pt;1195};11961197struct CV_EXPORTS QuadEdge1198{1199QuadEdge();1200QuadEdge(int edgeidx);1201bool isfree() const;12021203int next[4];1204int pt[4];1205};12061207//! All of the vertices1208std::vector<Vertex> vtx;1209//! All of the edges1210std::vector<QuadEdge> qedges;1211int freeQEdge;1212int freePoint;1213bool validGeometry;12141215int recentEdge;1216//! Top left corner of the bounding rect1217Point2f topLeft;1218//! Bottom right corner of the bounding rect1219Point2f bottomRight;1220};12211222//! @} imgproc_subdiv2d12231224//! @addtogroup imgproc_feature1225//! @{12261227/** @example samples/cpp/lsd_lines.cpp1228An example using the LineSegmentDetector1229\image html building_lsd.png "Sample output image" width=434 height=3001230*/12311232/** @brief Line segment detector class12331234following the algorithm described at @cite Rafael12 .1235*/1236class CV_EXPORTS_W LineSegmentDetector : public Algorithm1237{1238public:12391240/** @brief Finds lines in the input image.12411242This is the output of the default parameters of the algorithm on the above shown image.1243124412451246@param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use:1247`lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);`1248@param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where1249Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly1250oriented depending on the gradient.1251@param width Vector of widths of the regions, where the lines are found. E.g. Width of line.1252@param prec Vector of precisions with which the lines are found.1253@param nfa Vector containing number of false alarms in the line region, with precision of 10%. The1254bigger the value, logarithmically better the detection.1255- -1 corresponds to 10 mean false alarms1256- 0 corresponds to 1 mean false alarm1257- 1 corresponds to 0.1 mean false alarms1258This vector will be calculated only when the objects type is #LSD_REFINE_ADV.1259*/1260CV_WRAP virtual void detect(InputArray _image, OutputArray _lines,1261OutputArray width = noArray(), OutputArray prec = noArray(),1262OutputArray nfa = noArray()) = 0;12631264/** @brief Draws the line segments on a given image.1265@param _image The image, where the lines will be drawn. Should be bigger or equal to the image,1266where the lines were found.1267@param lines A vector of the lines that needed to be drawn.1268*/1269CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0;12701271/** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels.12721273@param size The size of the image, where lines1 and lines2 were found.1274@param lines1 The first group of lines that needs to be drawn. It is visualized in blue color.1275@param lines2 The second group of lines. They visualized in red color.1276@param _image Optional image, where the lines will be drawn. The image should be color(3-channel)1277in order for lines1 and lines2 to be drawn in the above mentioned colors.1278*/1279CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0;12801281virtual ~LineSegmentDetector() { }1282};12831284/** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it.12851286The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want1287to edit those, as to tailor it for their own application.12881289@param _refine The way found lines will be refined, see #LineSegmentDetectorModes1290@param _scale The scale of the image that will be used to find the lines. Range (0..1].1291@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale.1292@param _quant Bound to the quantization error on the gradient norm.1293@param _ang_th Gradient angle tolerance in degrees.1294@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement1295is chosen.1296@param _density_th Minimal density of aligned region points in the enclosing rectangle.1297@param _n_bins Number of bins in pseudo-ordering of gradient modulus.1298*/1299CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(1300int _refine = LSD_REFINE_STD, double _scale = 0.8,1301double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5,1302double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024);13031304//! @} imgproc_feature13051306//! @addtogroup imgproc_filter1307//! @{13081309/** @brief Returns Gaussian filter coefficients.13101311The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter1312coefficients:13131314\f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f]13151316where \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$.13171318Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize1319smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly.1320You may also use the higher-level GaussianBlur.1321@param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive.1322@param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as1323`sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`.1324@param ktype Type of filter coefficients. It can be CV_32F or CV_64F .1325@sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur1326*/1327CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F );13281329/** @brief Returns filter coefficients for computing spatial image derivatives.13301331The function computes and returns the filter coefficients for spatial image derivatives. When1332`ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel1333kernels are generated (see #Sobel). The filters are normally passed to #sepFilter2D or to13341335@param kx Output matrix of row filter coefficients. It has the type ktype .1336@param ky Output matrix of column filter coefficients. It has the type ktype .1337@param dx Derivative order in respect of x.1338@param dy Derivative order in respect of y.1339@param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7.1340@param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not.1341Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are1342going to filter floating-point images, you are likely to use the normalized kernels. But if you1343compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve1344all the fractional bits, you may want to set normalize=false .1345@param ktype Type of filter coefficients. It can be CV_32f or CV_64F .1346*/1347CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky,1348int dx, int dy, int ksize,1349bool normalize = false, int ktype = CV_32F );13501351/** @brief Returns Gabor filter coefficients.13521353For more details about gabor filter equations and parameters, see: [Gabor1354Filter](http://en.wikipedia.org/wiki/Gabor_filter).13551356@param ksize Size of the filter returned.1357@param sigma Standard deviation of the gaussian envelope.1358@param theta Orientation of the normal to the parallel stripes of a Gabor function.1359@param lambd Wavelength of the sinusoidal factor.1360@param gamma Spatial aspect ratio.1361@param psi Phase offset.1362@param ktype Type of filter coefficients. It can be CV_32F or CV_64F .1363*/1364CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd,1365double gamma, double psi = CV_PI*0.5, int ktype = CV_64F );13661367//! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.1368static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }13691370/** @brief Returns a structuring element of the specified size and shape for morphological operations.13711372The function constructs and returns the structuring element that can be further passed to #erode,1373#dilate or #morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as1374the structuring element.13751376@param shape Element shape that could be one of #MorphShapes1377@param ksize Size of the structuring element.1378@param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the1379anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor1380position. In other cases the anchor just regulates how much the result of the morphological1381operation is shifted.1382*/1383CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));13841385/** @example samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp1386Sample code for simple filters13871388Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details1389*/13901391/** @brief Blurs an image using the median filter.13921393The function smoothes an image using the median filter with the \f$\texttt{ksize} \times1394\texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently.1395In-place operation is supported.13961397@note The median filter uses #BORDER_REPLICATE internally to cope with border pixels, see #BorderTypes13981399@param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be1400CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.1401@param dst destination array of the same size and type as src.1402@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...1403@sa bilateralFilter, blur, boxFilter, GaussianBlur1404*/1405CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize );14061407/** @brief Blurs an image using a Gaussian filter.14081409The function convolves the source image with the specified Gaussian kernel. In-place filtering is1410supported.14111412@param src input image; the image can have any number of channels, which are processed1413independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.1414@param dst output image of the same size and type as src.1415@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be1416positive and odd. Or, they can be zero's and then they are computed from sigma.1417@param sigmaX Gaussian kernel standard deviation in X direction.1418@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be1419equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,1420respectively (see #getGaussianKernel for details); to fully control the result regardless of1421possible future modifications of all this semantics, it is recommended to specify all of ksize,1422sigmaX, and sigmaY.1423@param borderType pixel extrapolation method, see #BorderTypes14241425@sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur1426*/1427CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize,1428double sigmaX, double sigmaY = 0,1429int borderType = BORDER_DEFAULT );14301431/** @brief Applies the bilateral filter to an image.14321433The function applies bilateral filtering to the input image, as described in1434http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html1435bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is1436very slow compared to most filters.14371438_Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<143910), the filter will not have much effect, whereas if they are large (\> 150), they will have a very1440strong effect, making the image look "cartoonish".14411442_Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time1443applications, and perhaps d=9 for offline applications that need heavy noise filtering.14441445This filter does not work inplace.1446@param src Source 8-bit or floating-point, 1-channel or 3-channel image.1447@param dst Destination image of the same size and type as src .1448@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,1449it is computed from sigmaSpace.1450@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that1451farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting1452in larger areas of semi-equal color.1453@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that1454farther pixels will influence each other as long as their colors are close enough (see sigmaColor1455). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is1456proportional to sigmaSpace.1457@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes1458*/1459CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,1460double sigmaColor, double sigmaSpace,1461int borderType = BORDER_DEFAULT );14621463/** @brief Blurs an image using the box filter.14641465The function smooths an image using the kernel:14661467\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]14681469where14701471\f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f]14721473Unnormalized box filter is useful for computing various integral characteristics over each pixel1474neighborhood, such as covariance matrices of image derivatives (used in dense optical flow1475algorithms, and so on). If you need to compute pixel sums over variable-size windows, use #integral.14761477@param src input image.1478@param dst output image of the same size and type as src.1479@param ddepth the output image depth (-1 to use src.depth()).1480@param ksize blurring kernel size.1481@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel1482center.1483@param normalize flag, specifying whether the kernel is normalized by its area or not.1484@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes1485@sa blur, bilateralFilter, GaussianBlur, medianBlur, integral1486*/1487CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,1488Size ksize, Point anchor = Point(-1,-1),1489bool normalize = true,1490int borderType = BORDER_DEFAULT );14911492/** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter.14931494For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring1495pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$.14961497The unnormalized square box filter can be useful in computing local image statistics such as the the local1498variance and standard deviation around the neighborhood of a pixel.14991500@param _src input image1501@param _dst output image of the same size and type as _src1502@param ddepth the output image depth (-1 to use src.depth())1503@param ksize kernel size1504@param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel1505center.1506@param normalize flag, specifying whether the kernel is to be normalized by it's area or not.1507@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes1508@sa boxFilter1509*/1510CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth,1511Size ksize, Point anchor = Point(-1, -1),1512bool normalize = true,1513int borderType = BORDER_DEFAULT );15141515/** @brief Blurs an image using the normalized box filter.15161517The function smooths an image using the kernel:15181519\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]15201521The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(),1522anchor, true, borderType)`.15231524@param src input image; it can have any number of channels, which are processed independently, but1525the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.1526@param dst output image of the same size and type as src.1527@param ksize blurring kernel size.1528@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel1529center.1530@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes1531@sa boxFilter, bilateralFilter, GaussianBlur, medianBlur1532*/1533CV_EXPORTS_W void blur( InputArray src, OutputArray dst,1534Size ksize, Point anchor = Point(-1,-1),1535int borderType = BORDER_DEFAULT );15361537/** @brief Convolves an image with the kernel.15381539The function applies an arbitrary linear filter to an image. In-place operation is supported. When1540the aperture is partially outside the image, the function interpolates outlier pixel values1541according to the specified border mode.15421543The function does actually compute correlation, not the convolution:15441545\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]15461547That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip1548the kernel using #flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows -1549anchor.y - 1)`.15501551The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or1552larger) and the direct algorithm for small kernels.15531554@param src input image.1555@param dst output image of the same size and the same number of channels as src.1556@param ddepth desired depth of the destination image, see @ref filter_depths "combinations"1557@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point1558matrix; if you want to apply different kernels to different channels, split the image into1559separate color planes using split and process them individually.1560@param anchor anchor of the kernel that indicates the relative position of a filtered point within1561the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor1562is at the kernel center.1563@param delta optional value added to the filtered pixels before storing them in dst.1564@param borderType pixel extrapolation method, see #BorderTypes1565@sa sepFilter2D, dft, matchTemplate1566*/1567CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth,1568InputArray kernel, Point anchor = Point(-1,-1),1569double delta = 0, int borderType = BORDER_DEFAULT );15701571/** @brief Applies a separable linear filter to an image.15721573The function applies a separable linear filter to the image. That is, first, every row of src is1574filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D1575kernel kernelY. The final result shifted by delta is stored in dst .15761577@param src Source image.1578@param dst Destination image of the same size and the same number of channels as src .1579@param ddepth Destination image depth, see @ref filter_depths "combinations"1580@param kernelX Coefficients for filtering each row.1581@param kernelY Coefficients for filtering each column.1582@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor1583is at the kernel center.1584@param delta Value added to the filtered results before storing them.1585@param borderType Pixel extrapolation method, see #BorderTypes1586@sa filter2D, Sobel, GaussianBlur, boxFilter, blur1587*/1588CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth,1589InputArray kernelX, InputArray kernelY,1590Point anchor = Point(-1,-1),1591double delta = 0, int borderType = BORDER_DEFAULT );15921593/** @example samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp1594Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector15951596Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details1597*/15981599/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.16001601In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to1602calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$1603kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first1604or the second x- or y- derivatives.16051606There is also the special value `ksize = #CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr1607filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is16081609\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]16101611for the x-derivative, or transposed for the y-derivative.16121613The function calculates an image derivative by convolving the image with the appropriate kernel:16141615\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]16161617The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less1618resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)1619or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first1620case corresponds to a kernel of:16211622\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]16231624The second case corresponds to a kernel of:16251626\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]16271628@param src input image.1629@param dst output image of the same size and the same number of channels as src .1630@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of16318-bit input images it will result in truncated derivatives.1632@param dx order of the derivative x.1633@param dy order of the derivative y.1634@param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.1635@param scale optional scale factor for the computed derivative values; by default, no scaling is1636applied (see #getDerivKernels for details).1637@param delta optional delta value that is added to the results prior to storing them in dst.1638@param borderType pixel extrapolation method, see #BorderTypes1639@sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar1640*/1641CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,1642int dx, int dy, int ksize = 3,1643double scale = 1, double delta = 0,1644int borderType = BORDER_DEFAULT );16451646/** @brief Calculates the first order image derivative in both x and y using a Sobel operator16471648Equivalent to calling:16491650@code1651Sobel( src, dx, CV_16SC1, 1, 0, 3 );1652Sobel( src, dy, CV_16SC1, 0, 1, 3 );1653@endcode16541655@param src input image.1656@param dx output image with first-order derivative in x.1657@param dy output image with first-order derivative in y.1658@param ksize size of Sobel kernel. It must be 3.1659@param borderType pixel extrapolation method, see #BorderTypes16601661@sa Sobel1662*/16631664CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx,1665OutputArray dy, int ksize = 3,1666int borderType = BORDER_DEFAULT );16671668/** @brief Calculates the first x- or y- image derivative using Scharr operator.16691670The function computes the first x- or y- spatial image derivative using the Scharr operator. The1671call16721673\f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f]16741675is equivalent to16761677\f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV_SCHARR, scale, delta, borderType)} .\f]16781679@param src input image.1680@param dst output image of the same size and the same number of channels as src.1681@param ddepth output image depth, see @ref filter_depths "combinations"1682@param dx order of the derivative x.1683@param dy order of the derivative y.1684@param scale optional scale factor for the computed derivative values; by default, no scaling is1685applied (see #getDerivKernels for details).1686@param delta optional delta value that is added to the results prior to storing them in dst.1687@param borderType pixel extrapolation method, see #BorderTypes1688@sa cartToPolar1689*/1690CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth,1691int dx, int dy, double scale = 1, double delta = 0,1692int borderType = BORDER_DEFAULT );16931694/** @example samples/cpp/laplace.cpp1695An example using Laplace transformations for edge detection1696*/16971698/** @brief Calculates the Laplacian of an image.16991700The function calculates the Laplacian of the source image by adding up the second x and y1701derivatives calculated using the Sobel operator:17021703\f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f]17041705This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image1706with the following \f$3 \times 3\f$ aperture:17071708\f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]17091710@param src Source image.1711@param dst Destination image of the same size and the same number of channels as src .1712@param ddepth Desired depth of the destination image.1713@param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for1714details. The size must be positive and odd.1715@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is1716applied. See #getDerivKernels for details.1717@param delta Optional delta value that is added to the results prior to storing them in dst .1718@param borderType Pixel extrapolation method, see #BorderTypes1719@sa Sobel, Scharr1720*/1721CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,1722int ksize = 1, double scale = 1, double delta = 0,1723int borderType = BORDER_DEFAULT );17241725//! @} imgproc_filter17261727//! @addtogroup imgproc_feature1728//! @{17291730/** @example samples/cpp/edge.cpp1731This program demonstrates usage of the Canny edge detector17321733Check @ref tutorial_canny_detector "the corresponding tutorial" for more details1734*/17351736/** @brief Finds edges in an image using the Canny algorithm @cite Canny86 .17371738The function finds edges in the input image and marks them in the output map edges using the1739Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The1740largest value is used to find initial segments of strong edges. See1741<http://en.wikipedia.org/wiki/Canny_edge_detector>17421743@param image 8-bit input image.1744@param edges output edge map; single channels 8-bit image, which has the same size as image .1745@param threshold1 first threshold for the hysteresis procedure.1746@param threshold2 second threshold for the hysteresis procedure.1747@param apertureSize aperture size for the Sobel operator.1748@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm1749\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (1750L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (1751L2gradient=false ).1752*/1753CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,1754double threshold1, double threshold2,1755int apertureSize = 3, bool L2gradient = false );17561757/** \overload17581759Finds edges in an image using the Canny algorithm with custom image gradient.17601761@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3).1762@param dy 16-bit y derivative of input image (same type as dx).1763@param edges output edge map; single channels 8-bit image, which has the same size as image .1764@param threshold1 first threshold for the hysteresis procedure.1765@param threshold2 second threshold for the hysteresis procedure.1766@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm1767\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (1768L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (1769L2gradient=false ).1770*/1771CV_EXPORTS_W void Canny( InputArray dx, InputArray dy,1772OutputArray edges,1773double threshold1, double threshold2,1774bool L2gradient = false );17751776/** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection.17771778The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal1779eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms1780of the formulae in the cornerEigenValsAndVecs description.17811782@param src Input single-channel 8-bit or floating-point image.1783@param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as1784src .1785@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).1786@param ksize Aperture parameter for the Sobel operator.1787@param borderType Pixel extrapolation method. See #BorderTypes.1788*/1789CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst,1790int blockSize, int ksize = 3,1791int borderType = BORDER_DEFAULT );17921793/** @brief Harris corner detector.17941795The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and1796cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance1797matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it1798computes the following characteristic:17991800\f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f]18011802Corners in the image can be found as the local maxima of this response map.18031804@param src Input single-channel 8-bit or floating-point image.1805@param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same1806size as src .1807@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).1808@param ksize Aperture parameter for the Sobel operator.1809@param k Harris detector free parameter. See the formula above.1810@param borderType Pixel extrapolation method. See #BorderTypes.1811*/1812CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,1813int ksize, double k,1814int borderType = BORDER_DEFAULT );18151816/** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection.18171818For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize1819neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as:18201821\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]18221823where the derivatives are computed using the Sobel operator.18241825After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as1826\f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where18271828- \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$1829- \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$1830- \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$18311832The output of the function can be used for robust edge or corner detection.18331834@param src Input single-channel 8-bit or floating-point image.1835@param dst Image to store the results. It has the same size as src and the type CV_32FC(6) .1836@param blockSize Neighborhood size (see details below).1837@param ksize Aperture parameter for the Sobel operator.1838@param borderType Pixel extrapolation method. See #BorderTypes.18391840@sa cornerMinEigenVal, cornerHarris, preCornerDetect1841*/1842CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst,1843int blockSize, int ksize,1844int borderType = BORDER_DEFAULT );18451846/** @brief Calculates a feature map for corner detection.18471848The function calculates the complex spatial derivative-based function of the source image18491850\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]18511852where \f$D_x\f$,\f$D_y\f$ are the first image derivatives, \f$D_{xx}\f$,\f$D_{yy}\f$ are the second image1853derivatives, and \f$D_{xy}\f$ is the mixed derivative.18541855The corners can be found as local maximums of the functions, as shown below:1856@code1857Mat corners, dilated_corners;1858preCornerDetect(image, corners, 3);1859// dilation with 3x3 rectangular structuring element1860dilate(corners, dilated_corners, Mat(), 1);1861Mat corner_mask = corners == dilated_corners;1862@endcode18631864@param src Source single-channel 8-bit of floating-point image.1865@param dst Output image that has the type CV_32F and the same size as src .1866@param ksize %Aperture size of the Sobel .1867@param borderType Pixel extrapolation method. See #BorderTypes.1868*/1869CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize,1870int borderType = BORDER_DEFAULT );18711872/** @brief Refines the corner locations.18731874The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as1875shown on the figure below.1876187718781879Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$1880to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$1881subject to image and measurement noise. Consider the expression:18821883\f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f]18841885where \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$ . The1886value of \f$q\f$ is to be found so that \f$\epsilon_i\f$ is minimized. A system of equations may be set up1887with \f$\epsilon_i\f$ set to zero:18881889\f[\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) \cdot q - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)\f]18901891where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first1892gradient term \f$G\f$ and the second gradient term \f$b\f$ gives:18931894\f[q = G^{-1} \cdot b\f]18951896The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates1897until the center stays within a set threshold.18981899@param image Input single-channel, 8-bit or float image.1900@param corners Initial coordinates of the input corners and refined coordinates provided for1901output.1902@param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) ,1903then a \f$(5*2+1) \times (5*2+1) = 11 \times 11\f$ search window is used.1904@param zeroZone Half of the size of the dead region in the middle of the search zone over which1905the summation in the formula below is not done. It is used sometimes to avoid possible1906singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such1907a size.1908@param criteria Criteria for termination of the iterative process of corner refinement. That is,1909the process of corner position refinement stops either after criteria.maxCount iterations or when1910the corner position moves by less than criteria.epsilon on some iteration.1911*/1912CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners,1913Size winSize, Size zeroZone,1914TermCriteria criteria );19151916/** @brief Determines strong corners on an image.19171918The function finds the most prominent corners in the image or in the specified image region, as1919described in @cite Shi9419201921- Function calculates the corner quality measure at every source image pixel using the1922#cornerMinEigenVal or #cornerHarris .1923- Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are1924retained).1925- The corners with the minimal eigenvalue less than1926\f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.1927- The remaining corners are sorted by the quality measure in the descending order.1928- Function throws away each corner for which there is a stronger corner at a distance less than1929maxDistance.19301931The function can be used to initialize a point-based tracker of an object.19321933@note If the function is called with different values A and B of the parameter qualityLevel , and1934A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector1935with qualityLevel=B .19361937@param image Input 8-bit or floating-point 32-bit, single-channel image.1938@param corners Output vector of detected corners.1939@param maxCorners Maximum number of corners to return. If there are more corners than are found,1940the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set1941and all detected corners are returned.1942@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The1943parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue1944(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the1945quality measure less than the product are rejected. For example, if the best corner has the1946quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure1947less than 15 are rejected.1948@param minDistance Minimum possible Euclidean distance between the returned corners.1949@param mask Optional region of interest. If the image is not empty (it needs to have the type1950CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.1951@param blockSize Size of an average block for computing a derivative covariation matrix over each1952pixel neighborhood. See cornerEigenValsAndVecs .1953@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)1954or #cornerMinEigenVal.1955@param k Free parameter of the Harris detector.19561957@sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,1958*/19591960CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,1961int maxCorners, double qualityLevel, double minDistance,1962InputArray mask = noArray(), int blockSize = 3,1963bool useHarrisDetector = false, double k = 0.04 );19641965CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,1966int maxCorners, double qualityLevel, double minDistance,1967InputArray mask, int blockSize,1968int gradientSize, bool useHarrisDetector = false,1969double k = 0.04 );1970/** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp1971An example using the Hough line detector1972 1973*/19741975/** @brief Finds lines in a binary image using the standard Hough transform.19761977The function implements the standard or standard multi-scale Hough transform algorithm for line1978detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough1979transform.19801981@param image 8-bit, single-channel binary source image. The image may be modified by the function.1982@param lines Output vector of lines. Each line is represented by a 2 or 3 element vector1983\f$(\rho, \theta)\f$ or \f$(\rho, \theta, \textrm{votes})\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of1984the image). \f$\theta\f$ is the line rotation angle in radians (1985\f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).1986\f$\textrm{votes}\f$ is the value of accumulator.1987@param rho Distance resolution of the accumulator in pixels.1988@param theta Angle resolution of the accumulator in radians.1989@param threshold Accumulator threshold parameter. Only those lines are returned that get enough1990votes ( \f$>\texttt{threshold}\f$ ).1991@param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho .1992The coarse accumulator distance resolution is rho and the accurate accumulator resolution is1993rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these1994parameters should be positive.1995@param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.1996@param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines.1997Must fall between 0 and max_theta.1998@param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines.1999Must fall between min_theta and CV_PI.2000*/2001CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,2002double rho, double theta, int threshold,2003double srn = 0, double stn = 0,2004double min_theta = 0, double max_theta = CV_PI );20052006/** @brief Finds line segments in a binary image using the probabilistic Hough transform.20072008The function implements the probabilistic Hough transform algorithm for line detection, described2009in @cite Matas0020102011See the line detection example below:2012@include snippets/imgproc_HoughLinesP.cpp2013This is a sample picture the function parameters have been tuned for:2014201520162017And this is the output of the above program in case of the probabilistic Hough transform:2018201920202021@param image 8-bit, single-channel binary source image. The image may be modified by the function.2022@param lines Output vector of lines. Each line is represented by a 4-element vector2023\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 detected2024line segment.2025@param rho Distance resolution of the accumulator in pixels.2026@param theta Angle resolution of the accumulator in radians.2027@param threshold Accumulator threshold parameter. Only those lines are returned that get enough2028votes ( \f$>\texttt{threshold}\f$ ).2029@param minLineLength Minimum line length. Line segments shorter than that are rejected.2030@param maxLineGap Maximum allowed gap between points on the same line to link them.20312032@sa LineSegmentDetector2033*/2034CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,2035double rho, double theta, int threshold,2036double minLineLength = 0, double maxLineGap = 0 );20372038/** @brief Finds lines in a set of points using the standard Hough transform.20392040The function finds lines in a set of points using a modification of the Hough transform.2041@include snippets/imgproc_HoughLinesPointSet.cpp2042@param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2.2043@param _lines Output vector of found lines. Each vector is encoded as a vector<Vec3d> \f$(votes, rho, theta)\f$.2044The larger the value of 'votes', the higher the reliability of the Hough line.2045@param lines_max Max count of hough lines.2046@param threshold Accumulator threshold parameter. Only those lines are returned that get enough2047votes ( \f$>\texttt{threshold}\f$ )2048@param min_rho Minimum Distance value of the accumulator in pixels.2049@param max_rho Maximum Distance value of the accumulator in pixels.2050@param rho_step Distance resolution of the accumulator in pixels.2051@param min_theta Minimum angle value of the accumulator in radians.2052@param max_theta Maximum angle value of the accumulator in radians.2053@param theta_step Angle resolution of the accumulator in radians.2054*/2055CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold,2056double min_rho, double max_rho, double rho_step,2057double min_theta, double max_theta, double theta_step );20582059/** @example samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp2060An example using the Hough circle detector2061*/20622063/** @brief Finds circles in a grayscale image using the Hough transform.20642065The function finds circles in a grayscale image using a modification of the Hough transform.20662067Example: :2068@include snippets/imgproc_HoughLinesCircles.cpp20692070@note Usually the function detects the centers of circles well. However, it may fail to find correct2071radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if2072you know it. Or, you may set maxRadius to a negative number to return centers only without radius2073search, and find the correct radius using an additional procedure.20742075@param image 8-bit, single-channel, grayscale input image.2076@param circles Output vector of found circles. Each vector is encoded as 3 or 4 element2077floating-point vector \f$(x, y, radius)\f$ or \f$(x, y, radius, votes)\f$ .2078@param method Detection method, see #HoughModes. Currently, the only implemented method is #HOUGH_GRADIENT2079@param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if2080dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has2081half as big width and height.2082@param minDist Minimum distance between the centers of the detected circles. If the parameter is2083too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is2084too large, some circles may be missed.2085@param param1 First method-specific parameter. In case of #HOUGH_GRADIENT , it is the higher2086threshold of the two passed to the Canny edge detector (the lower one is twice smaller).2087@param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT , it is the2088accumulator threshold for the circle centers at the detection stage. The smaller it is, the more2089false circles may be detected. Circles, corresponding to the larger accumulator values, will be2090returned first.2091@param minRadius Minimum circle radius.2092@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns2093centers without finding the radius.20942095@sa fitEllipse, minEnclosingCircle2096*/2097CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles,2098int method, double dp, double minDist,2099double param1 = 100, double param2 = 100,2100int minRadius = 0, int maxRadius = 0 );21012102//! @} imgproc_feature21032104//! @addtogroup imgproc_filter2105//! @{21062107/** @example samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp2108Advanced morphology Transformations sample code21092110Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details2111*/21122113/** @brief Erodes an image by using a specific structuring element.21142115The function erodes the source image using the specified structuring element that determines the2116shape of a pixel neighborhood over which the minimum is taken:21172118\f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]21192120The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In2121case of multi-channel images, each channel is processed independently.21222123@param src input image; the number of channels can be arbitrary, but the depth should be one of2124CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.2125@param dst output image of the same size and type as src.2126@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular2127structuring element is used. Kernel can be created using #getStructuringElement.2128@param anchor position of the anchor within the element; default value (-1, -1) means that the2129anchor is at the element center.2130@param iterations number of times erosion is applied.2131@param borderType pixel extrapolation method, see #BorderTypes2132@param borderValue border value in case of a constant border2133@sa dilate, morphologyEx, getStructuringElement2134*/2135CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,2136Point anchor = Point(-1,-1), int iterations = 1,2137int borderType = BORDER_CONSTANT,2138const Scalar& borderValue = morphologyDefaultBorderValue() );21392140/** @example samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp2141Erosion and Dilation sample code21422143Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details2144*/21452146/** @brief Dilates an image by using a specific structuring element.21472148The function dilates the source image using the specified structuring element that determines the2149shape of a pixel neighborhood over which the maximum is taken:2150\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]21512152The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In2153case of multi-channel images, each channel is processed independently.21542155@param src input image; the number of channels can be arbitrary, but the depth should be one of2156CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.2157@param dst output image of the same size and type as src.2158@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular2159structuring element is used. Kernel can be created using #getStructuringElement2160@param anchor position of the anchor within the element; default value (-1, -1) means that the2161anchor is at the element center.2162@param iterations number of times dilation is applied.2163@param borderType pixel extrapolation method, see #BorderTypes2164@param borderValue border value in case of a constant border2165@sa erode, morphologyEx, getStructuringElement2166*/2167CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,2168Point anchor = Point(-1,-1), int iterations = 1,2169int borderType = BORDER_CONSTANT,2170const Scalar& borderValue = morphologyDefaultBorderValue() );21712172/** @brief Performs advanced morphological transformations.21732174The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as2175basic operations.21762177Any of the operations can be done in-place. In case of multi-channel images, each channel is2178processed independently.21792180@param src Source image. The number of channels can be arbitrary. The depth should be one of2181CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.2182@param dst Destination image of the same size and type as source image.2183@param op Type of a morphological operation, see #MorphTypes2184@param kernel Structuring element. It can be created using #getStructuringElement.2185@param anchor Anchor position with the kernel. Negative values mean that the anchor is at the2186kernel center.2187@param iterations Number of times erosion and dilation are applied.2188@param borderType Pixel extrapolation method, see #BorderTypes2189@param borderValue Border value in case of a constant border. The default value has a special2190meaning.2191@sa dilate, erode, getStructuringElement2192@note The number of iterations is the number of times erosion or dilatation operation will be applied.2193For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply2194successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate).2195*/2196CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,2197int op, InputArray kernel,2198Point anchor = Point(-1,-1), int iterations = 1,2199int borderType = BORDER_CONSTANT,2200const Scalar& borderValue = morphologyDefaultBorderValue() );22012202//! @} imgproc_filter22032204//! @addtogroup imgproc_transform2205//! @{22062207/** @brief Resizes an image.22082209The function resize resizes the image src down to or up to the specified size. Note that the2210initial dst type or size are not taken into account. Instead, the size and type are derived from2211the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst,2212you may call the function as follows:2213@code2214// explicitly specify dsize=dst.size(); fx and fy will be computed from that.2215resize(src, dst, dst.size(), 0, 0, interpolation);2216@endcode2217If you want to decimate the image by factor of 2 in each direction, you can call the function this2218way:2219@code2220// specify fx and fy and let the function compute the destination image size.2221resize(src, dst, Size(), 0.5, 0.5, interpolation);2222@endcode2223To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to2224enlarge an image, it will generally look best with c#INTER_CUBIC (slow) or #INTER_LINEAR2225(faster but still looks OK).22262227@param src input image.2228@param dst output image; it has the size dsize (when it is non-zero) or the size computed from2229src.size(), fx, and fy; the type of dst is the same as of src.2230@param dsize output image size; if it equals zero, it is computed as:2231\f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]2232Either dsize or both fx and fy must be non-zero.2233@param fx scale factor along the horizontal axis; when it equals 0, it is computed as2234\f[\texttt{(double)dsize.width/src.cols}\f]2235@param fy scale factor along the vertical axis; when it equals 0, it is computed as2236\f[\texttt{(double)dsize.height/src.rows}\f]2237@param interpolation interpolation method, see #InterpolationFlags22382239@sa warpAffine, warpPerspective, remap2240*/2241CV_EXPORTS_W void resize( InputArray src, OutputArray dst,2242Size dsize, double fx = 0, double fy = 0,2243int interpolation = INTER_LINEAR );22442245/** @brief Applies an affine transformation to an image.22462247The function warpAffine transforms the source image using the specified matrix:22482249\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]22502251when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted2252with #invertAffineTransform and then put in the formula above instead of M. The function cannot2253operate in-place.22542255@param src input image.2256@param dst output image that has the size dsize and the same type as src .2257@param M \f$2\times 3\f$ transformation matrix.2258@param dsize size of the output image.2259@param flags combination of interpolation methods (see #InterpolationFlags) and the optional2260flag #WARP_INVERSE_MAP that means that M is the inverse transformation (2261\f$\texttt{dst}\rightarrow\texttt{src}\f$ ).2262@param borderMode pixel extrapolation method (see #BorderTypes); when2263borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to2264the "outliers" in the source image are not modified by the function.2265@param borderValue value used in case of a constant border; by default, it is 0.22662267@sa warpPerspective, resize, remap, getRectSubPix, transform2268*/2269CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,2270InputArray M, Size dsize,2271int flags = INTER_LINEAR,2272int borderMode = BORDER_CONSTANT,2273const Scalar& borderValue = Scalar());22742275/** @example samples/cpp/warpPerspective_demo.cpp2276An example program shows using cv::findHomography and cv::warpPerspective for image warping2277*/22782279/** @brief Applies a perspective transformation to an image.22802281The function warpPerspective transforms the source image using the specified matrix:22822283\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}} ,2284\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f]22852286when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert2287and then put in the formula above instead of M. The function cannot operate in-place.22882289@param src input image.2290@param dst output image that has the size dsize and the same type as src .2291@param M \f$3\times 3\f$ transformation matrix.2292@param dsize size of the output image.2293@param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the2294optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation (2295\f$\texttt{dst}\rightarrow\texttt{src}\f$ ).2296@param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE).2297@param borderValue value used in case of a constant border; by default, it equals 0.22982299@sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform2300*/2301CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst,2302InputArray M, Size dsize,2303int flags = INTER_LINEAR,2304int borderMode = BORDER_CONSTANT,2305const Scalar& borderValue = Scalar());23062307/** @brief Applies a generic geometrical transformation to an image.23082309The function remap transforms the source image using the specified map:23102311\f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f]23122313where values of pixels with non-integer coordinates are computed using one of available2314interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps2315in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in2316\f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to2317convert from floating to fixed-point representations of a map is that they can yield much faster2318(\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),2319cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.23202321This function cannot operate in-place.23222323@param src Source image.2324@param dst Destination image. It has the same size as map1 and the same type as src .2325@param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 ,2326CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point2327representation to fixed-point for speed.2328@param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map2329if map1 is (x,y) points), respectively.2330@param interpolation Interpolation method (see #InterpolationFlags). The method #INTER_AREA is2331not supported by this function.2332@param borderMode Pixel extrapolation method (see #BorderTypes). When2333borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image that2334corresponds to the "outliers" in the source image are not modified by the function.2335@param borderValue Value used in case of a constant border. By default, it is 0.2336@note2337Due to current implementation limitations the size of an input and output images should be less than 32767x32767.2338*/2339CV_EXPORTS_W void remap( InputArray src, OutputArray dst,2340InputArray map1, InputArray map2,2341int interpolation, int borderMode = BORDER_CONSTANT,2342const Scalar& borderValue = Scalar());23432344/** @brief Converts image transformation maps from one representation to another.23452346The function converts a pair of maps for remap from one representation to another. The following2347options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are2348supported:23492350- \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the2351most frequently used conversion operation, in which the original floating-point maps (see remap )2352are converted to a more compact and much faster fixed-point representation. The first output array2353contains the rounded coordinates and the second array (created only when nninterpolation=false )2354contains indices in the interpolation tables.23552356- \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but2357the original maps are stored in one 2-channel matrix.23582359- Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same2360as the originals.23612362@param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 .2363@param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix),2364respectively.2365@param dstmap1 The first output map that has the type dstmap1type and the same size as src .2366@param dstmap2 The second output map.2367@param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or2368CV_32FC2 .2369@param nninterpolation Flag indicating whether the fixed-point maps are used for the2370nearest-neighbor or for a more complex interpolation.23712372@sa remap, undistort, initUndistortRectifyMap2373*/2374CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2,2375OutputArray dstmap1, OutputArray dstmap2,2376int dstmap1type, bool nninterpolation = false );23772378/** @brief Calculates an affine matrix of 2D rotation.23792380The function calculates the following matrix:23812382\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]23832384where23852386\f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f]23872388The transformation maps the rotation center to itself. If this is not the target, adjust the shift.23892390@param center Center of the rotation in the source image.2391@param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the2392coordinate origin is assumed to be the top-left corner).2393@param scale Isotropic scale factor.23942395@sa getAffineTransform, warpAffine, transform2396*/2397CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale );23982399/** @brief Calculates an affine transform from three pairs of the corresponding points.24002401The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that:24022403\f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]24042405where24062407\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f]24082409@param src Coordinates of triangle vertices in the source image.2410@param dst Coordinates of the corresponding triangle vertices in the destination image.24112412@sa warpAffine, transform2413*/2414CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );24152416/** @brief Inverts an affine transformation.24172418The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M:24192420\f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f]24212422The result is also a \f$2 \times 3\f$ matrix of the same type as M.24232424@param M Original affine transformation.2425@param iM Output reverse affine transformation.2426*/2427CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );24282429/** @brief Calculates a perspective transform from four pairs of the corresponding points.24302431The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that:24322433\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]24342435where24362437\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f]24382439@param src Coordinates of quadrangle vertices in the source image.2440@param dst Coordinates of the corresponding quadrangle vertices in the destination image.2441@param solveMethod method passed to cv::solve (#DecompTypes)24422443@sa findHomography, warpPerspective, perspectiveTransform2444*/2445CV_EXPORTS_W Mat getPerspectiveTransform(InputArray src, InputArray dst, int solveMethod = DECOMP_LU);24462447/** @overload */2448CV_EXPORTS Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod = DECOMP_LU);244924502451CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );24522453/** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy.24542455The function getRectSubPix extracts pixels from src:24562457\f[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f]24582459where the values of the pixels at non-integer coordinates are retrieved using bilinear2460interpolation. Every channel of multi-channel images is processed independently. Also2461the image should be a single channel or three channel image. While the center of the2462rectangle must be inside the image, parts of the rectangle may be outside.24632464@param image Source image.2465@param patchSize Size of the extracted patch.2466@param center Floating point coordinates of the center of the extracted rectangle within the2467source image. The center must be inside the image.2468@param patch Extracted patch that has the size patchSize and the same number of channels as src .2469@param patchType Depth of the extracted pixels. By default, they have the same depth as src .24702471@sa warpAffine, warpPerspective2472*/2473CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,2474Point2f center, OutputArray patch, int patchType = -1 );24752476/** @example samples/cpp/polar_transforms.cpp2477An example using the cv::linearPolar and cv::logPolar operations2478*/24792480/** @brief Remaps an image to semilog-polar coordinates space.24812482@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG);24832484@internal2485Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image d)"):2486\f[\begin{array}{l}2487dst( \rho , \phi ) = src(x,y) \\2488dst.size() \leftarrow src.size()2489\end{array}\f]24902491where2492\f[\begin{array}{l}2493I = (dx,dy) = (x - center.x,y - center.y) \\2494\rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\2495\phi = Kangle \cdot \texttt{angle} (I) \\2496\end{array}\f]24972498and2499\f[\begin{array}{l}2500M = src.cols / log_e(maxRadius) \\2501Kangle = src.rows / 2\Pi \\2502\end{array}\f]25032504The function emulates the human "foveal" vision and can be used for fast scale and2505rotation-invariant template matching, for object tracking and so forth.2506@param src Source image2507@param dst Destination image. It will have same size and type as src.2508@param center The transformation center; where the output precision is maximal2509@param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too.2510@param flags A combination of interpolation methods, see #InterpolationFlags25112512@note2513- The function can not operate in-place.2514- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.25152516@sa cv::linearPolar2517@endinternal2518*/2519CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,2520Point2f center, double M, int flags );25212522/** @brief Remaps an image to polar coordinates space.25232524@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags)25252526@internal2527Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image c)"):2528\f[\begin{array}{l}2529dst( \rho , \phi ) = src(x,y) \\2530dst.size() \leftarrow src.size()2531\end{array}\f]25322533where2534\f[\begin{array}{l}2535I = (dx,dy) = (x - center.x,y - center.y) \\2536\rho = Kmag \cdot \texttt{magnitude} (I) ,\\2537\phi = angle \cdot \texttt{angle} (I)2538\end{array}\f]25392540and2541\f[\begin{array}{l}2542Kx = src.cols / maxRadius \\2543Ky = src.rows / 2\Pi2544\end{array}\f]254525462547@param src Source image2548@param dst Destination image. It will have same size and type as src.2549@param center The transformation center;2550@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.2551@param flags A combination of interpolation methods, see #InterpolationFlags25522553@note2554- The function can not operate in-place.2555- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.25562557@sa cv::logPolar2558@endinternal2559*/2560CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,2561Point2f center, double maxRadius, int flags );256225632564/** \brief Remaps an image to polar or semilog-polar coordinates space25652566@anchor polar_remaps_reference_image256725682569Transform the source image using the following transformation:2570\f[2571dst(\rho , \phi ) = src(x,y)2572\f]25732574where2575\f[2576\begin{array}{l}2577\vec{I} = (x - center.x, \;y - center.y) \\2578\phi = Kangle \cdot \texttt{angle} (\vec{I}) \\2579\rho = \left\{\begin{matrix}2580Klin \cdot \texttt{magnitude} (\vec{I}) & default \\2581Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\2582\end{matrix}\right.2583\end{array}2584\f]25852586and2587\f[2588\begin{array}{l}2589Kangle = dsize.height / 2\Pi \\2590Klin = dsize.width / maxRadius \\2591Klog = dsize.width / log_e(maxRadius) \\2592\end{array}2593\f]259425952596\par Linear vs semilog mapping25972598Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to `flags` to specify the polar mapping mode.25992600Linear is the default mode.26012602The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision)2603in contrast to peripheral vision where acuity is minor.26042605\par Option on `dsize`:26062607- if both values in `dsize <=0 ` (default),2608the destination image will have (almost) same area of source bounding circle:2609\f[\begin{array}{l}2610dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\2611dsize.width = \texttt{cvRound}(maxRadius) \\2612dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\2613\end{array}\f]261426152616- if only `dsize.height <= 0`,2617the destination image area will be proportional to the bounding circle area but scaled by `Kx * Kx`:2618\f[\begin{array}{l}2619dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\2620\end{array}2621\f]26222623- if both values in `dsize > 0 `,2624the destination image will have the given size therefore the area of the bounding circle will be scaled to `dsize`.262526262627\par Reverse mapping26282629You can get reverse mapping adding #WARP_INVERSE_MAP to `flags`2630\snippet polar_transforms.cpp InverseMap26312632In addiction, to calculate the original coordinate from a polar mapped coordinate \f$(rho, phi)->(x, y)\f$:2633\snippet polar_transforms.cpp InverseCoordinate26342635@param src Source image.2636@param dst Destination image. It will have same type as src.2637@param dsize The destination image size (see description for valid options).2638@param center The transformation center.2639@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.2640@param flags A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode.2641- Add #WARP_POLAR_LINEAR to select linear polar mapping (default)2642- Add #WARP_POLAR_LOG to select semilog polar mapping2643- Add #WARP_INVERSE_MAP for reverse mapping.2644@note2645- The function can not operate in-place.2646- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.2647- This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.26482649@sa cv::remap2650*/2651CV_EXPORTS_W void warpPolar(InputArray src, OutputArray dst, Size dsize,2652Point2f center, double maxRadius, int flags);265326542655//! @} imgproc_transform26562657//! @addtogroup imgproc_misc2658//! @{26592660/** @overload */2661CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );26622663/** @overload */2664CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,2665OutputArray sqsum, int sdepth = -1, int sqdepth = -1 );26662667/** @brief Calculates the integral of an image.26682669The function calculates one or more integral images for the source image as follows:26702671\f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f]26722673\f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f]26742675\f[\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)\f]26762677Using these integral images, you can calculate sum, mean, and standard deviation over a specific2678up-right or rotated rectangular region of the image in a constant time, for example:26792680\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]26812682It makes possible to do a fast blurring or fast block correlation with a variable window size, for2683example. In case of multi-channel images, sums for each channel are accumulated independently.26842685As a practical example, the next figure shows the calculation of the integral of a straight2686rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the2687original image are shown, as well as the relative pixels in the integral images sum and tilted .2688268926902691@param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f).2692@param sum integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f).2693@param sqsum integral image for squared pixel values; it is \f$(W+1)\times (H+1)\f$, double-precision2694floating-point (64f) array.2695@param tilted integral for the image rotated by 45 degrees; it is \f$(W+1)\times (H+1)\f$ array with2696the same data type as sum.2697@param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or2698CV_64F.2699@param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.2700*/2701CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum,2702OutputArray sqsum, OutputArray tilted,2703int sdepth = -1, int sqdepth = -1 );27042705//! @} imgproc_misc27062707//! @addtogroup imgproc_motion2708//! @{27092710/** @brief Adds an image to the accumulator image.27112712The function adds src or some of its elements to dst :27132714\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]27152716The function supports multi-channel images. Each channel is processed independently.27172718The function cv::accumulate can be used, for example, to collect statistics of a scene background2719viewed by a still camera and for the further foreground-background segmentation.27202721@param src Input image of type CV_8UC(n), CV_16UC(n), CV_32FC(n) or CV_64FC(n), where n is a positive integer.2722@param dst %Accumulator image with the same number of channels as input image, and a depth of CV_32F or CV_64F.2723@param mask Optional operation mask.27242725@sa accumulateSquare, accumulateProduct, accumulateWeighted2726*/2727CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst,2728InputArray mask = noArray() );27292730/** @brief Adds the square of a source image to the accumulator image.27312732The function adds the input image src or its selected region, raised to a power of 2, to the2733accumulator dst :27342735\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]27362737The function supports multi-channel images. Each channel is processed independently.27382739@param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.2740@param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit2741floating-point.2742@param mask Optional operation mask.27432744@sa accumulateSquare, accumulateProduct, accumulateWeighted2745*/2746CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst,2747InputArray mask = noArray() );27482749/** @brief Adds the per-element product of two input images to the accumulator image.27502751The function adds the product of two images or their selected regions to the accumulator dst :27522753\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]27542755The function supports multi-channel images. Each channel is processed independently.27562757@param src1 First input image, 1- or 3-channel, 8-bit or 32-bit floating point.2758@param src2 Second input image of the same type and the same size as src1 .2759@param dst %Accumulator image with the same number of channels as input images, 32-bit or 64-bit2760floating-point.2761@param mask Optional operation mask.27622763@sa accumulate, accumulateSquare, accumulateWeighted2764*/2765CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,2766InputOutputArray dst, InputArray mask=noArray() );27672768/** @brief Updates a running average.27692770The function calculates the weighted sum of the input image src and the accumulator dst so that dst2771becomes a running average of a frame sequence:27722773\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]27742775That is, alpha regulates the update speed (how fast the accumulator "forgets" about earlier images).2776The function supports multi-channel images. Each channel is processed independently.27772778@param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point.2779@param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit2780floating-point.2781@param alpha Weight of the input image.2782@param mask Optional operation mask.27832784@sa accumulate, accumulateSquare, accumulateProduct2785*/2786CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,2787double alpha, InputArray mask = noArray() );27882789/** @brief The function is used to detect translational shifts that occur between two images.27902791The operation takes advantage of the Fourier shift theorem for detecting the translational shift in2792the frequency domain. It can be used for fast image registration as well as motion estimation. For2793more information please see <http://en.wikipedia.org/wiki/Phase_correlation>27942795Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed2796with getOptimalDFTSize.27972798The function performs the following equations:2799- First it applies a Hanning window (see <http://en.wikipedia.org/wiki/Hann_function>) to each2800image to remove possible edge effects. This window is cached until the array size changes to speed2801up processing time.2802- Next it computes the forward DFTs of each source array:2803\f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f]2804where \f$\mathcal{F}\f$ is the forward DFT.2805- It then computes the cross-power spectrum of each frequency domain array:2806\f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f]2807- Next the cross-correlation is converted back into the time domain via the inverse DFT:2808\f[r = \mathcal{F}^{-1}\{R\}\f]2809- Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to2810achieve sub-pixel accuracy.2811\f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f]2812- If non-zero, the response parameter is computed as the sum of the elements of r within the 5x52813centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single2814peak) and will be smaller when there are multiple peaks.28152816@param src1 Source floating point array (CV_32FC1 or CV_64FC1)2817@param src2 Source floating point array (CV_32FC1 or CV_64FC1)2818@param window Floating point array with windowing coefficients to reduce edge effects (optional).2819@param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional).2820@returns detected phase shift (sub-pixel) between the two arrays.28212822@sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow2823*/2824CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2,2825InputArray window = noArray(), CV_OUT double* response = 0);28262827/** @brief This function computes a Hanning window coefficients in two dimensions.28282829See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function)2830for more information.28312832An example is shown below:2833@code2834// create hanning window of size 100x100 and type CV_32F2835Mat hann;2836createHanningWindow(hann, Size(100, 100), CV_32F);2837@endcode2838@param dst Destination array to place Hann coefficients in2839@param winSize The window size specifications (both width and height must be > 1)2840@param type Created array type2841*/2842CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);28432844//! @} imgproc_motion28452846//! @addtogroup imgproc_misc2847//! @{28482849/** @brief Applies a fixed-level threshold to each array element.28502851The function applies fixed-level thresholding to a multiple-channel array. The function is typically2852used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for2853this purpose) or for removing a noise, that is, filtering out pixels with too small or too large2854values. There are several types of thresholding supported by the function. They are determined by2855type parameter.28562857Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the2858above values. In these cases, the function determines the optimal threshold value using the Otsu's2859or Triangle algorithm and uses it instead of the specified thresh.28602861@note Currently, the Otsu's and Triangle methods are implemented only for 8-bit single-channel images.28622863@param src input array (multiple-channel, 8-bit or 32-bit floating point).2864@param dst output array of the same size and type and the same number of channels as src.2865@param thresh threshold value.2866@param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding2867types.2868@param type thresholding type (see #ThresholdTypes).2869@return the computed threshold value if Otsu's or Triangle methods used.28702871@sa adaptiveThreshold, findContours, compare, min, max2872*/2873CV_EXPORTS_W double threshold( InputArray src, OutputArray dst,2874double thresh, double maxval, int type );287528762877/** @brief Applies an adaptive threshold to an array.28782879The function transforms a grayscale image to a binary image according to the formulae:2880- **THRESH_BINARY**2881\f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f]2882- **THRESH_BINARY_INV**2883\f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f]2884where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter).28852886The function can process the image in-place.28872888@param src Source 8-bit single-channel image.2889@param dst Destination image of the same size and the same type as src.2890@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied2891@param adaptiveMethod Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes.2892The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries.2893@param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV,2894see #ThresholdTypes.2895@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the2896pixel: 3, 5, 7, and so on.2897@param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it2898is positive but may be zero or negative as well.28992900@sa threshold, blur, GaussianBlur2901*/2902CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst,2903double maxValue, int adaptiveMethod,2904int thresholdType, int blockSize, double C );29052906//! @} imgproc_misc29072908//! @addtogroup imgproc_filter2909//! @{29102911/** @example samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp2912An example using pyrDown and pyrUp functions2913*/29142915/** @brief Blurs an image and downsamples it.29162917By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in2918any case, the following conditions should be satisfied:29192920\f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f]29212922The function performs the downsampling step of the Gaussian pyramid construction. First, it2923convolves the source image with the kernel:29242925\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]29262927Then, it downsamples the image by rejecting even rows and columns.29282929@param src input image.2930@param dst output image; it has the specified size and the same type as src.2931@param dstsize size of the output image.2932@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported)2933*/2934CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst,2935const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );29362937/** @brief Upsamples an image and then blurs it.29382939By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any2940case, the following conditions should be satisfied:29412942\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]29432944The function performs the upsampling step of the Gaussian pyramid construction, though it can2945actually be used to construct the Laplacian pyramid. First, it upsamples the source image by2946injecting even zero rows and columns and then convolves the result with the same kernel as in2947pyrDown multiplied by 4.29482949@param src input image.2950@param dst output image. It has the specified size and the same type as src .2951@param dstsize size of the output image.2952@param borderType Pixel extrapolation method, see #BorderTypes (only #BORDER_DEFAULT is supported)2953*/2954CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst,2955const Size& dstsize = Size(), int borderType = BORDER_DEFAULT );29562957/** @brief Constructs the Gaussian pyramid for an image.29582959The function constructs a vector of images and builds the Gaussian pyramid by recursively applying2960pyrDown to the previously built pyramid layers, starting from `dst[0]==src`.29612962@param src Source image. Check pyrDown for the list of supported types.2963@param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the2964same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on.2965@param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative.2966@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported)2967*/2968CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst,2969int maxlevel, int borderType = BORDER_DEFAULT );29702971//! @} imgproc_filter29722973//! @addtogroup imgproc_hist2974//! @{29752976/** @example samples/cpp/demhist.cpp2977An example for creating histograms of an image2978*/29792980/** @brief Calculates a histogram of a set of arrays.29812982The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used2983to increment a histogram bin are taken from the corresponding input arrays at the same location. The2984sample below shows how to compute a 2D Hue-Saturation histogram for a color image. :2985@include snippets/imgproc_calcHist.cpp29862987@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same2988size. Each of them can have an arbitrary number of channels.2989@param nimages Number of source images.2990@param channels List of the dims channels used to compute the histogram. The first array channels2991are numerated from 0 to images[0].channels()-1 , the second array channels are counted from2992images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.2993@param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size2994as images[i] . The non-zero mask elements mark the array elements counted in the histogram.2995@param hist Output histogram, which is a dense or sparse dims -dimensional array.2996@param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS2997(equal to 32 in the current OpenCV version).2998@param histSize Array of histogram sizes in each dimension.2999@param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the3000histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower3001(inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary3002\f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a3003uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform (3004uniform=false ), then each of ranges[i] contains histSize[i]+1 elements:3005\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$3006. The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not3007counted in the histogram.3008@param uniform Flag indicating whether the histogram is uniform or not (see above).3009@param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning3010when it is allocated. This feature enables you to compute a single histogram from several sets of3011arrays, or to update the histogram in time.3012*/3013CV_EXPORTS void calcHist( const Mat* images, int nimages,3014const int* channels, InputArray mask,3015OutputArray hist, int dims, const int* histSize,3016const float** ranges, bool uniform = true, bool accumulate = false );30173018/** @overload30193020this variant uses %SparseMat for output3021*/3022CV_EXPORTS void calcHist( const Mat* images, int nimages,3023const int* channels, InputArray mask,3024SparseMat& hist, int dims,3025const int* histSize, const float** ranges,3026bool uniform = true, bool accumulate = false );30273028/** @overload */3029CV_EXPORTS_W void calcHist( InputArrayOfArrays images,3030const std::vector<int>& channels,3031InputArray mask, OutputArray hist,3032const std::vector<int>& histSize,3033const std::vector<float>& ranges,3034bool accumulate = false );30353036/** @brief Calculates the back projection of a histogram.30373038The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to3039#calcHist , at each location (x, y) the function collects the values from the selected channels3040in the input images and finds the corresponding histogram bin. But instead of incrementing it, the3041function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of3042statistics, the function computes probability of each element value in respect with the empirical3043probability distribution represented by the histogram. See how, for example, you can find and track3044a bright-colored object in a scene:30453046- Before tracking, show the object to the camera so that it covers almost the whole frame.3047Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant3048colors in the object.30493050- When tracking, calculate a back projection of a hue plane of each input video frame using that3051pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make3052sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.30533054- Find connected components in the resulting picture and choose, for example, the largest3055component.30563057This is an approximate algorithm of the CamShift color object tracker.30583059@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same3060size. Each of them can have an arbitrary number of channels.3061@param nimages Number of source images.3062@param channels The list of channels used to compute the back projection. The number of channels3063must match the histogram dimensionality. The first array channels are numerated from 0 to3064images[0].channels()-1 , the second array channels are counted from images[0].channels() to3065images[0].channels() + images[1].channels()-1, and so on.3066@param hist Input histogram that can be dense or sparse.3067@param backProject Destination back projection array that is a single-channel array of the same3068size and depth as images[0] .3069@param ranges Array of arrays of the histogram bin boundaries in each dimension. See #calcHist .3070@param scale Optional scale factor for the output back projection.3071@param uniform Flag indicating whether the histogram is uniform or not (see above).30723073@sa calcHist, compareHist3074*/3075CV_EXPORTS void calcBackProject( const Mat* images, int nimages,3076const int* channels, InputArray hist,3077OutputArray backProject, const float** ranges,3078double scale = 1, bool uniform = true );30793080/** @overload */3081CV_EXPORTS void calcBackProject( const Mat* images, int nimages,3082const int* channels, const SparseMat& hist,3083OutputArray backProject, const float** ranges,3084double scale = 1, bool uniform = true );30853086/** @overload */3087CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector<int>& channels,3088InputArray hist, OutputArray dst,3089const std::vector<float>& ranges,3090double scale );30913092/** @brief Compares two histograms.30933094The function cv::compareHist compares two dense or two sparse histograms using the specified method.30953096The function returns \f$d(H_1, H_2)\f$ .30973098While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable3099for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling3100problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms3101or more general sparse configurations of weighted points, consider using the #EMD function.31023103@param H1 First compared histogram.3104@param H2 Second compared histogram of the same size as H1 .3105@param method Comparison method, see #HistCompMethods3106*/3107CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method );31083109/** @overload */3110CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method );31113112/** @brief Equalizes the histogram of a grayscale image.31133114The function equalizes the histogram of the input image using the following algorithm:31153116- Calculate the histogram \f$H\f$ for src .3117- Normalize the histogram so that the sum of histogram bins is 255.3118- Compute the integral of the histogram:3119\f[H'_i = \sum _{0 \le j < i} H(j)\f]3120- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$31213122The algorithm normalizes the brightness and increases the contrast of the image.31233124@param src Source 8-bit single channel image.3125@param dst Destination image of the same size and type as src .3126*/3127CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst );31283129/** @brief Computes the "minimal work" distance between two weighted point configurations.31303131The function computes the earth mover distance and/or a lower boundary of the distance between the3132two weighted point configurations. One of the applications described in @cite RubnerSept98,3133@cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation3134problem that is solved using some modification of a simplex algorithm, thus the complexity is3135exponential in the worst case, though, on average it is much faster. In the case of a real metric3136the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used3137to determine roughly whether the two signatures are far enough so that they cannot relate to the3138same object.31393140@param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix.3141Each row stores the point weight followed by the point coordinates. The matrix is allowed to have3142a single column (weights only) if the user-defined cost matrix is used. The weights must be3143non-negative and have at least one non-zero value.3144@param signature2 Second signature of the same format as signature1 , though the number of rows3145may be different. The total weights may be different. In this case an extra "dummy" point is added3146to either signature1 or signature2. The weights must be non-negative and have at least one non-zero3147value.3148@param distType Used metric. See #DistanceTypes.3149@param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix3150is used, lower boundary lowerBound cannot be calculated because it needs a metric function.3151@param lowerBound Optional input/output parameter: lower boundary of a distance between the two3152signatures that is a distance between mass centers. The lower boundary may not be calculated if3153the user-defined cost matrix is used, the total weights of point configurations are not equal, or3154if the signatures consist of weights only (the signature matrices have a single column). You3155**must** initialize \*lowerBound . If the calculated distance between mass centers is greater or3156equal to \*lowerBound (it means that the signatures are far enough), the function does not3157calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on3158return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound3159should be set to 0.3160@param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is3161a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 .3162*/3163CV_EXPORTS float EMD( InputArray signature1, InputArray signature2,3164int distType, InputArray cost=noArray(),3165float* lowerBound = 0, OutputArray flow = noArray() );31663167CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature2,3168int distType, InputArray cost=noArray(),3169CV_IN_OUT Ptr<float> lowerBound = Ptr<float>(), OutputArray flow = noArray() );31703171//! @} imgproc_hist31723173/** @example samples/cpp/watershed.cpp3174An example using the watershed algorithm3175*/31763177/** @brief Performs a marker-based image segmentation using the watershed algorithm.31783179The function implements one of the variants of watershed, non-parametric marker-based segmentation3180algorithm, described in @cite Meyer92 .31813182Before passing the image to the function, you have to roughly outline the desired regions in the3183image markers with positive (\>0) indices. So, every region is represented as one or more connected3184components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary3185mask using #findContours and #drawContours (see the watershed.cpp demo). The markers are "seeds" of3186the future image regions. All the other pixels in markers , whose relation to the outlined regions3187is not known and should be defined by the algorithm, should be set to 0's. In the function output,3188each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the3189regions.31903191@note Any two neighbor connected components are not necessarily separated by a watershed boundary3192(-1's pixels); for example, they can touch each other in the initial marker image passed to the3193function.31943195@param image Input 8-bit 3-channel image.3196@param markers Input/output 32-bit single-channel image (map) of markers. It should have the same3197size as image .31983199@sa findContours32003201@ingroup imgproc_misc3202*/3203CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers );32043205//! @addtogroup imgproc_filter3206//! @{32073208/** @brief Performs initial step of meanshift segmentation of an image.32093210The function implements the filtering stage of meanshift segmentation, that is, the output of the3211function is the filtered "posterized" image with color gradients and fine-grain texture flattened.3212At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes3213meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is3214considered:32153216\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]32173218where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively3219(though, the algorithm does not depend on the color space used, so any 3-component color space can3220be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector3221(R',G',B') are found and they act as the neighborhood center on the next iteration:32223223\f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f]32243225After the iterations over, the color components of the initial pixel (that is, the pixel from where3226the iterations started) are set to the final value (average color at the last iteration):32273228\f[I(X,Y) <- (R*,G*,B*)\f]32293230When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is3231run on the smallest layer first. After that, the results are propagated to the larger layer and the3232iterations are run again only on those pixels where the layer colors differ by more than sr from the3233lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the3234results will be actually different from the ones obtained by running the meanshift procedure on the3235whole original image (i.e. when maxLevel==0).32363237@param src The source 8-bit, 3-channel image.3238@param dst The destination image of the same format and the same size as the source.3239@param sp The spatial window radius.3240@param sr The color window radius.3241@param maxLevel Maximum level of the pyramid for the segmentation.3242@param termcrit Termination criteria: when to stop meanshift iterations.3243*/3244CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst,3245double sp, double sr, int maxLevel = 1,3246TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) );32473248//! @}32493250//! @addtogroup imgproc_misc3251//! @{32523253/** @example samples/cpp/grabcut.cpp3254An example using the GrabCut algorithm32553256*/32573258/** @brief Runs the GrabCut algorithm.32593260The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut).32613262@param img Input 8-bit 3-channel image.3263@param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when3264mode is set to #GC_INIT_WITH_RECT. Its elements may have one of the #GrabCutClasses.3265@param rect ROI containing a segmented object. The pixels outside of the ROI are marked as3266"obvious background". The parameter is only used when mode==#GC_INIT_WITH_RECT .3267@param bgdModel Temporary array for the background model. Do not modify it while you are3268processing the same image.3269@param fgdModel Temporary arrays for the foreground model. Do not modify it while you are3270processing the same image.3271@param iterCount Number of iterations the algorithm should make before returning the result. Note3272that the result can be refined with further calls with mode==#GC_INIT_WITH_MASK or3273mode==GC_EVAL .3274@param mode Operation mode that could be one of the #GrabCutModes3275*/3276CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect,3277InputOutputArray bgdModel, InputOutputArray fgdModel,3278int iterCount, int mode = GC_EVAL );32793280/** @example samples/cpp/distrans.cpp3281An example on using the distance transform3282*/32833284/** @brief Calculates the distance to the closest zero pixel for each pixel of the source image.32853286The function cv::distanceTransform calculates the approximate or precise distance from every binary3287image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero.32883289When maskSize == #DIST_MASK_PRECISE and distanceType == #DIST_L2 , the function runs the3290algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library.32913292In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function3293finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical,3294diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall3295distance is calculated as a sum of these basic distances. Since the distance function should be3296symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all3297the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the3298same cost (denoted as `c`). For the #DIST_C and #DIST_L1 types, the distance is calculated3299precisely, whereas for #DIST_L2 (Euclidean distance) the distance can be calculated only with a3300relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV3301uses the values suggested in the original paper:3302- DIST_L1: `a = 1, b = 2`3303- DIST_L2:3304- `3 x 3`: `a=0.955, b=1.3693`3305- `5 x 5`: `a=1, b=1.4, c=2.1969`3306- DIST_C: `a = 1, b = 1`33073308Typically, for a fast, coarse distance estimation #DIST_L2, a \f$3\times 3\f$ mask is used. For a3309more accurate distance estimation #DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used.3310Note that both the precise and the approximate algorithms are linear on the number of pixels.33113312This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$3313but also identifies the nearest connected component consisting of zero pixels3314(labelType==#DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==#DIST_LABEL_PIXEL). Index of the3315component/pixel is stored in `labels(x, y)`. When labelType==#DIST_LABEL_CCOMP, the function3316automatically finds connected components of zero pixels in the input image and marks them with3317distinct labels. When labelType==#DIST_LABEL_CCOMP, the function scans through the input image and3318marks all the zero pixels with distinct labels.33193320In this mode, the complexity is still linear. That is, the function provides a very fast way to3321compute the Voronoi diagram for a binary image. Currently, the second variant can use only the3322approximate distance transform algorithm, i.e. maskSize=#DIST_MASK_PRECISE is not supported3323yet.33243325@param src 8-bit, single-channel (binary) source image.3326@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,3327single-channel image of the same size as src.3328@param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type3329CV_32SC1 and the same size as src.3330@param distanceType Type of distance, see #DistanceTypes3331@param maskSize Size of the distance transform mask, see #DistanceTransformMasks.3332#DIST_MASK_PRECISE is not supported by this variant. In case of the #DIST_L1 or #DIST_C distance type,3333the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times33345\f$ or any larger aperture.3335@param labelType Type of the label array to build, see #DistanceTransformLabelTypes.3336*/3337CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst,3338OutputArray labels, int distanceType, int maskSize,3339int labelType = DIST_LABEL_CCOMP );33403341/** @overload3342@param src 8-bit, single-channel (binary) source image.3343@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point,3344single-channel image of the same size as src .3345@param distanceType Type of distance, see #DistanceTypes3346@param maskSize Size of the distance transform mask, see #DistanceTransformMasks. In case of the3347#DIST_L1 or #DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives3348the same result as \f$5\times 5\f$ or any larger aperture.3349@param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for3350the first variant of the function and distanceType == #DIST_L1.3351*/3352CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst,3353int distanceType, int maskSize, int dstType=CV_32F);33543355/** @example samples/cpp/ffilldemo.cpp3356An example using the FloodFill technique3357*/33583359/** @overload33603361variant without `mask` parameter3362*/3363CV_EXPORTS int floodFill( InputOutputArray image,3364Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0,3365Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),3366int flags = 4 );33673368/** @brief Fills a connected component with the given color.33693370The function cv::floodFill fills a connected component starting from the seed point with the specified3371color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The3372pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if:33733374- in case of a grayscale image and floating range3375\f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}\f]337633773378- in case of a grayscale image and fixed range3379\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]338033813382- in case of a color image and floating range3383\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]3384\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]3385and3386\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]338733883389- in case of a color image and fixed range3390\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]3391\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]3392and3393\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]339433953396where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the3397component. That is, to be added to the connected component, a color/brightness of the pixel should3398be close enough to:3399- Color/brightness of one of its neighbors that already belong to the connected component in case3400of a floating range.3401- Color/brightness of the seed point in case of a fixed range.34023403Use these functions to either mark a connected component with the specified color in-place, or build3404a mask and then extract the contour, or copy the region to another image, and so on.34053406@param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the3407function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See3408the details below.3409@param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels3410taller than image. Since this is both an input and output parameter, you must take responsibility3411of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example,3412an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the3413mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags3414as described below. Additionally, the function fills the border of the mask with ones to simplify3415internal processing. It is therefore possible to use the same mask in multiple calls to the function3416to make sure the filled areas do not overlap.3417@param seedPoint Starting point.3418@param newVal New value of the repainted domain pixels.3419@param loDiff Maximal lower brightness/color difference between the currently observed pixel and3420one of its neighbors belonging to the component, or a seed pixel being added to the component.3421@param upDiff Maximal upper brightness/color difference between the currently observed pixel and3422one of its neighbors belonging to the component, or a seed pixel being added to the component.3423@param rect Optional output parameter set by the function to the minimum bounding rectangle of the3424repainted domain.3425@param flags Operation flags. The first 8 bits contain a connectivity value. The default value of34264 means that only the four nearest neighbor pixels (those that share an edge) are considered. A3427connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner)3428will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill3429the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest3430neighbours and fill the mask with a value of 255. The following additional options occupy higher3431bits and therefore may be further combined with the connectivity and mask fill values using3432bit-wise or (|), see #FloodFillFlags.34333434@note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the3435pixel \f$(x+1, y+1)\f$ in the mask .34363437@sa findContours3438*/3439CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,3440Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0,3441Scalar loDiff = Scalar(), Scalar upDiff = Scalar(),3442int flags = 4 );34433444/** @brief Converts an image from one color space to another.34453446The function converts an input image from one color space to another. In case of a transformation3447to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note3448that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the3449bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue3450component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and3451sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.34523453The conventional ranges for R, G, and B channel values are:3454- 0 to 255 for CV_8U images3455- 0 to 65535 for CV_16U images3456- 0 to 1 for CV_32F images34573458In case of linear transformations, the range does not matter. But in case of a non-linear3459transformation, an input RGB image should be normalized to the proper value range to get the correct3460results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a346132-bit floating-point image directly converted from an 8-bit image without any scaling, then it will3462have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor ,3463you need first to scale the image down:3464@code3465img *= 1./255;3466cvtColor(img, img, COLOR_BGR2Luv);3467@endcode3468If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many3469applications, this will not be noticeable but it is recommended to use 32-bit images in applications3470that need the full range of colors or that convert an image before an operation and then convert3471back.34723473If conversion adds the alpha channel, its value will set to the maximum of corresponding channel3474range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.34753476@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision3477floating-point.3478@param dst output image of the same size and depth as src.3479@param code color space conversion code (see #ColorConversionCodes).3480@param dstCn number of channels in the destination image; if the parameter is 0, the number of the3481channels is derived automatically from src and code.34823483@see @ref imgproc_color_conversions3484*/3485CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );34863487/** @brief Converts an image from one color space to another where the source image is3488stored in two planes.34893490This function only supports YUV420 to RGB conversion as of now.34913492@param src1: 8-bit image (#CV_8U) of the Y plane.3493@param src2: image containing interleaved U/V plane.3494@param dst: output image.3495@param code: Specifies the type of conversion. It can take any of the following values:3496- #COLOR_YUV2BGR_NV123497- #COLOR_YUV2RGB_NV123498- #COLOR_YUV2BGRA_NV123499- #COLOR_YUV2RGBA_NV123500- #COLOR_YUV2BGR_NV213501- #COLOR_YUV2RGB_NV213502- #COLOR_YUV2BGRA_NV213503- #COLOR_YUV2RGBA_NV213504*/3505CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code );35063507//! @} imgproc_misc35083509// main function for all demosaicing processes3510CV_EXPORTS_W void demosaicing(InputArray _src, OutputArray _dst, int code, int dcn = 0);35113512//! @addtogroup imgproc_shape3513//! @{35143515/** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape.35163517The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The3518results are returned in the structure cv::Moments.35193520@param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array (3521\f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ).3522@param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is3523used for images only.3524@returns moments.35253526@note Only applicable to contour moments calculations from Python bindings: Note that the numpy3527type for the input array should be either np.int32 or np.float32.35283529@sa contourArea, arcLength3530*/3531CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false );35323533/** @brief Calculates seven Hu invariants.35343535The function calculates seven Hu invariants (introduced in @cite Hu62; see also3536<http://en.wikipedia.org/wiki/Image_moment>) defined as:35373538\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]35393540where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ .35413542These values are proved to be invariants to the image scale, rotation, and reflection except the3543seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of3544infinite image resolution. In case of raster images, the computed Hu invariants for the original and3545transformed images are a bit different.35463547@param moments Input moments computed with moments .3548@param hu Output Hu invariants.35493550@sa matchShapes3551*/3552CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );35533554/** @overload */3555CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu );35563557//! @} imgproc_shape35583559//! @addtogroup imgproc_object3560//! @{35613562//! type of the template matching operation3563enum TemplateMatchModes {3564TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]3565TM_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]3566TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f]3567TM_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]3568TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f]3569//!< where3570//!< \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]3571TM_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]3572};35733574/** @example samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp3575An example using Template Matching algorithm3576*/35773578/** @brief Compares a template against overlapped image regions.35793580The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against3581templ using the specified method and stores the comparison results in result . Here are the formulae3582for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation3583is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$35843585After the function finishes the comparison, the best matches can be found as global minimums (when3586#TM_SQDIFF was used) or maximums (when #TM_CCORR or #TM_CCOEFF was used) using the3587#minMaxLoc function. In case of a color image, template summation in the numerator and each sum in3588the denominator is done over all of the channels and separate mean values are used for each channel.3589That is, the function can take a color template and a color image. The result will still be a3590single-channel image, which is easier to analyze.35913592@param image Image where the search is running. It must be 8-bit or 32-bit floating-point.3593@param templ Searched template. It must be not greater than the source image and have the same3594data type.3595@param result Map of comparison results. It must be single-channel 32-bit floating-point. If image3596is \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$ .3597@param method Parameter specifying the comparison method, see #TemplateMatchModes3598@param mask Mask of searched template. It must have the same datatype and size with templ. It is3599not set by default. Currently, only the #TM_SQDIFF and #TM_CCORR_NORMED methods are supported.3600*/3601CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,3602OutputArray result, int method, InputArray mask = noArray() );36033604//! @}36053606//! @addtogroup imgproc_shape3607//! @{36083609/** @example samples/cpp/connected_components.cpp3610This program demonstrates connected components and use of the trackbar3611*/36123613/** @brief computes the connected components labeled image of boolean image36143615image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 03616represents the background label. ltype specifies the output label image type, an important3617consideration based on the total number of labels or alternatively the total number of pixels in3618the source image. ccltype specifies the connected components labeling algorithm to use, currently3619Grana (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes3620for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.3621This function uses parallel version of both Grana and Wu's algorithms if at least one allowed3622parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.36233624@param image the 8-bit single-channel image to be labeled3625@param labels destination labeled image3626@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively3627@param ltype output image label type. Currently CV_32S and CV_16U are supported.3628@param ccltype connected components algorithm type (see the #ConnectedComponentsAlgorithmsTypes).3629*/3630CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels,3631int connectivity, int ltype, int ccltype);363236333634/** @overload36353636@param image the 8-bit single-channel image to be labeled3637@param labels destination labeled image3638@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively3639@param ltype output image label type. Currently CV_32S and CV_16U are supported.3640*/3641CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels,3642int connectivity = 8, int ltype = CV_32S);364336443645/** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label36463647image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 03648represents the background label. ltype specifies the output label image type, an important3649consideration based on the total number of labels or alternatively the total number of pixels in3650the source image. ccltype specifies the connected components labeling algorithm to use, currently3651Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes3652for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.3653This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed3654parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.36553656@param image the 8-bit single-channel image to be labeled3657@param labels destination labeled image3658@param stats statistics output for each label, including the background label, see below for3659available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of3660#ConnectedComponentsTypes. The data type is CV_32S.3661@param centroids centroid output for each label, including the background label. Centroids are3662accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.3663@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively3664@param ltype output image label type. Currently CV_32S and CV_16U are supported.3665@param ccltype connected components algorithm type (see #ConnectedComponentsAlgorithmsTypes).3666*/3667CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels,3668OutputArray stats, OutputArray centroids,3669int connectivity, int ltype, int ccltype);36703671/** @overload3672@param image the 8-bit single-channel image to be labeled3673@param labels destination labeled image3674@param stats statistics output for each label, including the background label, see below for3675available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of3676#ConnectedComponentsTypes. The data type is CV_32S.3677@param centroids centroid output for each label, including the background label. Centroids are3678accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.3679@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively3680@param ltype output image label type. Currently CV_32S and CV_16U are supported.3681*/3682CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels,3683OutputArray stats, OutputArray centroids,3684int connectivity = 8, int ltype = CV_32S);368536863687/** @brief Finds contours in a binary image.36883689The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours3690are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the3691OpenCV sample directory.3692@note Since opencv 3.2 source image is not modified by this function.36933694@param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero3695pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold ,3696#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one.3697If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).3698@param contours Detected contours. Each contour is stored as a vector of points (e.g.3699std::vector<std::vector<cv::Point> >).3700@param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has3701as many elements as the number of contours. For each i-th contour contours[i], the elements3702hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices3703in contours of the next and previous contours at the same hierarchical level, the first child3704contour and the parent contour, respectively. If for the contour i there are no next, previous,3705parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.3706@param mode Contour retrieval mode, see #RetrievalModes3707@param method Contour approximation method, see #ContourApproximationModes3708@param offset Optional offset by which every contour point is shifted. This is useful if the3709contours are extracted from the image ROI and then they should be analyzed in the whole image3710context.3711*/3712CV_EXPORTS_W void findContours( InputArray image, OutputArrayOfArrays contours,3713OutputArray hierarchy, int mode,3714int method, Point offset = Point());37153716/** @overload */3717CV_EXPORTS void findContours( InputArray image, OutputArrayOfArrays contours,3718int mode, int method, Point offset = Point());37193720/** @example samples/cpp/squares.cpp3721A program using pyramid scaling, Canny, contours and contour simplification to find3722squares in a list of images (pic1-6.png). Returns sequence of squares detected on the image.3723*/37243725/** @example samples/tapi/squares.cpp3726A program using pyramid scaling, Canny, contours and contour simplification to find3727squares in the input image.3728*/37293730/** @brief Approximates a polygonal curve(s) with the specified precision.37313732The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less3733vertices so that the distance between them is less or equal to the specified precision. It uses the3734Douglas-Peucker algorithm <http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm>37353736@param curve Input vector of a 2D point stored in std::vector or Mat3737@param approxCurve Result of the approximation. The type should match the type of the input curve.3738@param epsilon Parameter specifying the approximation accuracy. This is the maximum distance3739between the original curve and its approximation.3740@param closed If true, the approximated curve is closed (its first and last vertices are3741connected). Otherwise, it is not closed.3742*/3743CV_EXPORTS_W void approxPolyDP( InputArray curve,3744OutputArray approxCurve,3745double epsilon, bool closed );37463747/** @brief Calculates a contour perimeter or a curve length.37483749The function computes a curve length or a closed contour perimeter.37503751@param curve Input vector of 2D points, stored in std::vector or Mat.3752@param closed Flag indicating whether the curve is closed or not.3753*/3754CV_EXPORTS_W double arcLength( InputArray curve, bool closed );37553756/** @brief Calculates the up-right bounding rectangle of a point set.37573758The function calculates and returns the minimal up-right bounding rectangle for the specified point set.37593760@param points Input 2D point set, stored in std::vector or Mat.3761*/3762CV_EXPORTS_W Rect boundingRect( InputArray points );37633764/** @brief Calculates a contour area.37653766The function computes a contour area. Similarly to moments , the area is computed using the Green3767formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using3768#drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong3769results for contours with self-intersections.37703771Example:3772@code3773vector<Point> contour;3774contour.push_back(Point2f(0, 0));3775contour.push_back(Point2f(10, 0));3776contour.push_back(Point2f(10, 10));3777contour.push_back(Point2f(5, 4));37783779double area0 = contourArea(contour);3780vector<Point> approx;3781approxPolyDP(contour, approx, 5, true);3782double area1 = contourArea(approx);37833784cout << "area0 =" << area0 << endl <<3785"area1 =" << area1 << endl <<3786"approx poly vertices" << approx.size() << endl;3787@endcode3788@param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat.3789@param oriented Oriented area flag. If it is true, the function returns a signed area value,3790depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can3791determine orientation of a contour by taking the sign of an area. By default, the parameter is3792false, which means that the absolute value is returned.3793*/3794CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false );37953796/** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set.37973798The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a3799specified point set. Developer should keep in mind that the returned RotatedRect can contain negative3800indices when data is close to the containing Mat element boundary.38013802@param points Input vector of 2D points, stored in std::vector\<\> or Mat3803*/3804CV_EXPORTS_W RotatedRect minAreaRect( InputArray points );38053806/** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.38073808The function finds the four vertices of a rotated rectangle. This function is useful to draw the3809rectangle. In C++, instead of using this function, you can directly use RotatedRect::points method. Please3810visit the @ref tutorial_bounding_rotated_ellipses "tutorial on Creating Bounding rotated boxes and ellipses for contours" for more information.38113812@param box The input rotated rectangle. It may be the output of3813@param points The output array of four vertices of rectangles.3814*/3815CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points);38163817/** @brief Finds a circle of the minimum area enclosing a 2D point set.38183819The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm.38203821@param points Input vector of 2D points, stored in std::vector\<\> or Mat3822@param center Output center of the circle.3823@param radius Output radius of the circle.3824*/3825CV_EXPORTS_W void minEnclosingCircle( InputArray points,3826CV_OUT Point2f& center, CV_OUT float& radius );38273828/** @example samples/cpp/minarea.cpp3829*/38303831/** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area.38323833The function finds a triangle of minimum area enclosing the given set of 2D points and returns its3834area. The output for a given 2D point set is shown in the image below. 2D points are depicted in3835*red* and the enclosing triangle in *yellow*.3836383738383839The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's3840@cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal3841enclosing triangle of a 2D convex polygon with n vertices. Since the #minEnclosingTriangle function3842takes a 2D point set as input an additional preprocessing step of computing the convex hull of the38432D point set is required. The complexity of the #convexHull function is \f$O(n log(n))\f$ which is higher3844than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$.38453846@param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat3847@param triangle Output vector of three 2D points defining the vertices of the triangle. The depth3848of the OutputArray must be CV_32F.3849*/3850CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle );38513852/** @brief Compares two shapes.38533854The function compares two shapes. All three implemented methods use the Hu invariants (see #HuMoments)38553856@param contour1 First contour or grayscale image.3857@param contour2 Second contour or grayscale image.3858@param method Comparison method, see #ShapeMatchModes3859@param parameter Method-specific parameter (not supported now).3860*/3861CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2,3862int method, double parameter );38633864/** @example samples/cpp/convexhull.cpp3865An example using the convexHull functionality3866*/38673868/** @brief Finds the convex hull of a point set.38693870The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky823871that has *O(N logN)* complexity in the current implementation.38723873@param points Input 2D point set, stored in std::vector or Mat.3874@param hull Output convex hull. It is either an integer vector of indices or vector of points. In3875the first case, the hull elements are 0-based indices of the convex hull points in the original3876array (since the set of convex hull points is a subset of the original point set). In the second3877case, hull elements are the convex hull points themselves.3878@param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise.3879Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing3880to the right, and its Y axis pointing upwards.3881@param returnPoints Operation flag. In case of a matrix, when the flag is true, the function3882returns convex hull points. Otherwise, it returns indices of the convex hull points. When the3883output array is std::vector, the flag is ignored, and the output depends on the type of the3884vector: std::vector\<int\> implies returnPoints=false, std::vector\<Point\> implies3885returnPoints=true.38863887@note `points` and `hull` should be different arrays, inplace processing isn't supported.3888*/3889CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull,3890bool clockwise = false, bool returnPoints = true );38913892/** @brief Finds the convexity defects of a contour.38933894The figure below displays convexity defects of a hand contour:3895389638973898@param contour Input contour.3899@param convexhull Convex hull obtained using convexHull that should contain indices of the contour3900points that make the hull.3901@param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java3902interface each convexity defect is represented as 4-element integer vector (a.k.a. #Vec4i):3903(start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices3904in the original contour of the convexity defect beginning, end and the farthest point, and3905fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the3906farthest contour point and the hull. That is, to get the floating-point value of the depth will be3907fixpt_depth/256.0.3908*/3909CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects );39103911/** @brief Tests a contour convexity.39123913The function tests whether the input contour is convex or not. The contour must be simple, that is,3914without self-intersections. Otherwise, the function output is undefined.39153916@param contour Input vector of 2D points, stored in std::vector\<\> or Mat3917*/3918CV_EXPORTS_W bool isContourConvex( InputArray contour );39193920//! finds intersection of two convex polygons3921CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2,3922OutputArray _p12, bool handleNested = true );39233924/** @example samples/cpp/fitellipse.cpp3925An example using the fitEllipse technique3926*/39273928/** @brief Fits an ellipse around a set of 2D points.39293930The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of3931all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon953932is used. Developer should keep in mind that it is possible that the returned3933ellipse/rotatedRect data contains negative indices, due to the data points being close to the3934border of the containing Mat element.39353936@param points Input 2D point set, stored in std::vector\<\> or Mat3937*/3938CV_EXPORTS_W RotatedRect fitEllipse( InputArray points );39393940/** @brief Fits an ellipse around a set of 2D points.39413942The function calculates the ellipse that fits a set of 2D points.3943It returns the rotated rectangle in which the ellipse is inscribed.3944The Approximate Mean Square (AMS) proposed by @cite Taubin1991 is used.39453946For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$,3947which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$.3948However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$,3949the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines,3950quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits.3951If the fit is found to be a parabolic or hyperbolic function then the standard #fitEllipse method is used.3952The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves3953by imposing the condition that \f$ A^T ( D_x^T D_x + D_y^T D_y) A = 1 \f$ where3954the matrices \f$ Dx \f$ and \f$ Dy \f$ are the partial derivatives of the design matrix \f$ D \f$ with3955respect to x and y. The matrices are formed row by row applying the following to3956each of the points in the set:3957\f{align*}{3958D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} &3959D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} &3960D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\}3961\f}3962The AMS method minimizes the cost function3963\f{equation*}{3964\epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T }3965\f}39663967The minimum cost is found by solving the generalized eigenvalue problem.39683969\f{equation*}{3970D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A3971\f}39723973@param points Input 2D point set, stored in std::vector\<\> or Mat3974*/3975CV_EXPORTS_W RotatedRect fitEllipseAMS( InputArray points );397639773978/** @brief Fits an ellipse around a set of 2D points.39793980The function calculates the ellipse that fits a set of 2D points.3981It returns the rotated rectangle in which the ellipse is inscribed.3982The Direct least square (Direct) method by @cite Fitzgibbon1999 is used.39833984For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$,3985which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$.3986However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$,3987the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines,3988quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits.3989The Direct method confines the fit to ellipses by ensuring that \f$ 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \f$.3990The condition imposed is that \f$ 4 A_{xx} A_{yy}- A_{xy}^2=1 \f$ which satisfies the inequality3991and as the coefficients can be arbitrarily scaled is not overly restrictive.39923993\f{equation*}{3994\epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix}39950 & 0 & 2 & 0 & 0 & 0 \\39960 & -1 & 0 & 0 & 0 & 0 \\39972 & 0 & 0 & 0 & 0 & 0 \\39980 & 0 & 0 & 0 & 0 & 0 \\39990 & 0 & 0 & 0 & 0 & 0 \\40000 & 0 & 0 & 0 & 0 & 04001\end{matrix} \right)4002\f}40034004The minimum cost is found by solving the generalized eigenvalue problem.40054006\f{equation*}{4007D^T D A = \lambda \left( C\right) A4008\f}40094010The system produces only one positive eigenvalue \f$ \lambda\f$ which is chosen as the solution4011with its eigenvector \f$\mathbf{u}\f$. These are used to find the coefficients40124013\f{equation*}{4014A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u}4015\f}4016The scaling factor guarantees that \f$A^T C A =1\f$.40174018@param points Input 2D point set, stored in std::vector\<\> or Mat4019*/4020CV_EXPORTS_W RotatedRect fitEllipseDirect( InputArray points );40214022/** @brief Fits a line to a 2D or 3D point set.40234024The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where4025\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, one4026of the following:4027- DIST_L24028\f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f]4029- DIST_L14030\f[\rho (r) = r\f]4031- DIST_L124032\f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f]4033- DIST_FAIR4034\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]4035- DIST_WELSCH4036\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]4037- DIST_HUBER4038\f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f]40394040The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique4041that iteratively fits the line using the weighted least-squares algorithm. After each iteration the4042weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ .40434044@param points Input vector of 2D or 3D points, stored in std::vector\<\> or Mat.4045@param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements4046(like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and4047(x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like4048Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line4049and (x0, y0, z0) is a point on the line.4050@param distType Distance used by the M-estimator, see #DistanceTypes4051@param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value4052is chosen.4053@param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line).4054@param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps.4055*/4056CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType,4057double param, double reps, double aeps );40584059/** @brief Performs a point-in-contour test.40604061The function determines whether the point is inside a contour, outside, or lies on an edge (or4062coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge)4063value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively.4064Otherwise, the return value is a signed distance between the point and the nearest contour edge.40654066See below a sample output of the function where each image pixel is tested against the contour:4067406840694070@param contour Input contour.4071@param pt Point tested against the contour.4072@param measureDist If true, the function estimates the signed distance from the point to the4073nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not.4074*/4075CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist );40764077/** @brief Finds out if there is any intersection between two rotated rectangles.40784079If there is then the vertices of the intersecting region are returned as well.40804081Below are some examples of intersection configurations. The hatched pattern indicates the4082intersecting region and the red vertices are returned by the function.4083408440854086@param rect1 First rectangle4087@param rect2 Second rectangle4088@param intersectingRegion The output array of the vertices of the intersecting region. It returns4089at most 8 vertices. Stored as std::vector\<cv::Point2f\> or cv::Mat as Mx1 of type CV_32FC2.4090@returns One of #RectanglesIntersectTypes4091*/4092CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion );40934094//! @} imgproc_shape4095/** @brief Creates implementation for cv::CLAHE .40964097@param clipLimit Threshold for contrast limiting.4098@param tileGridSize Size of grid for histogram equalization. Input image will be divided into4099equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column.4100*/4101CV_EXPORTS_W Ptr<CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8));41024103//! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.4104//! Detects position only without translation and rotation4105CV_EXPORTS Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard();41064107//! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.4108//! Detects position, translation and rotation4109CV_EXPORTS Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil();41104111//! Performs linear blending of two images:4112//! \f[ \texttt{dst}(i,j) = \texttt{weights1}(i,j)*\texttt{src1}(i,j) + \texttt{weights2}(i,j)*\texttt{src2}(i,j) \f]4113//! @param src1 It has a type of CV_8UC(n) or CV_32FC(n), where n is a positive integer.4114//! @param src2 It has the same type and size as src1.4115//! @param weights1 It has a type of CV_32FC1 and the same size with src1.4116//! @param weights2 It has a type of CV_32FC1 and the same size with src1.4117//! @param dst It is created if it does not have the same size and type with src1.4118CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst);41194120//! @addtogroup imgproc_colormap4121//! @{41224123//! GNU Octave/MATLAB equivalent colormaps4124enum ColormapTypes4125{4126COLORMAP_AUTUMN = 0, //!< 4127COLORMAP_BONE = 1, //!< 4128COLORMAP_JET = 2, //!< 4129COLORMAP_WINTER = 3, //!< 4130COLORMAP_RAINBOW = 4, //!< 4131COLORMAP_OCEAN = 5, //!< 4132COLORMAP_SUMMER = 6, //!< 4133COLORMAP_SPRING = 7, //!< 4134COLORMAP_COOL = 8, //!< 4135COLORMAP_HSV = 9, //!< 4136COLORMAP_PINK = 10, //!< 4137COLORMAP_HOT = 11, //!< 4138COLORMAP_PARULA = 12 //!< 4139};41404141/** @example samples/cpp/falsecolor.cpp4142An example using applyColorMap function4143*/41444145/** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image.41464147@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.4148@param dst The result is the colormapped source image. Note: Mat::create is called on dst.4149@param colormap The colormap to apply, see #ColormapTypes4150*/4151CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap);41524153/** @brief Applies a user colormap on a given image.41544155@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.4156@param dst The result is the colormapped source image. Note: Mat::create is called on dst.4157@param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 2564158*/4159CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor);41604161//! @} imgproc_colormap41624163//! @addtogroup imgproc_draw4164//! @{416541664167/** OpenCV color channel order is BGR[A] */4168#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)41694170/** @brief Draws a line segment connecting two points.41714172The function line draws the line segment between pt1 and pt2 points in the image. The line is4173clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected4174or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased4175lines are drawn using Gaussian filtering.41764177@param img Image.4178@param pt1 First point of the line segment.4179@param pt2 Second point of the line segment.4180@param color Line color.4181@param thickness Line thickness.4182@param lineType Type of the line. See #LineTypes.4183@param shift Number of fractional bits in the point coordinates.4184*/4185CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,4186int thickness = 1, int lineType = LINE_8, int shift = 0);41874188/** @brief Draws a arrow segment pointing from the first point to the second one.41894190The function cv::arrowedLine draws an arrow between pt1 and pt2 points in the image. See also #line.41914192@param img Image.4193@param pt1 The point the arrow starts from.4194@param pt2 The point the arrow points to.4195@param color Line color.4196@param thickness Line thickness.4197@param line_type Type of the line. See #LineTypes4198@param shift Number of fractional bits in the point coordinates.4199@param tipLength The length of the arrow tip in relation to the arrow length4200*/4201CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,4202int thickness=1, int line_type=8, int shift=0, double tipLength=0.1);42034204/** @brief Draws a simple, thick, or filled up-right rectangle.42054206The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners4207are pt1 and pt2.42084209@param img Image.4210@param pt1 Vertex of the rectangle.4211@param pt2 Vertex of the rectangle opposite to pt1 .4212@param color Rectangle color or brightness (grayscale image).4213@param thickness Thickness of lines that make up the rectangle. Negative values, like #FILLED,4214mean that the function has to draw a filled rectangle.4215@param lineType Type of the line. See #LineTypes4216@param shift Number of fractional bits in the point coordinates.4217*/4218CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,4219const Scalar& color, int thickness = 1,4220int lineType = LINE_8, int shift = 0);42214222/** @overload42234224use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and4225r.br()-Point(1,1)` are opposite corners4226*/4227CV_EXPORTS_W void rectangle(InputOutputArray img, Rect rec,4228const Scalar& color, int thickness = 1,4229int lineType = LINE_8, int shift = 0);42304231/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_2.cpp4232An example using drawing functions4233*/42344235/** @brief Draws a circle.42364237The function cv::circle draws a simple or filled circle with a given center and radius.4238@param img Image where the circle is drawn.4239@param center Center of the circle.4240@param radius Radius of the circle.4241@param color Circle color.4242@param thickness Thickness of the circle outline, if positive. Negative values, like #FILLED,4243mean that a filled circle is to be drawn.4244@param lineType Type of the circle boundary. See #LineTypes4245@param shift Number of fractional bits in the coordinates of the center and in the radius value.4246*/4247CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius,4248const Scalar& color, int thickness = 1,4249int lineType = LINE_8, int shift = 0);42504251/** @brief Draws a simple or thick elliptic arc or fills an ellipse sector.42524253The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic4254arc, or a filled ellipse sector. The drawing code uses general parametric form.4255A piecewise-linear curve is used to approximate the elliptic arc4256boundary. If you need more control of the ellipse rendering, you can retrieve the curve using4257#ellipse2Poly and then render it with #polylines or fill it with #fillPoly. If you use the first4258variant of the function and want to draw the whole ellipse, not an arc, pass `startAngle=0` and4259`endAngle=360`. If `startAngle` is greater than `endAngle`, they are swapped. The figure below explains4260the meaning of the parameters to draw the blue arc.4261426242634264@param img Image.4265@param center Center of the ellipse.4266@param axes Half of the size of the ellipse main axes.4267@param angle Ellipse rotation angle in degrees.4268@param startAngle Starting angle of the elliptic arc in degrees.4269@param endAngle Ending angle of the elliptic arc in degrees.4270@param color Ellipse color.4271@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that4272a filled ellipse sector is to be drawn.4273@param lineType Type of the ellipse boundary. See #LineTypes4274@param shift Number of fractional bits in the coordinates of the center and values of axes.4275*/4276CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,4277double angle, double startAngle, double endAngle,4278const Scalar& color, int thickness = 1,4279int lineType = LINE_8, int shift = 0);42804281/** @overload4282@param img Image.4283@param box Alternative ellipse representation via RotatedRect. This means that the function draws4284an ellipse inscribed in the rotated rectangle.4285@param color Ellipse color.4286@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that4287a filled ellipse sector is to be drawn.4288@param lineType Type of the ellipse boundary. See #LineTypes4289*/4290CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color,4291int thickness = 1, int lineType = LINE_8);42924293/* ----------------------------------------------------------------------------------------- */4294/* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */4295/* ----------------------------------------------------------------------------------------- */42964297/** @brief Draws a marker on a predefined position in an image.42984299The function cv::drawMarker draws a marker on a given position in the image. For the moment several4300marker types are supported, see #MarkerTypes for more information.43014302@param img Image.4303@param position The point where the crosshair is positioned.4304@param color Line color.4305@param markerType The specific type of marker you want to use, see #MarkerTypes4306@param thickness Line thickness.4307@param line_type Type of the line, See #LineTypes4308@param markerSize The length of the marker axis [default = 20 pixels]4309*/4310CV_EXPORTS_W void drawMarker(InputOutputArray img, Point position, const Scalar& color,4311int markerType = MARKER_CROSS, int markerSize=20, int thickness=1,4312int line_type=8);43134314/* ----------------------------------------------------------------------------------------- */4315/* END OF MARKER SECTION */4316/* ----------------------------------------------------------------------------------------- */43174318/** @overload */4319CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,4320const Scalar& color, int lineType = LINE_8,4321int shift = 0);43224323/** @brief Fills a convex polygon.43244325The function cv::fillConvexPoly draws a filled convex polygon. This function is much faster than the4326function #fillPoly . It can fill not only convex polygons but any monotonic polygon without4327self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line)4328twice at the most (though, its top-most and/or the bottom edge could be horizontal).43294330@param img Image.4331@param points Polygon vertices.4332@param color Polygon color.4333@param lineType Type of the polygon boundaries. See #LineTypes4334@param shift Number of fractional bits in the vertex coordinates.4335*/4336CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,4337const Scalar& color, int lineType = LINE_8,4338int shift = 0);43394340/** @overload */4341CV_EXPORTS void fillPoly(Mat& img, const Point** pts,4342const int* npts, int ncontours,4343const Scalar& color, int lineType = LINE_8, int shift = 0,4344Point offset = Point() );43454346/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp4347An example using drawing functions4348Check @ref tutorial_random_generator_and_text "the corresponding tutorial" for more details4349*/43504351/** @brief Fills the area bounded by one or more polygons.43524353The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill4354complex areas, for example, areas with holes, contours with self-intersections (some of their4355parts), and so forth.43564357@param img Image.4358@param pts Array of polygons where each polygon is represented as an array of points.4359@param color Polygon color.4360@param lineType Type of the polygon boundaries. See #LineTypes4361@param shift Number of fractional bits in the vertex coordinates.4362@param offset Optional offset of all points of the contours.4363*/4364CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,4365const Scalar& color, int lineType = LINE_8, int shift = 0,4366Point offset = Point() );43674368/** @overload */4369CV_EXPORTS void polylines(Mat& img, const Point* const* pts, const int* npts,4370int ncontours, bool isClosed, const Scalar& color,4371int thickness = 1, int lineType = LINE_8, int shift = 0 );43724373/** @brief Draws several polygonal curves.43744375@param img Image.4376@param pts Array of polygonal curves.4377@param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed,4378the function draws a line from the last vertex of each curve to its first vertex.4379@param color Polyline color.4380@param thickness Thickness of the polyline edges.4381@param lineType Type of the line segments. See #LineTypes4382@param shift Number of fractional bits in the vertex coordinates.43834384The function cv::polylines draws one or more polygonal curves.4385*/4386CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,4387bool isClosed, const Scalar& color,4388int thickness = 1, int lineType = LINE_8, int shift = 0 );43894390/** @example samples/cpp/contours2.cpp4391An example program illustrates the use of cv::findContours and cv::drawContours4392\image html WindowsQtContoursOutput.png "Screenshot of the program"4393*/43944395/** @example samples/cpp/segment_objects.cpp4396An example using drawContours to clean up a background segmentation result4397*/43984399/** @brief Draws contours outlines or filled contours.44004401The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area4402bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve4403connected components from the binary image and label them: :4404@include snippets/imgproc_drawContours.cpp44054406@param image Destination image.4407@param contours All the input contours. Each contour is stored as a point vector.4408@param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn.4409@param color Color of the contours.4410@param thickness Thickness of lines the contours are drawn with. If it is negative (for example,4411thickness=#FILLED ), the contour interiors are drawn.4412@param lineType Line connectivity. See #LineTypes4413@param hierarchy Optional information about hierarchy. It is only needed if you want to draw only4414some of the contours (see maxLevel ).4415@param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn.4416If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function4417draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This4418parameter is only taken into account when there is hierarchy available.4419@param offset Optional contour shift parameter. Shift all the drawn contours by the specified4420\f$\texttt{offset}=(dx,dy)\f$ .4421@note When thickness=#FILLED, the function is designed to handle connected components with holes correctly4422even when no hierarchy date is provided. This is done by analyzing all the outlines together4423using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved4424contours. In order to solve this problem, you need to call #drawContours separately for each sub-group4425of contours, or iterate over the collection using contourIdx parameter.4426*/4427CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours,4428int contourIdx, const Scalar& color,4429int thickness = 1, int lineType = LINE_8,4430InputArray hierarchy = noArray(),4431int maxLevel = INT_MAX, Point offset = Point() );44324433/** @brief Clips the line against the image rectangle.44344435The function cv::clipLine calculates a part of the line segment that is entirely within the specified4436rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise,4437it returns true .4438@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .4439@param pt1 First line point.4440@param pt2 Second line point.4441*/4442CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);44434444/** @overload4445@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .4446@param pt1 First line point.4447@param pt2 Second line point.4448*/4449CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2);44504451/** @overload4452@param imgRect Image rectangle.4453@param pt1 First line point.4454@param pt2 Second line point.4455*/4456CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);44574458/** @brief Approximates an elliptic arc with a polyline.44594460The function ellipse2Poly computes the vertices of a polyline that approximates the specified4461elliptic arc. It is used by #ellipse. If `arcStart` is greater than `arcEnd`, they are swapped.44624463@param center Center of the arc.4464@param axes Half of the size of the ellipse main axes. See #ellipse for details.4465@param angle Rotation angle of the ellipse in degrees. See #ellipse for details.4466@param arcStart Starting angle of the elliptic arc in degrees.4467@param arcEnd Ending angle of the elliptic arc in degrees.4468@param delta Angle between the subsequent polyline vertices. It defines the approximation4469accuracy.4470@param pts Output vector of polyline vertices.4471*/4472CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,4473int arcStart, int arcEnd, int delta,4474CV_OUT std::vector<Point>& pts );44754476/** @overload4477@param center Center of the arc.4478@param axes Half of the size of the ellipse main axes. See #ellipse for details.4479@param angle Rotation angle of the ellipse in degrees. See #ellipse for details.4480@param arcStart Starting angle of the elliptic arc in degrees.4481@param arcEnd Ending angle of the elliptic arc in degrees.4482@param delta Angle between the subsequent polyline vertices. It defines the approximation accuracy.4483@param pts Output vector of polyline vertices.4484*/4485CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle,4486int arcStart, int arcEnd, int delta,4487CV_OUT std::vector<Point2d>& pts);44884489/** @brief Draws a text string.44904491The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered4492using the specified font are replaced by question marks. See #getTextSize for a text rendering code4493example.44944495@param img Image.4496@param text Text string to be drawn.4497@param org Bottom-left corner of the text string in the image.4498@param fontFace Font type, see #HersheyFonts.4499@param fontScale Font scale factor that is multiplied by the font-specific base size.4500@param color Text color.4501@param thickness Thickness of the lines used to draw a text.4502@param lineType Line type. See #LineTypes4503@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,4504it is at the top-left corner.4505*/4506CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org,4507int fontFace, double fontScale, Scalar color,4508int thickness = 1, int lineType = LINE_8,4509bool bottomLeftOrigin = false );45104511/** @brief Calculates the width and height of a text string.45124513The function cv::getTextSize calculates and returns the size of a box that contains the specified text.4514That is, the following code renders some text, the tight box surrounding it, and the baseline: :4515@code4516String text = "Funny text inside the box";4517int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;4518double fontScale = 2;4519int thickness = 3;45204521Mat img(600, 800, CV_8UC3, Scalar::all(0));45224523int baseline=0;4524Size textSize = getTextSize(text, fontFace,4525fontScale, thickness, &baseline);4526baseline += thickness;45274528// center the text4529Point textOrg((img.cols - textSize.width)/2,4530(img.rows + textSize.height)/2);45314532// draw the box4533rectangle(img, textOrg + Point(0, baseline),4534textOrg + Point(textSize.width, -textSize.height),4535Scalar(0,0,255));4536// ... and the baseline first4537line(img, textOrg + Point(0, thickness),4538textOrg + Point(textSize.width, thickness),4539Scalar(0, 0, 255));45404541// then put the text itself4542putText(img, text, textOrg, fontFace, fontScale,4543Scalar::all(255), thickness, 8);4544@endcode45454546@param text Input text string.4547@param fontFace Font to use, see #HersheyFonts.4548@param fontScale Font scale factor that is multiplied by the font-specific base size.4549@param thickness Thickness of lines used to render the text. See #putText for details.4550@param[out] baseLine y-coordinate of the baseline relative to the bottom-most text4551point.4552@return The size of a box that contains the specified text.45534554@see putText4555*/4556CV_EXPORTS_W Size getTextSize(const String& text, int fontFace,4557double fontScale, int thickness,4558CV_OUT int* baseLine);455945604561/** @brief Calculates the font-specific size to use to achieve a given height in pixels.45624563@param fontFace Font to use, see cv::HersheyFonts.4564@param pixelHeight Pixel height to compute the fontScale for4565@param thickness Thickness of lines used to render the text.See putText for details.4566@return The fontSize to use for cv::putText45674568@see cv::putText4569*/4570CV_EXPORTS_W double getFontScaleFromHeight(const int fontFace,4571const int pixelHeight,4572const int thickness = 1);45734574/** @brief Line iterator45754576The class is used to iterate over all the pixels on the raster line4577segment connecting two specified points.45784579The class LineIterator is used to get each pixel of a raster line. It4580can be treated as versatile implementation of the Bresenham algorithm4581where you can stop at each pixel and do some extra processing, for4582example, grab pixel values along the line or draw a line with an effect4583(for example, with XOR operation).45844585The number of pixels along the line is stored in LineIterator::count.4586The method LineIterator::pos returns the current position in the image:45874588@code{.cpp}4589// grabs pixels along the line (pt1, pt2)4590// from 8-bit 3-channel image to the buffer4591LineIterator it(img, pt1, pt2, 8);4592LineIterator it2 = it;4593vector<Vec3b> buf(it.count);45944595for(int i = 0; i < it.count; i++, ++it)4596buf[i] = *(const Vec3b)*it;45974598// alternative way of iterating through the line4599for(int i = 0; i < it2.count; i++, ++it2)4600{4601Vec3b val = img.at<Vec3b>(it2.pos());4602CV_Assert(buf[i] == val);4603}4604@endcode4605*/4606class CV_EXPORTS LineIterator4607{4608public:4609/** @brief initializes the iterator46104611creates iterators for the line connecting pt1 and pt24612the line will be clipped on the image boundaries4613the line is 8-connected or 4-connected4614If leftToRight=true, then the iteration is always done4615from the left-most point to the right most,4616not to depend on the ordering of pt1 and pt2 parameters4617*/4618LineIterator( const Mat& img, Point pt1, Point pt2,4619int connectivity = 8, bool leftToRight = false );4620/** @brief returns pointer to the current pixel4621*/4622uchar* operator *();4623/** @brief prefix increment operator (++it). shifts iterator to the next pixel4624*/4625LineIterator& operator ++();4626/** @brief postfix increment operator (it++). shifts iterator to the next pixel4627*/4628LineIterator operator ++(int);4629/** @brief returns coordinates of the current pixel4630*/4631Point pos() const;46324633uchar* ptr;4634const uchar* ptr0;4635int step, elemSize;4636int err, count;4637int minusDelta, plusDelta;4638int minusStep, plusStep;4639};46404641//! @cond IGNORED46424643// === LineIterator implementation ===46444645inline4646uchar* LineIterator::operator *()4647{4648return ptr;4649}46504651inline4652LineIterator& LineIterator::operator ++()4653{4654int mask = err < 0 ? -1 : 0;4655err += minusDelta + (plusDelta & mask);4656ptr += minusStep + (plusStep & mask);4657return *this;4658}46594660inline4661LineIterator LineIterator::operator ++(int)4662{4663LineIterator it = *this;4664++(*this);4665return it;4666}46674668inline4669Point LineIterator::pos() const4670{4671Point p;4672p.y = (int)((ptr - ptr0)/step);4673p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize);4674return p;4675}46764677//! @endcond46784679//! @} imgproc_draw46804681//! @} imgproc46824683} // cv46844685#endif468646874688