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