Line data Source code
1 : /*M///////////////////////////////////////////////////////////////////////////////////////
2 : //
3 : // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 : //
5 : // By downloading, copying, installing or using the software you agree to this license.
6 : // If you do not agree to this license, do not download, install,
7 : // copy or use the software.
8 : //
9 : //
10 : // License Agreement
11 : // For Open Source Computer Vision Library
12 : //
13 : // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 : // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 : // Third party copyrights are property of their respective owners.
16 : //
17 : // Redistribution and use in source and binary forms, with or without modification,
18 : // are permitted provided that the following conditions are met:
19 : //
20 : // * Redistribution's of source code must retain the above copyright notice,
21 : // this list of conditions and the following disclaimer.
22 : //
23 : // * Redistribution's in binary form must reproduce the above copyright notice,
24 : // this list of conditions and the following disclaimer in the documentation
25 : // and/or other materials provided with the distribution.
26 : //
27 : // * The name of the copyright holders may not be used to endorse or promote products
28 : // derived from this software without specific prior written permission.
29 : //
30 : // This software is provided by the copyright holders and contributors "as is" and
31 : // any express or implied warranties, including, but not limited to, the implied
32 : // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 : // In no event shall the Intel Corporation or contributors be liable for any direct,
34 : // indirect, incidental, special, exemplary, or consequential damages
35 : // (including, but not limited to, procurement of substitute goods or services;
36 : // loss of use, data, or profits; or business interruption) however caused
37 : // and on any theory of liability, whether in contract, strict liability,
38 : // or tort (including negligence or otherwise) arising in any way out of
39 : // the use of this software, even if advised of the possibility of such damage.
40 : //
41 : //M*/
42 :
43 : #ifndef OPENCV_IMGPROC_HPP
44 : #define OPENCV_IMGPROC_HPP
45 :
46 : #include "opencv2/core.hpp"
47 :
48 : /**
49 : @defgroup imgproc Image processing
50 : @{
51 : @defgroup imgproc_filter Image Filtering
52 :
53 : Functions and classes described in this section are used to perform various linear or non-linear
54 : filtering operations on 2D images (represented as Mat's). It means that for each pixel location
55 : \f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to
56 : compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of
57 : morphological operations, it is the minimum or maximum values, and so on. The computed response is
58 : stored in the destination image at the same location \f$(x,y)\f$. It means that the output image
59 : will be of the same size as the input image. Normally, the functions support multi-channel arrays,
60 : in which case every channel is processed independently. Therefore, the output image will also have
61 : the same number of channels as the input one.
62 :
63 : Another common feature of the functions and classes described in this section is that, unlike
64 : simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For
65 : example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when
66 : processing the left-most pixels in each row, you need pixels to the left of them, that is, outside
67 : of the image. You can let these pixels be the same as the left-most image pixels ("replicated
68 : border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant
69 : border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method.
70 : For details, see cv::BorderTypes
71 :
72 : @anchor filter_depths
73 : ### Depth combinations
74 : Input depth (src.depth()) | Output depth (ddepth)
75 : --------------------------|----------------------
76 : CV_8U | -1/CV_16S/CV_32F/CV_64F
77 : CV_16U/CV_16S | -1/CV_32F/CV_64F
78 : CV_32F | -1/CV_32F/CV_64F
79 : CV_64F | -1/CV_64F
80 :
81 : @note when ddepth=-1, the output image will have the same depth as the source.
82 :
83 : @defgroup imgproc_transform Geometric Image Transformations
84 :
85 : The functions in this section perform various geometrical transformations of 2D images. They do not
86 : change the image content but deform the pixel grid and map this deformed grid to the destination
87 : image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from
88 : destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the
89 : functions compute coordinates of the corresponding "donor" pixel in the source image and copy the
90 : pixel value:
91 :
92 : \f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f]
93 :
94 : In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow
95 : \texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping
96 : \f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula.
97 :
98 : The actual implementations of the geometrical transformations, from the most generic remap and to
99 : the simplest and the fastest resize, need to solve two main problems with the above formula:
100 :
101 : - Extrapolation of non-existing pixels. Similarly to the filtering functions described in the
102 : previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both
103 : of them may fall outside of the image. In this case, an extrapolation method needs to be used.
104 : OpenCV provides the same selection of extrapolation methods as in the filtering functions. In
105 : addition, it provides the method BORDER_TRANSPARENT. This means that the corresponding pixels in
106 : the destination image will not be modified at all.
107 :
108 : - Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point
109 : numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective
110 : transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional
111 : coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the
112 : nearest integer coordinates and the corresponding pixel can be used. This is called a
113 : nearest-neighbor interpolation. However, a better result can be achieved by using more
114 : sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) ,
115 : where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y),
116 : f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ is taken as the
117 : interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See
118 : resize for details.
119 :
120 : @note The geometrical transformations do not work with `CV_8S` or `CV_32S` images.
121 :
122 : @defgroup imgproc_misc Miscellaneous Image Transformations
123 : @defgroup imgproc_draw Drawing Functions
124 :
125 : Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be
126 : rendered with antialiasing (implemented only for 8-bit images for now). All the functions include
127 : the parameter color that uses an RGB value (that may be constructed with the Scalar constructor )
128 : for color images and brightness for grayscale images. For color images, the channel ordering is
129 : normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a
130 : color using the Scalar constructor, it should look like:
131 :
132 : \f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f]
133 :
134 : If you are using your own image rendering and I/O functions, you can use any channel ordering. The
135 : drawing functions process each channel independently and do not depend on the channel order or even
136 : on the used color space. The whole image can be converted from BGR to RGB or to a different color
137 : space using cvtColor .
138 :
139 : If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also,
140 : many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means
141 : that the coordinates can be passed as fixed-point numbers encoded as integers. The number of
142 : fractional bits is specified by the shift parameter and the real point coordinates are calculated as
143 : \f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is
144 : especially effective when rendering antialiased shapes.
145 :
146 : @note The functions do not support alpha-transparency when the target image is 4-channel. In this
147 : case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint
148 : semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main
149 : image.
150 :
151 : @defgroup imgproc_colormap ColorMaps in OpenCV
152 :
153 : The human perception isn't built for observing fine changes in grayscale images. Human eyes are more
154 : sensitive to observing changes between colors, so you often need to recolor your grayscale images to
155 : get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your
156 : computer vision application.
157 :
158 : In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample
159 : code reads the path to an image from command line, applies a Jet colormap on it and shows the
160 : result:
161 :
162 : @code
163 : #include <opencv2/core.hpp>
164 : #include <opencv2/imgproc.hpp>
165 : #include <opencv2/imgcodecs.hpp>
166 : #include <opencv2/highgui.hpp>
167 : using namespace cv;
168 :
169 : #include <iostream>
170 : using namespace std;
171 :
172 : int main(int argc, const char *argv[])
173 : {
174 : // We need an input image. (can be grayscale or color)
175 : if (argc < 2)
176 : {
177 : cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl;
178 : return -1;
179 : }
180 : Mat img_in = imread(argv[1]);
181 : if(img_in.empty())
182 : {
183 : cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl;
184 : return -1;
185 : }
186 : // Holds the colormap version of the image:
187 : Mat img_color;
188 : // Apply the colormap:
189 : applyColorMap(img_in, img_color, COLORMAP_JET);
190 : // Show the result:
191 : imshow("colorMap", img_color);
192 : waitKey(0);
193 : return 0;
194 : }
195 : @endcode
196 :
197 : @see cv::ColormapTypes
198 :
199 : @defgroup imgproc_subdiv2d Planar Subdivision
200 :
201 : The Subdiv2D class described in this section is used to perform various planar subdivision on
202 : a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles
203 : using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram.
204 : In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi
205 : diagram with red lines.
206 :
207 : ![Delaunay triangulation (black) and Voronoi (red)](pics/delaunay_voronoi.png)
208 :
209 : The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast
210 : location of points on the plane, building special graphs (such as NNG,RNG), and so forth.
211 :
212 : @defgroup imgproc_hist Histograms
213 : @defgroup imgproc_shape Structural Analysis and Shape Descriptors
214 : @defgroup imgproc_motion Motion Analysis and Object Tracking
215 : @defgroup imgproc_feature Feature Detection
216 : @defgroup imgproc_object Object Detection
217 : @defgroup imgproc_c C API
218 : @defgroup imgproc_hal Hardware Acceleration Layer
219 : @{
220 : @defgroup imgproc_hal_functions Functions
221 : @defgroup imgproc_hal_interface Interface
222 : @}
223 : @}
224 : */
225 :
226 : namespace cv
227 : {
228 :
229 : /** @addtogroup imgproc
230 : @{
231 : */
232 :
233 : //! @addtogroup imgproc_filter
234 : //! @{
235 :
236 : //! type of morphological operation
237 : enum MorphTypes{
238 : MORPH_ERODE = 0, //!< see cv::erode
239 : MORPH_DILATE = 1, //!< see cv::dilate
240 : MORPH_OPEN = 2, //!< an opening operation
241 : //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f]
242 : MORPH_CLOSE = 3, //!< a closing operation
243 : //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f]
244 : MORPH_GRADIENT = 4, //!< a morphological gradient
245 : //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f]
246 : MORPH_TOPHAT = 5, //!< "top hat"
247 : //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f]
248 : MORPH_BLACKHAT = 6, //!< "black hat"
249 : //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f]
250 : MORPH_HITMISS = 7 //!< "hit or miss"
251 : //!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation
252 : };
253 :
254 : //! shape of the structuring element
255 : enum MorphShapes {
256 : MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f]
257 : MORPH_CROSS = 1, //!< a cross-shaped structuring element:
258 : //!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f]
259 : MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed
260 : //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height)
261 : };
262 :
263 : //! @} imgproc_filter
264 :
265 : //! @addtogroup imgproc_transform
266 : //! @{
267 :
268 : //! interpolation algorithm
269 : enum InterpolationFlags{
270 : /** nearest neighbor interpolation */
271 : INTER_NEAREST = 0,
272 : /** bilinear interpolation */
273 : INTER_LINEAR = 1,
274 : /** bicubic interpolation */
275 : INTER_CUBIC = 2,
276 : /** resampling using pixel area relation. It may be a preferred method for image decimation, as
277 : it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST
278 : method. */
279 : INTER_AREA = 3,
280 : /** Lanczos interpolation over 8x8 neighborhood */
281 : INTER_LANCZOS4 = 4,
282 : /** Bit exact bilinear interpolation */
283 : INTER_LINEAR_EXACT = 5,
284 : /** mask for interpolation codes */
285 : INTER_MAX = 7,
286 : /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the
287 : source image, they are set to zero */
288 : WARP_FILL_OUTLIERS = 8,
289 : /** flag, inverse transformation
290 :
291 : For example, @ref cv::linearPolar or @ref cv::logPolar transforms:
292 : - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$
293 : - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$
294 : */
295 : WARP_INVERSE_MAP = 16
296 : };
297 :
298 : enum InterpolationMasks {
299 : INTER_BITS = 5,
300 : INTER_BITS2 = INTER_BITS * 2,
301 : INTER_TAB_SIZE = 1 << INTER_BITS,
302 : INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE
303 : };
304 :
305 : //! @} imgproc_transform
306 :
307 : //! @addtogroup imgproc_misc
308 : //! @{
309 :
310 : //! Distance types for Distance Transform and M-estimators
311 : //! @see cv::distanceTransform, cv::fitLine
312 : enum DistanceTypes {
313 : DIST_USER = -1, //!< User defined distance
314 : DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2|
315 : DIST_L2 = 2, //!< the simple euclidean distance
316 : DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|)
317 : DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))
318 : DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998
319 : DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
320 : DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345
321 : };
322 :
323 : //! Mask size for distance transform
324 : enum DistanceTransformMasks {
325 : DIST_MASK_3 = 3, //!< mask=3
326 : DIST_MASK_5 = 5, //!< mask=5
327 : DIST_MASK_PRECISE = 0 //!<
328 : };
329 :
330 : //! type of the threshold operation
331 : //! ![threshold types](pics/threshold.png)
332 : enum ThresholdTypes {
333 : THRESH_BINARY = 0, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
334 : THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f]
335 : THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
336 : THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f]
337 : THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f]
338 : THRESH_MASK = 7,
339 : THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value
340 : THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value
341 : };
342 :
343 : //! adaptive threshold algorithm
344 : //! see cv::adaptiveThreshold
345 : enum AdaptiveThresholdTypes {
346 : /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times
347 : \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */
348 : ADAPTIVE_THRESH_MEAN_C = 0,
349 : /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian
350 : window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$
351 : minus C . The default sigma (standard deviation) is used for the specified blockSize . See
352 : cv::getGaussianKernel*/
353 : ADAPTIVE_THRESH_GAUSSIAN_C = 1
354 : };
355 :
356 : //! cv::undistort mode
357 : enum UndistortTypes {
358 : PROJ_SPHERICAL_ORTHO = 0,
359 : PROJ_SPHERICAL_EQRECT = 1
360 : };
361 :
362 : //! class of the pixel in GrabCut algorithm
363 : enum GrabCutClasses {
364 : GC_BGD = 0, //!< an obvious background pixels
365 : GC_FGD = 1, //!< an obvious foreground (object) pixel
366 : GC_PR_BGD = 2, //!< a possible background pixel
367 : GC_PR_FGD = 3 //!< a possible foreground pixel
368 : };
369 :
370 : //! GrabCut algorithm flags
371 : enum GrabCutModes {
372 : /** The function initializes the state and the mask using the provided rectangle. After that it
373 : runs iterCount iterations of the algorithm. */
374 : GC_INIT_WITH_RECT = 0,
375 : /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT
376 : and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are
377 : automatically initialized with GC_BGD .*/
378 : GC_INIT_WITH_MASK = 1,
379 : /** The value means that the algorithm should just resume. */
380 : GC_EVAL = 2
381 : };
382 :
383 : //! distanceTransform algorithm flags
384 : enum DistanceTransformLabelTypes {
385 : /** each connected component of zeros in src (as well as all the non-zero pixels closest to the
386 : connected component) will be assigned the same label */
387 : DIST_LABEL_CCOMP = 0,
388 : /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */
389 : DIST_LABEL_PIXEL = 1
390 : };
391 :
392 : //! floodfill algorithm flags
393 : enum FloodFillFlags {
394 : /** If set, the difference between the current pixel and seed pixel is considered. Otherwise,
395 : the difference between neighbor pixels is considered (that is, the range is floating). */
396 : FLOODFILL_FIXED_RANGE = 1 << 16,
397 : /** If set, the function does not change the image ( newVal is ignored), and only fills the
398 : mask with the value specified in bits 8-16 of flags as described above. This option only make
399 : sense in function variants that have the mask parameter. */
400 : FLOODFILL_MASK_ONLY = 1 << 17
401 : };
402 :
403 : //! @} imgproc_misc
404 :
405 : //! @addtogroup imgproc_shape
406 : //! @{
407 :
408 : //! connected components algorithm output formats
409 : enum ConnectedComponentsTypes {
410 : CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding
411 : //!< box in the horizontal direction.
412 : CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding
413 : //!< box in the vertical direction.
414 : CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box
415 : CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box
416 : CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component
417 : CC_STAT_MAX = 5
418 : };
419 :
420 : //! connected components algorithm
421 : enum ConnectedComponentsAlgorithmsTypes {
422 : CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
423 : CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
424 : CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
425 : };
426 :
427 : //! mode of the contour retrieval algorithm
428 : enum RetrievalModes {
429 : /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for
430 : all the contours. */
431 : RETR_EXTERNAL = 0,
432 : /** retrieves all of the contours without establishing any hierarchical relationships. */
433 : RETR_LIST = 1,
434 : /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top
435 : level, there are external boundaries of the components. At the second level, there are
436 : boundaries of the holes. If there is another contour inside a hole of a connected component, it
437 : is still put at the top level. */
438 : RETR_CCOMP = 2,
439 : /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/
440 : RETR_TREE = 3,
441 : RETR_FLOODFILL = 4 //!<
442 : };
443 :
444 : //! the contour approximation algorithm
445 : enum ContourApproximationModes {
446 : /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and
447 : (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is,
448 : max(abs(x1-x2),abs(y2-y1))==1. */
449 : CHAIN_APPROX_NONE = 1,
450 : /** compresses horizontal, vertical, and diagonal segments and leaves only their end points.
451 : For example, an up-right rectangular contour is encoded with 4 points. */
452 : CHAIN_APPROX_SIMPLE = 2,
453 : /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
454 : CHAIN_APPROX_TC89_L1 = 3,
455 : /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */
456 : CHAIN_APPROX_TC89_KCOS = 4
457 : };
458 :
459 : /** @brief Shape matching methods
460 :
461 : \f$A\f$ denotes object1,\f$B\f$ denotes object2
462 :
463 : \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$
464 :
465 : and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively.
466 : */
467 : enum ShapeMatchModes {
468 : 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]
469 : CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f]
470 : 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]
471 : };
472 :
473 : //! @} imgproc_shape
474 :
475 : //! Variants of a Hough transform
476 : enum HoughModes {
477 :
478 : /** classical or standard Hough transform. Every line is represented by two floating-point
479 : numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line,
480 : and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must
481 : be (the created sequence will be) of CV_32FC2 type */
482 : HOUGH_STANDARD = 0,
483 : /** probabilistic Hough transform (more efficient in case if the picture contains a few long
484 : linear segments). It returns line segments rather than the whole line. Each segment is
485 : represented by starting and ending points, and the matrix must be (the created sequence will
486 : be) of the CV_32SC4 type. */
487 : HOUGH_PROBABILISTIC = 1,
488 : /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as
489 : HOUGH_STANDARD. */
490 : HOUGH_MULTI_SCALE = 2,
491 : HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90
492 : };
493 :
494 : //! Variants of Line Segment %Detector
495 : //! @ingroup imgproc_feature
496 : enum LineSegmentDetectorModes {
497 : LSD_REFINE_NONE = 0, //!< No refinement applied
498 : LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations.
499 : LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are
500 : //!< refined through increase of precision, decrement in size, etc.
501 : };
502 :
503 : /** Histogram comparison methods
504 : @ingroup imgproc_hist
505 : */
506 : enum HistCompMethods {
507 : /** Correlation
508 : \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]
509 : where
510 : \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f]
511 : and \f$N\f$ is a total number of histogram bins. */
512 : HISTCMP_CORREL = 0,
513 : /** Chi-Square
514 : \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */
515 : HISTCMP_CHISQR = 1,
516 : /** Intersection
517 : \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */
518 : HISTCMP_INTERSECT = 2,
519 : /** Bhattacharyya distance
520 : (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.)
521 : \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] */
522 : HISTCMP_BHATTACHARYYA = 3,
523 : HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA
524 : /** Alternative Chi-Square
525 : \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]
526 : This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */
527 : HISTCMP_CHISQR_ALT = 4,
528 : /** Kullback-Leibler divergence
529 : \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */
530 : HISTCMP_KL_DIV = 5
531 : };
532 :
533 : /** the color conversion code
534 : @see @ref imgproc_color_conversions
535 : @ingroup imgproc_misc
536 : */
537 : enum ColorConversionCodes {
538 : COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image
539 : COLOR_RGB2RGBA = COLOR_BGR2BGRA,
540 :
541 : COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image
542 : COLOR_RGBA2RGB = COLOR_BGRA2BGR,
543 :
544 : COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel)
545 : COLOR_RGB2BGRA = COLOR_BGR2RGBA,
546 :
547 : COLOR_RGBA2BGR = 3,
548 : COLOR_BGRA2RGB = COLOR_RGBA2BGR,
549 :
550 : COLOR_BGR2RGB = 4,
551 : COLOR_RGB2BGR = COLOR_BGR2RGB,
552 :
553 : COLOR_BGRA2RGBA = 5,
554 : COLOR_RGBA2BGRA = COLOR_BGRA2RGBA,
555 :
556 : COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions"
557 : COLOR_RGB2GRAY = 7,
558 : COLOR_GRAY2BGR = 8,
559 : COLOR_GRAY2RGB = COLOR_GRAY2BGR,
560 : COLOR_GRAY2BGRA = 9,
561 : COLOR_GRAY2RGBA = COLOR_GRAY2BGRA,
562 : COLOR_BGRA2GRAY = 10,
563 : COLOR_RGBA2GRAY = 11,
564 :
565 : COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images)
566 : COLOR_RGB2BGR565 = 13,
567 : COLOR_BGR5652BGR = 14,
568 : COLOR_BGR5652RGB = 15,
569 : COLOR_BGRA2BGR565 = 16,
570 : COLOR_RGBA2BGR565 = 17,
571 : COLOR_BGR5652BGRA = 18,
572 : COLOR_BGR5652RGBA = 19,
573 :
574 : COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images)
575 : COLOR_BGR5652GRAY = 21,
576 :
577 : COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images)
578 : COLOR_RGB2BGR555 = 23,
579 : COLOR_BGR5552BGR = 24,
580 : COLOR_BGR5552RGB = 25,
581 : COLOR_BGRA2BGR555 = 26,
582 : COLOR_RGBA2BGR555 = 27,
583 : COLOR_BGR5552BGRA = 28,
584 : COLOR_BGR5552RGBA = 29,
585 :
586 : COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images)
587 : COLOR_BGR5552GRAY = 31,
588 :
589 : COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions"
590 : COLOR_RGB2XYZ = 33,
591 : COLOR_XYZ2BGR = 34,
592 : COLOR_XYZ2RGB = 35,
593 :
594 : COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions"
595 : COLOR_RGB2YCrCb = 37,
596 : COLOR_YCrCb2BGR = 38,
597 : COLOR_YCrCb2RGB = 39,
598 :
599 : COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
600 : COLOR_RGB2HSV = 41,
601 :
602 : COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
603 : COLOR_RGB2Lab = 45,
604 :
605 : COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
606 : COLOR_RGB2Luv = 51,
607 : COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
608 : COLOR_RGB2HLS = 53,
609 :
610 : COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
611 : COLOR_HSV2RGB = 55,
612 :
613 : COLOR_Lab2BGR = 56,
614 : COLOR_Lab2RGB = 57,
615 : COLOR_Luv2BGR = 58,
616 : COLOR_Luv2RGB = 59,
617 : COLOR_HLS2BGR = 60,
618 : COLOR_HLS2RGB = 61,
619 :
620 : COLOR_BGR2HSV_FULL = 66, //!<
621 : COLOR_RGB2HSV_FULL = 67,
622 : COLOR_BGR2HLS_FULL = 68,
623 : COLOR_RGB2HLS_FULL = 69,
624 :
625 : COLOR_HSV2BGR_FULL = 70,
626 : COLOR_HSV2RGB_FULL = 71,
627 : COLOR_HLS2BGR_FULL = 72,
628 : COLOR_HLS2RGB_FULL = 73,
629 :
630 : COLOR_LBGR2Lab = 74,
631 : COLOR_LRGB2Lab = 75,
632 : COLOR_LBGR2Luv = 76,
633 : COLOR_LRGB2Luv = 77,
634 :
635 : COLOR_Lab2LBGR = 78,
636 : COLOR_Lab2LRGB = 79,
637 : COLOR_Luv2LBGR = 80,
638 : COLOR_Luv2LRGB = 81,
639 :
640 : COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV
641 : COLOR_RGB2YUV = 83,
642 : COLOR_YUV2BGR = 84,
643 : COLOR_YUV2RGB = 85,
644 :
645 : //! YUV 4:2:0 family to RGB
646 : COLOR_YUV2RGB_NV12 = 90,
647 : COLOR_YUV2BGR_NV12 = 91,
648 : COLOR_YUV2RGB_NV21 = 92,
649 : COLOR_YUV2BGR_NV21 = 93,
650 : COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21,
651 : COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21,
652 :
653 : COLOR_YUV2RGBA_NV12 = 94,
654 : COLOR_YUV2BGRA_NV12 = 95,
655 : COLOR_YUV2RGBA_NV21 = 96,
656 : COLOR_YUV2BGRA_NV21 = 97,
657 : COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21,
658 : COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21,
659 :
660 : COLOR_YUV2RGB_YV12 = 98,
661 : COLOR_YUV2BGR_YV12 = 99,
662 : COLOR_YUV2RGB_IYUV = 100,
663 : COLOR_YUV2BGR_IYUV = 101,
664 : COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV,
665 : COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV,
666 : COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12,
667 : COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12,
668 :
669 : COLOR_YUV2RGBA_YV12 = 102,
670 : COLOR_YUV2BGRA_YV12 = 103,
671 : COLOR_YUV2RGBA_IYUV = 104,
672 : COLOR_YUV2BGRA_IYUV = 105,
673 : COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV,
674 : COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV,
675 : COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12,
676 : COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12,
677 :
678 : COLOR_YUV2GRAY_420 = 106,
679 : COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420,
680 : COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420,
681 : COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420,
682 : COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420,
683 : COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420,
684 : COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420,
685 : COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420,
686 :
687 : //! YUV 4:2:2 family to RGB
688 : COLOR_YUV2RGB_UYVY = 107,
689 : COLOR_YUV2BGR_UYVY = 108,
690 : //COLOR_YUV2RGB_VYUY = 109,
691 : //COLOR_YUV2BGR_VYUY = 110,
692 : COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY,
693 : COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY,
694 : COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY,
695 : COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY,
696 :
697 : COLOR_YUV2RGBA_UYVY = 111,
698 : COLOR_YUV2BGRA_UYVY = 112,
699 : //COLOR_YUV2RGBA_VYUY = 113,
700 : //COLOR_YUV2BGRA_VYUY = 114,
701 : COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY,
702 : COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY,
703 : COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY,
704 : COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY,
705 :
706 : COLOR_YUV2RGB_YUY2 = 115,
707 : COLOR_YUV2BGR_YUY2 = 116,
708 : COLOR_YUV2RGB_YVYU = 117,
709 : COLOR_YUV2BGR_YVYU = 118,
710 : COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2,
711 : COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2,
712 : COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2,
713 : COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2,
714 :
715 : COLOR_YUV2RGBA_YUY2 = 119,
716 : COLOR_YUV2BGRA_YUY2 = 120,
717 : COLOR_YUV2RGBA_YVYU = 121,
718 : COLOR_YUV2BGRA_YVYU = 122,
719 : COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2,
720 : COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2,
721 : COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2,
722 : COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2,
723 :
724 : COLOR_YUV2GRAY_UYVY = 123,
725 : COLOR_YUV2GRAY_YUY2 = 124,
726 : //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY,
727 : COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY,
728 : COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY,
729 : COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2,
730 : COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2,
731 : COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2,
732 :
733 : //! alpha premultiplication
734 : COLOR_RGBA2mRGBA = 125,
735 : COLOR_mRGBA2RGBA = 126,
736 :
737 : //! RGB to YUV 4:2:0 family
738 : COLOR_RGB2YUV_I420 = 127,
739 : COLOR_BGR2YUV_I420 = 128,
740 : COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420,
741 : COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420,
742 :
743 : COLOR_RGBA2YUV_I420 = 129,
744 : COLOR_BGRA2YUV_I420 = 130,
745 : COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420,
746 : COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420,
747 : COLOR_RGB2YUV_YV12 = 131,
748 : COLOR_BGR2YUV_YV12 = 132,
749 : COLOR_RGBA2YUV_YV12 = 133,
750 : COLOR_BGRA2YUV_YV12 = 134,
751 :
752 : //! Demosaicing
753 : COLOR_BayerBG2BGR = 46,
754 : COLOR_BayerGB2BGR = 47,
755 : COLOR_BayerRG2BGR = 48,
756 : COLOR_BayerGR2BGR = 49,
757 :
758 : COLOR_BayerBG2RGB = COLOR_BayerRG2BGR,
759 : COLOR_BayerGB2RGB = COLOR_BayerGR2BGR,
760 : COLOR_BayerRG2RGB = COLOR_BayerBG2BGR,
761 : COLOR_BayerGR2RGB = COLOR_BayerGB2BGR,
762 :
763 : COLOR_BayerBG2GRAY = 86,
764 : COLOR_BayerGB2GRAY = 87,
765 : COLOR_BayerRG2GRAY = 88,
766 : COLOR_BayerGR2GRAY = 89,
767 :
768 : //! Demosaicing using Variable Number of Gradients
769 : COLOR_BayerBG2BGR_VNG = 62,
770 : COLOR_BayerGB2BGR_VNG = 63,
771 : COLOR_BayerRG2BGR_VNG = 64,
772 : COLOR_BayerGR2BGR_VNG = 65,
773 :
774 : COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG,
775 : COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG,
776 : COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG,
777 : COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG,
778 :
779 : //! Edge-Aware Demosaicing
780 : COLOR_BayerBG2BGR_EA = 135,
781 : COLOR_BayerGB2BGR_EA = 136,
782 : COLOR_BayerRG2BGR_EA = 137,
783 : COLOR_BayerGR2BGR_EA = 138,
784 :
785 : COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA,
786 : COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA,
787 : COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA,
788 : COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA,
789 :
790 : //! Demosaicing with alpha channel
791 : COLOR_BayerBG2BGRA = 139,
792 : COLOR_BayerGB2BGRA = 140,
793 : COLOR_BayerRG2BGRA = 141,
794 : COLOR_BayerGR2BGRA = 142,
795 :
796 : COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA,
797 : COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA,
798 : COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA,
799 : COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA,
800 :
801 : COLOR_COLORCVT_MAX = 143
802 : };
803 :
804 : /** types of intersection between rectangles
805 : @ingroup imgproc_shape
806 : */
807 : enum RectanglesIntersectTypes {
808 : INTERSECT_NONE = 0, //!< No intersection
809 : INTERSECT_PARTIAL = 1, //!< There is a partial intersection
810 : INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other
811 : };
812 :
813 : //! finds arbitrary template in the grayscale image using Generalized Hough Transform
814 : class CV_EXPORTS GeneralizedHough : public Algorithm
815 : {
816 : public:
817 : //! set template to search
818 : virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0;
819 : virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0;
820 :
821 : //! find template on image
822 : virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0;
823 : virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0;
824 :
825 : //! Canny low threshold.
826 : virtual void setCannyLowThresh(int cannyLowThresh) = 0;
827 : virtual int getCannyLowThresh() const = 0;
828 :
829 : //! Canny high threshold.
830 : virtual void setCannyHighThresh(int cannyHighThresh) = 0;
831 : virtual int getCannyHighThresh() const = 0;
832 :
833 : //! Minimum distance between the centers of the detected objects.
834 : virtual void setMinDist(double minDist) = 0;
835 : virtual double getMinDist() const = 0;
836 :
837 : //! Inverse ratio of the accumulator resolution to the image resolution.
838 : virtual void setDp(double dp) = 0;
839 : virtual double getDp() const = 0;
840 :
841 : //! Maximal size of inner buffers.
842 : virtual void setMaxBufferSize(int maxBufferSize) = 0;
843 : virtual int getMaxBufferSize() const = 0;
844 : };
845 :
846 : //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122.
847 : //! Detects position only without translation and rotation
848 : class CV_EXPORTS GeneralizedHoughBallard : public GeneralizedHough
849 : {
850 : public:
851 : //! R-Table levels.
852 : virtual void setLevels(int levels) = 0;
853 : virtual int getLevels() const = 0;
854 :
855 : //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected.
856 : virtual void setVotesThreshold(int votesThreshold) = 0;
857 : virtual int getVotesThreshold() const = 0;
858 : };
859 :
860 : //! Guil, N., González-Linares, J.M. and Zapata, E.L. (1999). Bidimensional shape detection using an invariant approach. Pattern Recognition 32 (6): 1025-1038.
861 : //! Detects position, translation and rotation
862 : class CV_EXPORTS GeneralizedHoughGuil : public GeneralizedHough
863 : {
864 : public:
865 : //! Angle difference in degrees between two points in feature.
866 : virtual void setXi(double xi) = 0;
867 : virtual double getXi() const = 0;
868 :
869 : //! Feature table levels.
870 : virtual void setLevels(int levels) = 0;
871 : virtual int getLevels() const = 0;
872 :
873 : //! Maximal difference between angles that treated as equal.
874 : virtual void setAngleEpsilon(double angleEpsilon) = 0;
875 : virtual double getAngleEpsilon() const = 0;
876 :
877 : //! Minimal rotation angle to detect in degrees.
878 : virtual void setMinAngle(double minAngle) = 0;
879 : virtual double getMinAngle() const = 0;
880 :
881 : //! Maximal rotation angle to detect in degrees.
882 : virtual void setMaxAngle(double maxAngle) = 0;
883 : virtual double getMaxAngle() const = 0;
884 :
885 : //! Angle step in degrees.
886 : virtual void setAngleStep(double angleStep) = 0;
887 : virtual double getAngleStep() const = 0;
888 :
889 : //! Angle votes threshold.
890 : virtual void setAngleThresh(int angleThresh) = 0;
891 : virtual int getAngleThresh() const = 0;
892 :
893 : //! Minimal scale to detect.
894 : virtual void setMinScale(double minScale) = 0;
895 : virtual double getMinScale() const = 0;
896 :
897 : //! Maximal scale to detect.
898 : virtual void setMaxScale(double maxScale) = 0;
899 : virtual double getMaxScale() const = 0;
900 :
901 : //! Scale step.
902 : virtual void setScaleStep(double scaleStep) = 0;
903 : virtual double getScaleStep() const = 0;
904 :
905 : //! Scale votes threshold.
906 : virtual void setScaleThresh(int scaleThresh) = 0;
907 : virtual int getScaleThresh() const = 0;
908 :
909 : //! Position votes threshold.
910 : virtual void setPosThresh(int posThresh) = 0;
911 : virtual int getPosThresh() const = 0;
912 : };
913 :
914 :
915 : class CV_EXPORTS_W CLAHE : public Algorithm
916 : {
917 : public:
918 : CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0;
919 :
920 : CV_WRAP virtual void setClipLimit(double clipLimit) = 0;
921 : CV_WRAP virtual double getClipLimit() const = 0;
922 :
923 : CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0;
924 : CV_WRAP virtual Size getTilesGridSize() const = 0;
925 :
926 : CV_WRAP virtual void collectGarbage() = 0;
927 : };
928 :
929 :
930 : //! @addtogroup imgproc_subdiv2d
931 : //! @{
932 :
933 : class CV_EXPORTS_W Subdiv2D
934 : {
935 : public:
936 : /** Subdiv2D point location cases */
937 : enum { PTLOC_ERROR = -2, //!< Point location error
938 : PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect
939 : PTLOC_INSIDE = 0, //!< Point inside some facet
940 : PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices
941 : PTLOC_ON_EDGE = 2 //!< Point on some edge
942 : };
943 :
944 : /** Subdiv2D edge type navigation (see: getEdge()) */
945 : enum { NEXT_AROUND_ORG = 0x00,
946 : NEXT_AROUND_DST = 0x22,
947 : PREV_AROUND_ORG = 0x11,
948 : PREV_AROUND_DST = 0x33,
949 : NEXT_AROUND_LEFT = 0x13,
950 : NEXT_AROUND_RIGHT = 0x31,
951 : PREV_AROUND_LEFT = 0x20,
952 : PREV_AROUND_RIGHT = 0x02
953 : };
954 :
955 : /** creates an empty Subdiv2D object.
956 : To create a new empty Delaunay subdivision you need to use the initDelaunay() function.
957 : */
958 : CV_WRAP Subdiv2D();
959 :
960 : /** @overload
961 :
962 : @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
963 :
964 : The function creates an empty Delaunay subdivision where 2D points can be added using the function
965 : insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime
966 : error is raised.
967 : */
968 : CV_WRAP Subdiv2D(Rect rect);
969 :
970 : /** @brief Creates a new empty Delaunay subdivision
971 :
972 : @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision.
973 :
974 : */
975 : CV_WRAP void initDelaunay(Rect rect);
976 :
977 : /** @brief Insert a single point into a Delaunay triangulation.
978 :
979 : @param pt Point to insert.
980 :
981 : The function inserts a single point into a subdivision and modifies the subdivision topology
982 : appropriately. If a point with the same coordinates exists already, no new point is added.
983 : @returns the ID of the point.
984 :
985 : @note If the point is outside of the triangulation specified rect a runtime error is raised.
986 : */
987 : CV_WRAP int insert(Point2f pt);
988 :
989 : /** @brief Insert multiple points into a Delaunay triangulation.
990 :
991 : @param ptvec Points to insert.
992 :
993 : The function inserts a vector of points into a subdivision and modifies the subdivision topology
994 : appropriately.
995 : */
996 : CV_WRAP void insert(const std::vector<Point2f>& ptvec);
997 :
998 : /** @brief Returns the location of a point within a Delaunay triangulation.
999 :
1000 : @param pt Point to locate.
1001 : @param edge Output edge that the point belongs to or is located to the right of it.
1002 : @param vertex Optional output vertex the input point coincides with.
1003 :
1004 : The function locates the input point within the subdivision and gives one of the triangle edges
1005 : or vertices.
1006 :
1007 : @returns an integer which specify one of the following five cases for point location:
1008 : - The point falls into some facet. The function returns PTLOC_INSIDE and edge will contain one of
1009 : edges of the facet.
1010 : - The point falls onto the edge. The function returns PTLOC_ON_EDGE and edge will contain this edge.
1011 : - The point coincides with one of the subdivision vertices. The function returns PTLOC_VERTEX and
1012 : vertex will contain a pointer to the vertex.
1013 : - The point is outside the subdivision reference rectangle. The function returns PTLOC_OUTSIDE_RECT
1014 : and no pointers are filled.
1015 : - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error
1016 : processing mode is selected, CV_PTLOC_ERROR is returned.
1017 : */
1018 : CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex);
1019 :
1020 : /** @brief Finds the subdivision vertex closest to the given point.
1021 :
1022 : @param pt Input point.
1023 : @param nearestPt Output subdivision vertex point.
1024 :
1025 : The function is another function that locates the input point within the subdivision. It finds the
1026 : subdivision vertex that is the closest to the input point. It is not necessarily one of vertices
1027 : of the facet containing the input point, though the facet (located using locate() ) is used as a
1028 : starting point.
1029 :
1030 : @returns vertex ID.
1031 : */
1032 : CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0);
1033 :
1034 : /** @brief Returns a list of all edges.
1035 :
1036 : @param edgeList Output vector.
1037 :
1038 : The function gives each edge as a 4 numbers vector, where each two are one of the edge
1039 : vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3].
1040 : */
1041 : CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const;
1042 :
1043 : /** @brief Returns a list of the leading edge ID connected to each triangle.
1044 :
1045 : @param leadingEdgeList Output vector.
1046 :
1047 : The function gives one edge ID for each triangle.
1048 : */
1049 : CV_WRAP void getLeadingEdgeList(CV_OUT std::vector<int>& leadingEdgeList) const;
1050 :
1051 : /** @brief Returns a list of all triangles.
1052 :
1053 : @param triangleList Output vector.
1054 :
1055 : The function gives each triangle as a 6 numbers vector, where each two are one of the triangle
1056 : 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].
1057 : */
1058 : CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const;
1059 :
1060 : /** @brief Returns a list of all Voroni facets.
1061 :
1062 : @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector.
1063 : @param facetList Output vector of the Voroni facets.
1064 : @param facetCenters Output vector of the Voroni facets center points.
1065 :
1066 : */
1067 : CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList,
1068 : CV_OUT std::vector<Point2f>& facetCenters);
1069 :
1070 : /** @brief Returns vertex location from vertex ID.
1071 :
1072 : @param vertex vertex ID.
1073 : @param firstEdge Optional. The first edge ID which is connected to the vertex.
1074 : @returns vertex (x,y)
1075 :
1076 : */
1077 : CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const;
1078 :
1079 : /** @brief Returns one of the edges related to the given edge.
1080 :
1081 : @param edge Subdivision edge ID.
1082 : @param nextEdgeType Parameter specifying which of the related edges to return.
1083 : The following values are possible:
1084 : - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge)
1085 : - NEXT_AROUND_DST next around the edge vertex ( eDnext )
1086 : - PREV_AROUND_ORG previous around the edge origin (reversed eRnext )
1087 : - PREV_AROUND_DST previous around the edge destination (reversed eLnext )
1088 : - NEXT_AROUND_LEFT next around the left facet ( eLnext )
1089 : - NEXT_AROUND_RIGHT next around the right facet ( eRnext )
1090 : - PREV_AROUND_LEFT previous around the left facet (reversed eOnext )
1091 : - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext )
1092 :
1093 : ![sample output](pics/quadedge.png)
1094 :
1095 : @returns edge ID related to the input edge.
1096 : */
1097 : CV_WRAP int getEdge( int edge, int nextEdgeType ) const;
1098 :
1099 : /** @brief Returns next edge around the edge origin.
1100 :
1101 : @param edge Subdivision edge ID.
1102 :
1103 : @returns an integer which is next edge ID around the edge origin: eOnext on the
1104 : picture above if e is the input edge).
1105 : */
1106 : CV_WRAP int nextEdge(int edge) const;
1107 :
1108 : /** @brief Returns another edge of the same quad-edge.
1109 :
1110 : @param edge Subdivision edge ID.
1111 : @param rotate Parameter specifying which of the edges of the same quad-edge as the input
1112 : one to return. The following values are possible:
1113 : - 0 - the input edge ( e on the picture below if e is the input edge)
1114 : - 1 - the rotated edge ( eRot )
1115 : - 2 - the reversed edge (reversed e (in green))
1116 : - 3 - the reversed rotated edge (reversed eRot (in green))
1117 :
1118 : @returns one of the edges ID of the same quad-edge as the input edge.
1119 : */
1120 : CV_WRAP int rotateEdge(int edge, int rotate) const;
1121 : CV_WRAP int symEdge(int edge) const;
1122 :
1123 : /** @brief Returns the edge origin.
1124 :
1125 : @param edge Subdivision edge ID.
1126 : @param orgpt Output vertex location.
1127 :
1128 : @returns vertex ID.
1129 : */
1130 : CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const;
1131 :
1132 : /** @brief Returns the edge destination.
1133 :
1134 : @param edge Subdivision edge ID.
1135 : @param dstpt Output vertex location.
1136 :
1137 : @returns vertex ID.
1138 : */
1139 : CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const;
1140 :
1141 : protected:
1142 : int newEdge();
1143 : void deleteEdge(int edge);
1144 : int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0);
1145 : void deletePoint(int vtx);
1146 : void setEdgePoints( int edge, int orgPt, int dstPt );
1147 : void splice( int edgeA, int edgeB );
1148 : int connectEdges( int edgeA, int edgeB );
1149 : void swapEdges( int edge );
1150 : int isRightOf(Point2f pt, int edge) const;
1151 : void calcVoronoi();
1152 : void clearVoronoi();
1153 : void checkSubdiv() const;
1154 :
1155 : struct CV_EXPORTS Vertex
1156 : {
1157 : Vertex();
1158 : Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0);
1159 : bool isvirtual() const;
1160 : bool isfree() const;
1161 :
1162 : int firstEdge;
1163 : int type;
1164 : Point2f pt;
1165 : };
1166 :
1167 : struct CV_EXPORTS QuadEdge
1168 : {
1169 : QuadEdge();
1170 : QuadEdge(int edgeidx);
1171 : bool isfree() const;
1172 :
1173 : int next[4];
1174 : int pt[4];
1175 : };
1176 :
1177 : //! All of the vertices
1178 : std::vector<Vertex> vtx;
1179 : //! All of the edges
1180 : std::vector<QuadEdge> qedges;
1181 : int freeQEdge;
1182 : int freePoint;
1183 : bool validGeometry;
1184 :
1185 : int recentEdge;
1186 : //! Top left corner of the bounding rect
1187 : Point2f topLeft;
1188 : //! Bottom right corner of the bounding rect
1189 : Point2f bottomRight;
1190 : };
1191 :
1192 : //! @} imgproc_subdiv2d
1193 :
1194 : //! @addtogroup imgproc_feature
1195 : //! @{
1196 :
1197 : /** @example lsd_lines.cpp
1198 : An example using the LineSegmentDetector
1199 : \image html building_lsd.png "Sample output image" width=434 height=300
1200 : */
1201 :
1202 : /** @brief Line segment detector class
1203 :
1204 : following the algorithm described at @cite Rafael12 .
1205 : */
1206 : class CV_EXPORTS_W LineSegmentDetector : public Algorithm
1207 : {
1208 : public:
1209 :
1210 : /** @brief Finds lines in the input image.
1211 :
1212 : This is the output of the default parameters of the algorithm on the above shown image.
1213 :
1214 : ![image](pics/building_lsd.png)
1215 :
1216 : @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use:
1217 : `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
1218 : @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where
1219 : Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly
1220 : oriented depending on the gradient.
1221 : @param width Vector of widths of the regions, where the lines are found. E.g. Width of line.
1222 : @param prec Vector of precisions with which the lines are found.
1223 : @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The
1224 : bigger the value, logarithmically better the detection.
1225 : - -1 corresponds to 10 mean false alarms
1226 : - 0 corresponds to 1 mean false alarm
1227 : - 1 corresponds to 0.1 mean false alarms
1228 : This vector will be calculated only when the objects type is LSD_REFINE_ADV.
1229 : */
1230 : CV_WRAP virtual void detect(InputArray _image, OutputArray _lines,
1231 : OutputArray width = noArray(), OutputArray prec = noArray(),
1232 : OutputArray nfa = noArray()) = 0;
1233 :
1234 : /** @brief Draws the line segments on a given image.
1235 : @param _image The image, where the lines will be drawn. Should be bigger or equal to the image,
1236 : where the lines were found.
1237 : @param lines A vector of the lines that needed to be drawn.
1238 : */
1239 : CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0;
1240 :
1241 : /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels.
1242 :
1243 : @param size The size of the image, where lines1 and lines2 were found.
1244 : @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color.
1245 : @param lines2 The second group of lines. They visualized in red color.
1246 : @param _image Optional image, where the lines will be drawn. The image should be color(3-channel)
1247 : in order for lines1 and lines2 to be drawn in the above mentioned colors.
1248 : */
1249 : CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0;
1250 :
1251 : virtual ~LineSegmentDetector() { }
1252 : };
1253 :
1254 : /** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it.
1255 :
1256 : The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want
1257 : to edit those, as to tailor it for their own application.
1258 :
1259 : @param _refine The way found lines will be refined, see cv::LineSegmentDetectorModes
1260 : @param _scale The scale of the image that will be used to find the lines. Range (0..1].
1261 : @param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale.
1262 : @param _quant Bound to the quantization error on the gradient norm.
1263 : @param _ang_th Gradient angle tolerance in degrees.
1264 : @param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement
1265 : is chosen.
1266 : @param _density_th Minimal density of aligned region points in the enclosing rectangle.
1267 : @param _n_bins Number of bins in pseudo-ordering of gradient modulus.
1268 : */
1269 : CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(
1270 : int _refine = LSD_REFINE_STD, double _scale = 0.8,
1271 : double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5,
1272 : double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024);
1273 :
1274 : //! @} imgproc_feature
1275 :
1276 : //! @addtogroup imgproc_filter
1277 : //! @{
1278 :
1279 : /** @brief Returns Gaussian filter coefficients.
1280 :
1281 : The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter
1282 : coefficients:
1283 :
1284 : \f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f]
1285 :
1286 : 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$.
1287 :
1288 : Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize
1289 : smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly.
1290 : You may also use the higher-level GaussianBlur.
1291 : @param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive.
1292 : @param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as
1293 : `sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`.
1294 : @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
1295 : @sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur
1296 : */
1297 : CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F );
1298 :
1299 : /** @brief Returns filter coefficients for computing spatial image derivatives.
1300 :
1301 : The function computes and returns the filter coefficients for spatial image derivatives. When
1302 : `ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see cv::Scharr). Otherwise, Sobel
1303 : kernels are generated (see cv::Sobel). The filters are normally passed to sepFilter2D or to
1304 :
1305 : @param kx Output matrix of row filter coefficients. It has the type ktype .
1306 : @param ky Output matrix of column filter coefficients. It has the type ktype .
1307 : @param dx Derivative order in respect of x.
1308 : @param dy Derivative order in respect of y.
1309 : @param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7.
1310 : @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not.
1311 : Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are
1312 : going to filter floating-point images, you are likely to use the normalized kernels. But if you
1313 : compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve
1314 : all the fractional bits, you may want to set normalize=false .
1315 : @param ktype Type of filter coefficients. It can be CV_32f or CV_64F .
1316 : */
1317 : CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky,
1318 : int dx, int dy, int ksize,
1319 : bool normalize = false, int ktype = CV_32F );
1320 :
1321 : /** @brief Returns Gabor filter coefficients.
1322 :
1323 : For more details about gabor filter equations and parameters, see: [Gabor
1324 : Filter](http://en.wikipedia.org/wiki/Gabor_filter).
1325 :
1326 : @param ksize Size of the filter returned.
1327 : @param sigma Standard deviation of the gaussian envelope.
1328 : @param theta Orientation of the normal to the parallel stripes of a Gabor function.
1329 : @param lambd Wavelength of the sinusoidal factor.
1330 : @param gamma Spatial aspect ratio.
1331 : @param psi Phase offset.
1332 : @param ktype Type of filter coefficients. It can be CV_32F or CV_64F .
1333 : */
1334 : CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd,
1335 : double gamma, double psi = CV_PI*0.5, int ktype = CV_64F );
1336 :
1337 : //! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
1338 3 : static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); }
1339 :
1340 : /** @brief Returns a structuring element of the specified size and shape for morphological operations.
1341 :
1342 : The function constructs and returns the structuring element that can be further passed to cv::erode,
1343 : cv::dilate or cv::morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as
1344 : the structuring element.
1345 :
1346 : @param shape Element shape that could be one of cv::MorphShapes
1347 : @param ksize Size of the structuring element.
1348 : @param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the
1349 : anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor
1350 : position. In other cases the anchor just regulates how much the result of the morphological
1351 : operation is shifted.
1352 : */
1353 : CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1));
1354 :
1355 : /** @example Smoothing.cpp
1356 : Sample code for simple filters
1357 : ![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg)
1358 : Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details
1359 : */
1360 : /** @brief Blurs an image using the median filter.
1361 :
1362 : The function smoothes an image using the median filter with the \f$\texttt{ksize} \times
1363 : \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently.
1364 : In-place operation is supported.
1365 :
1366 : @note The median filter uses BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes
1367 :
1368 : @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be
1369 : CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.
1370 : @param dst destination array of the same size and type as src.
1371 : @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
1372 : @sa bilateralFilter, blur, boxFilter, GaussianBlur
1373 : */
1374 : CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize );
1375 :
1376 : /** @brief Blurs an image using a Gaussian filter.
1377 :
1378 : The function convolves the source image with the specified Gaussian kernel. In-place filtering is
1379 : supported.
1380 :
1381 : @param src input image; the image can have any number of channels, which are processed
1382 : independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
1383 : @param dst output image of the same size and type as src.
1384 : @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
1385 : positive and odd. Or, they can be zero's and then they are computed from sigma.
1386 : @param sigmaX Gaussian kernel standard deviation in X direction.
1387 : @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
1388 : equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
1389 : respectively (see cv::getGaussianKernel for details); to fully control the result regardless of
1390 : possible future modifications of all this semantics, it is recommended to specify all of ksize,
1391 : sigmaX, and sigmaY.
1392 : @param borderType pixel extrapolation method, see cv::BorderTypes
1393 :
1394 : @sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur
1395 : */
1396 : CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize,
1397 : double sigmaX, double sigmaY = 0,
1398 : int borderType = BORDER_DEFAULT );
1399 :
1400 : /** @brief Applies the bilateral filter to an image.
1401 :
1402 : The function applies bilateral filtering to the input image, as described in
1403 : http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
1404 : bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
1405 : very slow compared to most filters.
1406 :
1407 : _Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<
1408 : 10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very
1409 : strong effect, making the image look "cartoonish".
1410 :
1411 : _Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time
1412 : applications, and perhaps d=9 for offline applications that need heavy noise filtering.
1413 :
1414 : This filter does not work inplace.
1415 : @param src Source 8-bit or floating-point, 1-channel or 3-channel image.
1416 : @param dst Destination image of the same size and type as src .
1417 : @param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
1418 : it is computed from sigmaSpace.
1419 : @param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
1420 : farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
1421 : in larger areas of semi-equal color.
1422 : @param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that
1423 : farther pixels will influence each other as long as their colors are close enough (see sigmaColor
1424 : ). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
1425 : proportional to sigmaSpace.
1426 : @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
1427 : */
1428 : CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,
1429 : double sigmaColor, double sigmaSpace,
1430 : int borderType = BORDER_DEFAULT );
1431 :
1432 : /** @brief Blurs an image using the box filter.
1433 :
1434 : The function smooths an image using the kernel:
1435 :
1436 : \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]
1437 :
1438 : where
1439 :
1440 : \f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f]
1441 :
1442 : Unnormalized box filter is useful for computing various integral characteristics over each pixel
1443 : neighborhood, such as covariance matrices of image derivatives (used in dense optical flow
1444 : algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral.
1445 :
1446 : @param src input image.
1447 : @param dst output image of the same size and type as src.
1448 : @param ddepth the output image depth (-1 to use src.depth()).
1449 : @param ksize blurring kernel size.
1450 : @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
1451 : center.
1452 : @param normalize flag, specifying whether the kernel is normalized by its area or not.
1453 : @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
1454 : @sa blur, bilateralFilter, GaussianBlur, medianBlur, integral
1455 : */
1456 : CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth,
1457 : Size ksize, Point anchor = Point(-1,-1),
1458 : bool normalize = true,
1459 : int borderType = BORDER_DEFAULT );
1460 :
1461 : /** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter.
1462 :
1463 : For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring
1464 : pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$.
1465 :
1466 : The unnormalized square box filter can be useful in computing local image statistics such as the the local
1467 : variance and standard deviation around the neighborhood of a pixel.
1468 :
1469 : @param _src input image
1470 : @param _dst output image of the same size and type as _src
1471 : @param ddepth the output image depth (-1 to use src.depth())
1472 : @param ksize kernel size
1473 : @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel
1474 : center.
1475 : @param normalize flag, specifying whether the kernel is to be normalized by it's area or not.
1476 : @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
1477 : @sa boxFilter
1478 : */
1479 : CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth,
1480 : Size ksize, Point anchor = Point(-1, -1),
1481 : bool normalize = true,
1482 : int borderType = BORDER_DEFAULT );
1483 :
1484 : /** @brief Blurs an image using the normalized box filter.
1485 :
1486 : The function smooths an image using the kernel:
1487 :
1488 : \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]
1489 :
1490 : The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(),
1491 : anchor, true, borderType)`.
1492 :
1493 : @param src input image; it can have any number of channels, which are processed independently, but
1494 : the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
1495 : @param dst output image of the same size and type as src.
1496 : @param ksize blurring kernel size.
1497 : @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
1498 : center.
1499 : @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
1500 : @sa boxFilter, bilateralFilter, GaussianBlur, medianBlur
1501 : */
1502 : CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
1503 : Size ksize, Point anchor = Point(-1,-1),
1504 : int borderType = BORDER_DEFAULT );
1505 :
1506 : /** @brief Convolves an image with the kernel.
1507 :
1508 : The function applies an arbitrary linear filter to an image. In-place operation is supported. When
1509 : the aperture is partially outside the image, the function interpolates outlier pixel values
1510 : according to the specified border mode.
1511 :
1512 : The function does actually compute correlation, not the convolution:
1513 :
1514 : \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]
1515 :
1516 : That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip
1517 : the kernel using cv::flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows -
1518 : anchor.y - 1)`.
1519 :
1520 : The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or
1521 : larger) and the direct algorithm for small kernels.
1522 :
1523 : @param src input image.
1524 : @param dst output image of the same size and the same number of channels as src.
1525 : @param ddepth desired depth of the destination image, see @ref filter_depths "combinations"
1526 : @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point
1527 : matrix; if you want to apply different kernels to different channels, split the image into
1528 : separate color planes using split and process them individually.
1529 : @param anchor anchor of the kernel that indicates the relative position of a filtered point within
1530 : the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor
1531 : is at the kernel center.
1532 : @param delta optional value added to the filtered pixels before storing them in dst.
1533 : @param borderType pixel extrapolation method, see cv::BorderTypes
1534 : @sa sepFilter2D, dft, matchTemplate
1535 : */
1536 : CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth,
1537 : InputArray kernel, Point anchor = Point(-1,-1),
1538 : double delta = 0, int borderType = BORDER_DEFAULT );
1539 :
1540 : /** @brief Applies a separable linear filter to an image.
1541 :
1542 : The function applies a separable linear filter to the image. That is, first, every row of src is
1543 : filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D
1544 : kernel kernelY. The final result shifted by delta is stored in dst .
1545 :
1546 : @param src Source image.
1547 : @param dst Destination image of the same size and the same number of channels as src .
1548 : @param ddepth Destination image depth, see @ref filter_depths "combinations"
1549 : @param kernelX Coefficients for filtering each row.
1550 : @param kernelY Coefficients for filtering each column.
1551 : @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor
1552 : is at the kernel center.
1553 : @param delta Value added to the filtered results before storing them.
1554 : @param borderType Pixel extrapolation method, see cv::BorderTypes
1555 : @sa filter2D, Sobel, GaussianBlur, boxFilter, blur
1556 : */
1557 : CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth,
1558 : InputArray kernelX, InputArray kernelY,
1559 : Point anchor = Point(-1,-1),
1560 : double delta = 0, int borderType = BORDER_DEFAULT );
1561 :
1562 : /** @example Sobel_Demo.cpp
1563 : Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector
1564 : ![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg)
1565 : Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details
1566 : */
1567 : /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
1568 :
1569 : In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to
1570 : calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$
1571 : kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first
1572 : or the second x- or y- derivatives.
1573 :
1574 : There is also the special value `ksize = CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr
1575 : filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is
1576 :
1577 : \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]
1578 :
1579 : for the x-derivative, or transposed for the y-derivative.
1580 :
1581 : The function calculates an image derivative by convolving the image with the appropriate kernel:
1582 :
1583 : \f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]
1584 :
1585 : The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less
1586 : resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)
1587 : or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first
1588 : case corresponds to a kernel of:
1589 :
1590 : \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]
1591 :
1592 : The second case corresponds to a kernel of:
1593 :
1594 : \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]
1595 :
1596 : @param src input image.
1597 : @param dst output image of the same size and the same number of channels as src .
1598 : @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
1599 : 8-bit input images it will result in truncated derivatives.
1600 : @param dx order of the derivative x.
1601 : @param dy order of the derivative y.
1602 : @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
1603 : @param scale optional scale factor for the computed derivative values; by default, no scaling is
1604 : applied (see cv::getDerivKernels for details).
1605 : @param delta optional delta value that is added to the results prior to storing them in dst.
1606 : @param borderType pixel extrapolation method, see cv::BorderTypes
1607 : @sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar
1608 : */
1609 : CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth,
1610 : int dx, int dy, int ksize = 3,
1611 : double scale = 1, double delta = 0,
1612 : int borderType = BORDER_DEFAULT );
1613 :
1614 : /** @brief Calculates the first order image derivative in both x and y using a Sobel operator
1615 :
1616 : Equivalent to calling:
1617 :
1618 : @code
1619 : Sobel( src, dx, CV_16SC1, 1, 0, 3 );
1620 : Sobel( src, dy, CV_16SC1, 0, 1, 3 );
1621 : @endcode
1622 :
1623 : @param src input image.
1624 : @param dx output image with first-order derivative in x.
1625 : @param dy output image with first-order derivative in y.
1626 : @param ksize size of Sobel kernel. It must be 3.
1627 : @param borderType pixel extrapolation method, see cv::BorderTypes
1628 :
1629 : @sa Sobel
1630 : */
1631 :
1632 : CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx,
1633 : OutputArray dy, int ksize = 3,
1634 : int borderType = BORDER_DEFAULT );
1635 :
1636 : /** @brief Calculates the first x- or y- image derivative using Scharr operator.
1637 :
1638 : The function computes the first x- or y- spatial image derivative using the Scharr operator. The
1639 : call
1640 :
1641 : \f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f]
1642 :
1643 : is equivalent to
1644 :
1645 : \f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV\_SCHARR, scale, delta, borderType)} .\f]
1646 :
1647 : @param src input image.
1648 : @param dst output image of the same size and the same number of channels as src.
1649 : @param ddepth output image depth, see @ref filter_depths "combinations"
1650 : @param dx order of the derivative x.
1651 : @param dy order of the derivative y.
1652 : @param scale optional scale factor for the computed derivative values; by default, no scaling is
1653 : applied (see getDerivKernels for details).
1654 : @param delta optional delta value that is added to the results prior to storing them in dst.
1655 : @param borderType pixel extrapolation method, see cv::BorderTypes
1656 : @sa cartToPolar
1657 : */
1658 : CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth,
1659 : int dx, int dy, double scale = 1, double delta = 0,
1660 : int borderType = BORDER_DEFAULT );
1661 :
1662 : /** @example laplace.cpp
1663 : An example using Laplace transformations for edge detection
1664 : */
1665 :
1666 : /** @brief Calculates the Laplacian of an image.
1667 :
1668 : The function calculates the Laplacian of the source image by adding up the second x and y
1669 : derivatives calculated using the Sobel operator:
1670 :
1671 : \f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f]
1672 :
1673 : This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image
1674 : with the following \f$3 \times 3\f$ aperture:
1675 :
1676 : \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]
1677 :
1678 : @param src Source image.
1679 : @param dst Destination image of the same size and the same number of channels as src .
1680 : @param ddepth Desired depth of the destination image.
1681 : @param ksize Aperture size used to compute the second-derivative filters. See getDerivKernels for
1682 : details. The size must be positive and odd.
1683 : @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
1684 : applied. See getDerivKernels for details.
1685 : @param delta Optional delta value that is added to the results prior to storing them in dst .
1686 : @param borderType Pixel extrapolation method, see cv::BorderTypes
1687 : @sa Sobel, Scharr
1688 : */
1689 : CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth,
1690 : int ksize = 1, double scale = 1, double delta = 0,
1691 : int borderType = BORDER_DEFAULT );
1692 :
1693 : //! @} imgproc_filter
1694 :
1695 : //! @addtogroup imgproc_feature
1696 : //! @{
1697 :
1698 : /** @example edge.cpp
1699 : This program demonstrates usage of the Canny edge detector
1700 :
1701 : Check @ref tutorial_canny_detector "the corresponding tutorial" for more details
1702 : */
1703 :
1704 : /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 .
1705 :
1706 : The function finds edges in the input image and marks them in the output map edges using the
1707 : Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The
1708 : largest value is used to find initial segments of strong edges. See
1709 : <http://en.wikipedia.org/wiki/Canny_edge_detector>
1710 :
1711 : @param image 8-bit input image.
1712 : @param edges output edge map; single channels 8-bit image, which has the same size as image .
1713 : @param threshold1 first threshold for the hysteresis procedure.
1714 : @param threshold2 second threshold for the hysteresis procedure.
1715 : @param apertureSize aperture size for the Sobel operator.
1716 : @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
1717 : \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
1718 : L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
1719 : L2gradient=false ).
1720 : */
1721 : CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
1722 : double threshold1, double threshold2,
1723 : int apertureSize = 3, bool L2gradient = false );
1724 :
1725 : /** \overload
1726 :
1727 : Finds edges in an image using the Canny algorithm with custom image gradient.
1728 :
1729 : @param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3).
1730 : @param dy 16-bit y derivative of input image (same type as dx).
1731 : @param edges,threshold1,threshold2,L2gradient See cv::Canny
1732 : */
1733 : CV_EXPORTS_W void Canny( InputArray dx, InputArray dy,
1734 : OutputArray edges,
1735 : double threshold1, double threshold2,
1736 : bool L2gradient = false );
1737 :
1738 : /** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection.
1739 :
1740 : The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal
1741 : eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms
1742 : of the formulae in the cornerEigenValsAndVecs description.
1743 :
1744 : @param src Input single-channel 8-bit or floating-point image.
1745 : @param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as
1746 : src .
1747 : @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ).
1748 : @param ksize Aperture parameter for the Sobel operator.
1749 : @param borderType Pixel extrapolation method. See cv::BorderTypes.
1750 : */
1751 : CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst,
1752 : int blockSize, int ksize = 3,
1753 : int borderType = BORDER_DEFAULT );
1754 :
1755 : /** @brief Harris corner detector.
1756 :
1757 : The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and
1758 : cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance
1759 : matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it
1760 : computes the following characteristic:
1761 :
1762 : \f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f]
1763 :
1764 : Corners in the image can be found as the local maxima of this response map.
1765 :
1766 : @param src Input single-channel 8-bit or floating-point image.
1767 : @param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same
1768 : size as src .
1769 : @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ).
1770 : @param ksize Aperture parameter for the Sobel operator.
1771 : @param k Harris detector free parameter. See the formula below.
1772 : @param borderType Pixel extrapolation method. See cv::BorderTypes.
1773 : */
1774 : CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,
1775 : int ksize, double k,
1776 : int borderType = BORDER_DEFAULT );
1777 :
1778 : /** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection.
1779 :
1780 : For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize
1781 : neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as:
1782 :
1783 : \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]
1784 :
1785 : where the derivatives are computed using the Sobel operator.
1786 :
1787 : After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as
1788 : \f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where
1789 :
1790 : - \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$
1791 : - \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$
1792 : - \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$
1793 :
1794 : The output of the function can be used for robust edge or corner detection.
1795 :
1796 : @param src Input single-channel 8-bit or floating-point image.
1797 : @param dst Image to store the results. It has the same size as src and the type CV_32FC(6) .
1798 : @param blockSize Neighborhood size (see details below).
1799 : @param ksize Aperture parameter for the Sobel operator.
1800 : @param borderType Pixel extrapolation method. See cv::BorderTypes.
1801 :
1802 : @sa cornerMinEigenVal, cornerHarris, preCornerDetect
1803 : */
1804 : CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst,
1805 : int blockSize, int ksize,
1806 : int borderType = BORDER_DEFAULT );
1807 :
1808 : /** @brief Calculates a feature map for corner detection.
1809 :
1810 : The function calculates the complex spatial derivative-based function of the source image
1811 :
1812 : \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]
1813 :
1814 : 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
1815 : derivatives, and \f$D_{xy}\f$ is the mixed derivative.
1816 :
1817 : The corners can be found as local maximums of the functions, as shown below:
1818 : @code
1819 : Mat corners, dilated_corners;
1820 : preCornerDetect(image, corners, 3);
1821 : // dilation with 3x3 rectangular structuring element
1822 : dilate(corners, dilated_corners, Mat(), 1);
1823 : Mat corner_mask = corners == dilated_corners;
1824 : @endcode
1825 :
1826 : @param src Source single-channel 8-bit of floating-point image.
1827 : @param dst Output image that has the type CV_32F and the same size as src .
1828 : @param ksize %Aperture size of the Sobel .
1829 : @param borderType Pixel extrapolation method. See cv::BorderTypes.
1830 : */
1831 : CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize,
1832 : int borderType = BORDER_DEFAULT );
1833 :
1834 : /** @brief Refines the corner locations.
1835 :
1836 : The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as
1837 : shown on the figure below.
1838 :
1839 : ![image](pics/cornersubpix.png)
1840 :
1841 : Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$
1842 : to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$
1843 : subject to image and measurement noise. Consider the expression:
1844 :
1845 : \f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f]
1846 :
1847 : 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
1848 : 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
1849 : with \f$\epsilon_i\f$ set to zero:
1850 :
1851 : \f[\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)\f]
1852 :
1853 : where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first
1854 : gradient term \f$G\f$ and the second gradient term \f$b\f$ gives:
1855 :
1856 : \f[q = G^{-1} \cdot b\f]
1857 :
1858 : The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates
1859 : until the center stays within a set threshold.
1860 :
1861 : @param image Input image.
1862 : @param corners Initial coordinates of the input corners and refined coordinates provided for
1863 : output.
1864 : @param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) ,
1865 : then a \f$5*2+1 \times 5*2+1 = 11 \times 11\f$ search window is used.
1866 : @param zeroZone Half of the size of the dead region in the middle of the search zone over which
1867 : the summation in the formula below is not done. It is used sometimes to avoid possible
1868 : singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such
1869 : a size.
1870 : @param criteria Criteria for termination of the iterative process of corner refinement. That is,
1871 : the process of corner position refinement stops either after criteria.maxCount iterations or when
1872 : the corner position moves by less than criteria.epsilon on some iteration.
1873 : */
1874 : CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners,
1875 : Size winSize, Size zeroZone,
1876 : TermCriteria criteria );
1877 :
1878 : /** @brief Determines strong corners on an image.
1879 :
1880 : The function finds the most prominent corners in the image or in the specified image region, as
1881 : described in @cite Shi94
1882 :
1883 : - Function calculates the corner quality measure at every source image pixel using the
1884 : cornerMinEigenVal or cornerHarris .
1885 : - Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are
1886 : retained).
1887 : - The corners with the minimal eigenvalue less than
1888 : \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.
1889 : - The remaining corners are sorted by the quality measure in the descending order.
1890 : - Function throws away each corner for which there is a stronger corner at a distance less than
1891 : maxDistance.
1892 :
1893 : The function can be used to initialize a point-based tracker of an object.
1894 :
1895 : @note If the function is called with different values A and B of the parameter qualityLevel , and
1896 : A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector
1897 : with qualityLevel=B .
1898 :
1899 : @param image Input 8-bit or floating-point 32-bit, single-channel image.
1900 : @param corners Output vector of detected corners.
1901 : @param maxCorners Maximum number of corners to return. If there are more corners than are found,
1902 : the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
1903 : and all detected corners are returned.
1904 : @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
1905 : parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
1906 : (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the
1907 : quality measure less than the product are rejected. For example, if the best corner has the
1908 : quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
1909 : less than 15 are rejected.
1910 : @param minDistance Minimum possible Euclidean distance between the returned corners.
1911 : @param mask Optional region of interest. If the image is not empty (it needs to have the type
1912 : CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
1913 : @param blockSize Size of an average block for computing a derivative covariation matrix over each
1914 : pixel neighborhood. See cornerEigenValsAndVecs .
1915 : @param useHarrisDetector Parameter indicating whether to use a Harris detector (see cornerHarris)
1916 : or cornerMinEigenVal.
1917 : @param k Free parameter of the Harris detector.
1918 :
1919 : @sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,
1920 : */
1921 :
1922 : CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
1923 : int maxCorners, double qualityLevel, double minDistance,
1924 : InputArray mask = noArray(), int blockSize = 3,
1925 : bool useHarrisDetector = false, double k = 0.04 );
1926 :
1927 : CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
1928 : int maxCorners, double qualityLevel, double minDistance,
1929 : InputArray mask, int blockSize,
1930 : int gradientSize, bool useHarrisDetector = false,
1931 : double k = 0.04 );
1932 : /** @example houghlines.cpp
1933 : An example using the Hough line detector
1934 : ![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg)
1935 : */
1936 :
1937 : /** @brief Finds lines in a binary image using the standard Hough transform.
1938 :
1939 : The function implements the standard or standard multi-scale Hough transform algorithm for line
1940 : detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough
1941 : transform.
1942 :
1943 : @param image 8-bit, single-channel binary source image. The image may be modified by the function.
1944 : @param lines Output vector of lines. Each line is represented by a two-element vector
1945 : \f$(\rho, \theta)\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of
1946 : the image). \f$\theta\f$ is the line rotation angle in radians (
1947 : \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).
1948 : @param rho Distance resolution of the accumulator in pixels.
1949 : @param theta Angle resolution of the accumulator in radians.
1950 : @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
1951 : votes ( \f$>\texttt{threshold}\f$ ).
1952 : @param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho .
1953 : The coarse accumulator distance resolution is rho and the accurate accumulator resolution is
1954 : rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these
1955 : parameters should be positive.
1956 : @param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.
1957 : @param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines.
1958 : Must fall between 0 and max_theta.
1959 : @param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines.
1960 : Must fall between min_theta and CV_PI.
1961 : */
1962 : CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines,
1963 : double rho, double theta, int threshold,
1964 : double srn = 0, double stn = 0,
1965 : double min_theta = 0, double max_theta = CV_PI );
1966 :
1967 : /** @brief Finds line segments in a binary image using the probabilistic Hough transform.
1968 :
1969 : The function implements the probabilistic Hough transform algorithm for line detection, described
1970 : in @cite Matas00
1971 :
1972 : See the line detection example below:
1973 :
1974 : @code
1975 : #include <opencv2/imgproc.hpp>
1976 : #include <opencv2/highgui.hpp>
1977 :
1978 : using namespace cv;
1979 : using namespace std;
1980 :
1981 : int main(int argc, char** argv)
1982 : {
1983 : Mat src, dst, color_dst;
1984 : if( argc != 2 || !(src=imread(argv[1], 0)).data)
1985 : return -1;
1986 :
1987 : Canny( src, dst, 50, 200, 3 );
1988 : cvtColor( dst, color_dst, COLOR_GRAY2BGR );
1989 :
1990 : #if 0
1991 : vector<Vec2f> lines;
1992 : HoughLines( dst, lines, 1, CV_PI/180, 100 );
1993 :
1994 : for( size_t i = 0; i < lines.size(); i++ )
1995 : {
1996 : float rho = lines[i][0];
1997 : float theta = lines[i][1];
1998 : double a = cos(theta), b = sin(theta);
1999 : double x0 = a*rho, y0 = b*rho;
2000 : Point pt1(cvRound(x0 + 1000*(-b)),
2001 : cvRound(y0 + 1000*(a)));
2002 : Point pt2(cvRound(x0 - 1000*(-b)),
2003 : cvRound(y0 - 1000*(a)));
2004 : line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 );
2005 : }
2006 : #else
2007 : vector<Vec4i> lines;
2008 : HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
2009 : for( size_t i = 0; i < lines.size(); i++ )
2010 : {
2011 : line( color_dst, Point(lines[i][0], lines[i][1]),
2012 : Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
2013 : }
2014 : #endif
2015 : namedWindow( "Source", 1 );
2016 : imshow( "Source", src );
2017 :
2018 : namedWindow( "Detected Lines", 1 );
2019 : imshow( "Detected Lines", color_dst );
2020 :
2021 : waitKey(0);
2022 : return 0;
2023 : }
2024 : @endcode
2025 : This is a sample picture the function parameters have been tuned for:
2026 :
2027 : ![image](pics/building.jpg)
2028 :
2029 : And this is the output of the above program in case of the probabilistic Hough transform:
2030 :
2031 : ![image](pics/houghp.png)
2032 :
2033 : @param image 8-bit, single-channel binary source image. The image may be modified by the function.
2034 : @param lines Output vector of lines. Each line is represented by a 4-element vector
2035 : \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
2036 : line segment.
2037 : @param rho Distance resolution of the accumulator in pixels.
2038 : @param theta Angle resolution of the accumulator in radians.
2039 : @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
2040 : votes ( \f$>\texttt{threshold}\f$ ).
2041 : @param minLineLength Minimum line length. Line segments shorter than that are rejected.
2042 : @param maxLineGap Maximum allowed gap between points on the same line to link them.
2043 :
2044 : @sa LineSegmentDetector
2045 : */
2046 : CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines,
2047 : double rho, double theta, int threshold,
2048 : double minLineLength = 0, double maxLineGap = 0 );
2049 :
2050 : /** @example houghcircles.cpp
2051 : An example using the Hough circle detector
2052 : */
2053 :
2054 : /** @brief Finds circles in a grayscale image using the Hough transform.
2055 :
2056 : The function finds circles in a grayscale image using a modification of the Hough transform.
2057 :
2058 : Example: :
2059 : @code
2060 : #include <opencv2/imgproc.hpp>
2061 : #include <opencv2/highgui.hpp>
2062 : #include <math.h>
2063 :
2064 : using namespace cv;
2065 : using namespace std;
2066 :
2067 : int main(int argc, char** argv)
2068 : {
2069 : Mat img, gray;
2070 : if( argc != 2 || !(img=imread(argv[1], 1)).data)
2071 : return -1;
2072 : cvtColor(img, gray, COLOR_BGR2GRAY);
2073 : // smooth it, otherwise a lot of false circles may be detected
2074 : GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
2075 : vector<Vec3f> circles;
2076 : HoughCircles(gray, circles, HOUGH_GRADIENT,
2077 : 2, gray.rows/4, 200, 100 );
2078 : for( size_t i = 0; i < circles.size(); i++ )
2079 : {
2080 : Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
2081 : int radius = cvRound(circles[i][2]);
2082 : // draw the circle center
2083 : circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
2084 : // draw the circle outline
2085 : circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
2086 : }
2087 : namedWindow( "circles", 1 );
2088 : imshow( "circles", img );
2089 :
2090 : waitKey(0);
2091 : return 0;
2092 : }
2093 : @endcode
2094 :
2095 : @note Usually the function detects the centers of circles well. However, it may fail to find correct
2096 : radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if
2097 : you know it. Or, you may set maxRadius to 0 to return centers only without radius search, and find the correct
2098 : radius using an additional procedure.
2099 :
2100 : @param image 8-bit, single-channel, grayscale input image.
2101 : @param circles Output vector of found circles. Each vector is encoded as a 3-element
2102 : floating-point vector \f$(x, y, radius)\f$ .
2103 : @param method Detection method, see cv::HoughModes. Currently, the only implemented method is HOUGH_GRADIENT
2104 : @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if
2105 : dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has
2106 : half as big width and height.
2107 : @param minDist Minimum distance between the centers of the detected circles. If the parameter is
2108 : too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is
2109 : too large, some circles may be missed.
2110 : @param param1 First method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the higher
2111 : threshold of the two passed to the Canny edge detector (the lower one is twice smaller).
2112 : @param param2 Second method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the
2113 : accumulator threshold for the circle centers at the detection stage. The smaller it is, the more
2114 : false circles may be detected. Circles, corresponding to the larger accumulator values, will be
2115 : returned first.
2116 : @param minRadius Minimum circle radius.
2117 : @param maxRadius Maximum circle radius.
2118 :
2119 : @sa fitEllipse, minEnclosingCircle
2120 : */
2121 : CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles,
2122 : int method, double dp, double minDist,
2123 : double param1 = 100, double param2 = 100,
2124 : int minRadius = 0, int maxRadius = 0 );
2125 :
2126 : //! @} imgproc_feature
2127 :
2128 : //! @addtogroup imgproc_filter
2129 : //! @{
2130 :
2131 : /** @example morphology2.cpp
2132 : Advanced morphology Transformations sample code
2133 : ![Sample screenshot](Morphology_2_Tutorial_Result.jpg)
2134 : Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details
2135 : */
2136 :
2137 : /** @brief Erodes an image by using a specific structuring element.
2138 :
2139 : The function erodes the source image using the specified structuring element that determines the
2140 : shape of a pixel neighborhood over which the minimum is taken:
2141 :
2142 : \f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
2143 :
2144 : The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In
2145 : case of multi-channel images, each channel is processed independently.
2146 :
2147 : @param src input image; the number of channels can be arbitrary, but the depth should be one of
2148 : CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
2149 : @param dst output image of the same size and type as src.
2150 : @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
2151 : structuring element is used. Kernel can be created using getStructuringElement.
2152 : @param anchor position of the anchor within the element; default value (-1, -1) means that the
2153 : anchor is at the element center.
2154 : @param iterations number of times erosion is applied.
2155 : @param borderType pixel extrapolation method, see cv::BorderTypes
2156 : @param borderValue border value in case of a constant border
2157 : @sa dilate, morphologyEx, getStructuringElement
2158 : */
2159 : CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel,
2160 : Point anchor = Point(-1,-1), int iterations = 1,
2161 : int borderType = BORDER_CONSTANT,
2162 : const Scalar& borderValue = morphologyDefaultBorderValue() );
2163 :
2164 : /** @example Morphology_1.cpp
2165 : Erosion and Dilation sample code
2166 : ![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg)
2167 : Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details
2168 : */
2169 : /** @brief Dilates an image by using a specific structuring element.
2170 :
2171 : The function dilates the source image using the specified structuring element that determines the
2172 : shape of a pixel neighborhood over which the maximum is taken:
2173 : \f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
2174 :
2175 : The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In
2176 : case of multi-channel images, each channel is processed independently.
2177 :
2178 : @param src input image; the number of channels can be arbitrary, but the depth should be one of
2179 : CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
2180 : @param dst output image of the same size and type as src\`.
2181 : @param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
2182 : structuring element is used. Kernel can be created using getStructuringElement
2183 : @param anchor position of the anchor within the element; default value (-1, -1) means that the
2184 : anchor is at the element center.
2185 : @param iterations number of times dilation is applied.
2186 : @param borderType pixel extrapolation method, see cv::BorderTypes
2187 : @param borderValue border value in case of a constant border
2188 : @sa erode, morphologyEx, getStructuringElement
2189 : */
2190 : CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel,
2191 : Point anchor = Point(-1,-1), int iterations = 1,
2192 : int borderType = BORDER_CONSTANT,
2193 : const Scalar& borderValue = morphologyDefaultBorderValue() );
2194 :
2195 : /** @brief Performs advanced morphological transformations.
2196 :
2197 : The function morphologyEx can perform advanced morphological transformations using an erosion and dilation as
2198 : basic operations.
2199 :
2200 : Any of the operations can be done in-place. In case of multi-channel images, each channel is
2201 : processed independently.
2202 :
2203 : @param src Source image. The number of channels can be arbitrary. The depth should be one of
2204 : CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
2205 : @param dst Destination image of the same size and type as source image.
2206 : @param op Type of a morphological operation, see cv::MorphTypes
2207 : @param kernel Structuring element. It can be created using cv::getStructuringElement.
2208 : @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the
2209 : kernel center.
2210 : @param iterations Number of times erosion and dilation are applied.
2211 : @param borderType Pixel extrapolation method, see cv::BorderTypes
2212 : @param borderValue Border value in case of a constant border. The default value has a special
2213 : meaning.
2214 : @sa dilate, erode, getStructuringElement
2215 : @note The number of iterations is the number of times erosion or dilatation operation will be applied.
2216 : For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply
2217 : successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate).
2218 : */
2219 : CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst,
2220 : int op, InputArray kernel,
2221 : Point anchor = Point(-1,-1), int iterations = 1,
2222 : int borderType = BORDER_CONSTANT,
2223 : const Scalar& borderValue = morphologyDefaultBorderValue() );
2224 :
2225 : //! @} imgproc_filter
2226 :
2227 : //! @addtogroup imgproc_transform
2228 : //! @{
2229 :
2230 : /** @brief Resizes an image.
2231 :
2232 : The function resize resizes the image src down to or up to the specified size. Note that the
2233 : initial dst type or size are not taken into account. Instead, the size and type are derived from
2234 : the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst,
2235 : you may call the function as follows:
2236 : @code
2237 : // explicitly specify dsize=dst.size(); fx and fy will be computed from that.
2238 : resize(src, dst, dst.size(), 0, 0, interpolation);
2239 : @endcode
2240 : If you want to decimate the image by factor of 2 in each direction, you can call the function this
2241 : way:
2242 : @code
2243 : // specify fx and fy and let the function compute the destination image size.
2244 : resize(src, dst, Size(), 0.5, 0.5, interpolation);
2245 : @endcode
2246 : To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to
2247 : enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR
2248 : (faster but still looks OK).
2249 :
2250 : @param src input image.
2251 : @param dst output image; it has the size dsize (when it is non-zero) or the size computed from
2252 : src.size(), fx, and fy; the type of dst is the same as of src.
2253 : @param dsize output image size; if it equals zero, it is computed as:
2254 : \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
2255 : Either dsize or both fx and fy must be non-zero.
2256 : @param fx scale factor along the horizontal axis; when it equals 0, it is computed as
2257 : \f[\texttt{(double)dsize.width/src.cols}\f]
2258 : @param fy scale factor along the vertical axis; when it equals 0, it is computed as
2259 : \f[\texttt{(double)dsize.height/src.rows}\f]
2260 : @param interpolation interpolation method, see cv::InterpolationFlags
2261 :
2262 : @sa warpAffine, warpPerspective, remap
2263 : */
2264 : CV_EXPORTS_W void resize( InputArray src, OutputArray dst,
2265 : Size dsize, double fx = 0, double fy = 0,
2266 : int interpolation = INTER_LINEAR );
2267 :
2268 : /** @brief Applies an affine transformation to an image.
2269 :
2270 : The function warpAffine transforms the source image using the specified matrix:
2271 :
2272 : \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]
2273 :
2274 : when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted
2275 : with cv::invertAffineTransform and then put in the formula above instead of M. The function cannot
2276 : operate in-place.
2277 :
2278 : @param src input image.
2279 : @param dst output image that has the size dsize and the same type as src .
2280 : @param M \f$2\times 3\f$ transformation matrix.
2281 : @param dsize size of the output image.
2282 : @param flags combination of interpolation methods (see cv::InterpolationFlags) and the optional
2283 : flag WARP_INVERSE_MAP that means that M is the inverse transformation (
2284 : \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
2285 : @param borderMode pixel extrapolation method (see cv::BorderTypes); when
2286 : borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to
2287 : the "outliers" in the source image are not modified by the function.
2288 : @param borderValue value used in case of a constant border; by default, it is 0.
2289 :
2290 : @sa warpPerspective, resize, remap, getRectSubPix, transform
2291 : */
2292 : CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst,
2293 : InputArray M, Size dsize,
2294 : int flags = INTER_LINEAR,
2295 : int borderMode = BORDER_CONSTANT,
2296 : const Scalar& borderValue = Scalar());
2297 :
2298 : /** @example warpPerspective_demo.cpp
2299 : An example program shows using cv::findHomography and cv::warpPerspective for image warping
2300 : */
2301 : /** @brief Applies a perspective transformation to an image.
2302 :
2303 : The function warpPerspective transforms the source image using the specified matrix:
2304 :
2305 : \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}} ,
2306 : \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f]
2307 :
2308 : when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert
2309 : and then put in the formula above instead of M. The function cannot operate in-place.
2310 :
2311 : @param src input image.
2312 : @param dst output image that has the size dsize and the same type as src .
2313 : @param M \f$3\times 3\f$ transformation matrix.
2314 : @param dsize size of the output image.
2315 : @param flags combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the
2316 : optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation (
2317 : \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
2318 : @param borderMode pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).
2319 : @param borderValue value used in case of a constant border; by default, it equals 0.
2320 :
2321 : @sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform
2322 : */
2323 : CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst,
2324 : InputArray M, Size dsize,
2325 : int flags = INTER_LINEAR,
2326 : int borderMode = BORDER_CONSTANT,
2327 : const Scalar& borderValue = Scalar());
2328 :
2329 : /** @brief Applies a generic geometrical transformation to an image.
2330 :
2331 : The function remap transforms the source image using the specified map:
2332 :
2333 : \f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f]
2334 :
2335 : where values of pixels with non-integer coordinates are computed using one of available
2336 : interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps
2337 : in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in
2338 : \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to
2339 : convert from floating to fixed-point representations of a map is that they can yield much faster
2340 : (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),
2341 : cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.
2342 :
2343 : This function cannot operate in-place.
2344 :
2345 : @param src Source image.
2346 : @param dst Destination image. It has the same size as map1 and the same type as src .
2347 : @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 ,
2348 : CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point
2349 : representation to fixed-point for speed.
2350 : @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map
2351 : if map1 is (x,y) points), respectively.
2352 : @param interpolation Interpolation method (see cv::InterpolationFlags). The method INTER_AREA is
2353 : not supported by this function.
2354 : @param borderMode Pixel extrapolation method (see cv::BorderTypes). When
2355 : borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that
2356 : corresponds to the "outliers" in the source image are not modified by the function.
2357 : @param borderValue Value used in case of a constant border. By default, it is 0.
2358 : @note
2359 : Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
2360 : */
2361 : CV_EXPORTS_W void remap( InputArray src, OutputArray dst,
2362 : InputArray map1, InputArray map2,
2363 : int interpolation, int borderMode = BORDER_CONSTANT,
2364 : const Scalar& borderValue = Scalar());
2365 :
2366 : /** @brief Converts image transformation maps from one representation to another.
2367 :
2368 : The function converts a pair of maps for remap from one representation to another. The following
2369 : options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are
2370 : supported:
2371 :
2372 : - \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the
2373 : most frequently used conversion operation, in which the original floating-point maps (see remap )
2374 : are converted to a more compact and much faster fixed-point representation. The first output array
2375 : contains the rounded coordinates and the second array (created only when nninterpolation=false )
2376 : contains indices in the interpolation tables.
2377 :
2378 : - \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but
2379 : the original maps are stored in one 2-channel matrix.
2380 :
2381 : - Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same
2382 : as the originals.
2383 :
2384 : @param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 .
2385 : @param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix),
2386 : respectively.
2387 : @param dstmap1 The first output map that has the type dstmap1type and the same size as src .
2388 : @param dstmap2 The second output map.
2389 : @param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or
2390 : CV_32FC2 .
2391 : @param nninterpolation Flag indicating whether the fixed-point maps are used for the
2392 : nearest-neighbor or for a more complex interpolation.
2393 :
2394 : @sa remap, undistort, initUndistortRectifyMap
2395 : */
2396 : CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2,
2397 : OutputArray dstmap1, OutputArray dstmap2,
2398 : int dstmap1type, bool nninterpolation = false );
2399 :
2400 : /** @brief Calculates an affine matrix of 2D rotation.
2401 :
2402 : The function calculates the following matrix:
2403 :
2404 : \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]
2405 :
2406 : where
2407 :
2408 : \f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f]
2409 :
2410 : The transformation maps the rotation center to itself. If this is not the target, adjust the shift.
2411 :
2412 : @param center Center of the rotation in the source image.
2413 : @param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the
2414 : coordinate origin is assumed to be the top-left corner).
2415 : @param scale Isotropic scale factor.
2416 :
2417 : @sa getAffineTransform, warpAffine, transform
2418 : */
2419 : CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale );
2420 :
2421 : //! returns 3x3 perspective transformation for the corresponding 4 point pairs.
2422 : CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] );
2423 :
2424 : /** @brief Calculates an affine transform from three pairs of the corresponding points.
2425 :
2426 : The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that:
2427 :
2428 : \f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f]
2429 :
2430 : where
2431 :
2432 : \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f]
2433 :
2434 : @param src Coordinates of triangle vertices in the source image.
2435 : @param dst Coordinates of the corresponding triangle vertices in the destination image.
2436 :
2437 : @sa warpAffine, transform
2438 : */
2439 : CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
2440 :
2441 : /** @brief Inverts an affine transformation.
2442 :
2443 : The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M:
2444 :
2445 : \f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f]
2446 :
2447 : The result is also a \f$2 \times 3\f$ matrix of the same type as M.
2448 :
2449 : @param M Original affine transformation.
2450 : @param iM Output reverse affine transformation.
2451 : */
2452 : CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );
2453 :
2454 : /** @brief Calculates a perspective transform from four pairs of the corresponding points.
2455 :
2456 : The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that:
2457 :
2458 : \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]
2459 :
2460 : where
2461 :
2462 : \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f]
2463 :
2464 : @param src Coordinates of quadrangle vertices in the source image.
2465 : @param dst Coordinates of the corresponding quadrangle vertices in the destination image.
2466 :
2467 : @sa findHomography, warpPerspective, perspectiveTransform
2468 : */
2469 : CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst );
2470 :
2471 : CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
2472 :
2473 : /** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy.
2474 :
2475 : The function getRectSubPix extracts pixels from src:
2476 :
2477 : \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]
2478 :
2479 : where the values of the pixels at non-integer coordinates are retrieved using bilinear
2480 : interpolation. Every channel of multi-channel images is processed independently. Also
2481 : the image should be a single channel or three channel image. While the center of the
2482 : rectangle must be inside the image, parts of the rectangle may be outside.
2483 :
2484 : @param image Source image.
2485 : @param patchSize Size of the extracted patch.
2486 : @param center Floating point coordinates of the center of the extracted rectangle within the
2487 : source image. The center must be inside the image.
2488 : @param patch Extracted patch that has the size patchSize and the same number of channels as src .
2489 : @param patchType Depth of the extracted pixels. By default, they have the same depth as src .
2490 :
2491 : @sa warpAffine, warpPerspective
2492 : */
2493 : CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
2494 : Point2f center, OutputArray patch, int patchType = -1 );
2495 :
2496 : /** @example polar_transforms.cpp
2497 : An example using the cv::linearPolar and cv::logPolar operations
2498 : */
2499 :
2500 : /** @brief Remaps an image to semilog-polar coordinates space.
2501 :
2502 : Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image"):
2503 : \f[\begin{array}{l}
2504 : dst( \rho , \phi ) = src(x,y) \\
2505 : dst.size() \leftarrow src.size()
2506 : \end{array}\f]
2507 :
2508 : where
2509 : \f[\begin{array}{l}
2510 : I = (dx,dy) = (x - center.x,y - center.y) \\
2511 : \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\
2512 : \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} \\
2513 : \end{array}\f]
2514 :
2515 : and
2516 : \f[\begin{array}{l}
2517 : M = src.cols / log_e(maxRadius) \\
2518 : Ky = src.rows / 360 \\
2519 : \end{array}\f]
2520 :
2521 : The function emulates the human "foveal" vision and can be used for fast scale and
2522 : rotation-invariant template matching, for object tracking and so forth.
2523 : @param src Source image
2524 : @param dst Destination image. It will have same size and type as src.
2525 : @param center The transformation center; where the output precision is maximal
2526 : @param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too.
2527 : @param flags A combination of interpolation methods, see cv::InterpolationFlags
2528 :
2529 : @note
2530 : - The function can not operate in-place.
2531 : - To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
2532 : */
2533 : CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,
2534 : Point2f center, double M, int flags );
2535 :
2536 : /** @brief Remaps an image to polar coordinates space.
2537 :
2538 : @anchor polar_remaps_reference_image
2539 : ![Polar remaps reference](pics/polar_remap_doc.png)
2540 :
2541 : Transform the source image using the following transformation:
2542 : \f[\begin{array}{l}
2543 : dst( \rho , \phi ) = src(x,y) \\
2544 : dst.size() \leftarrow src.size()
2545 : \end{array}\f]
2546 :
2547 : where
2548 : \f[\begin{array}{l}
2549 : I = (dx,dy) = (x - center.x,y - center.y) \\
2550 : \rho = Kx \cdot \texttt{magnitude} (I) ,\\
2551 : \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg}
2552 : \end{array}\f]
2553 :
2554 : and
2555 : \f[\begin{array}{l}
2556 : Kx = src.cols / maxRadius \\
2557 : Ky = src.rows / 360
2558 : \end{array}\f]
2559 :
2560 :
2561 : @param src Source image
2562 : @param dst Destination image. It will have same size and type as src.
2563 : @param center The transformation center;
2564 : @param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.
2565 : @param flags A combination of interpolation methods, see cv::InterpolationFlags
2566 :
2567 : @note
2568 : - The function can not operate in-place.
2569 : - To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
2570 :
2571 : */
2572 : CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,
2573 : Point2f center, double maxRadius, int flags );
2574 :
2575 : //! @} imgproc_transform
2576 :
2577 : //! @addtogroup imgproc_misc
2578 : //! @{
2579 :
2580 : /** @overload */
2581 : CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 );
2582 :
2583 : /** @overload */
2584 : CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum,
2585 : OutputArray sqsum, int sdepth = -1, int sqdepth = -1 );
2586 :
2587 : /** @brief Calculates the integral of an image.
2588 :
2589 : The function calculates one or more integral images for the source image as follows:
2590 :
2591 : \f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f]
2592 :
2593 : \f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f]
2594 :
2595 : \f[\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)\f]
2596 :
2597 : Using these integral images, you can calculate sum, mean, and standard deviation over a specific
2598 : up-right or rotated rectangular region of the image in a constant time, for example:
2599 :
2600 : \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]
2601 :
2602 : It makes possible to do a fast blurring or fast block correlation with a variable window size, for
2603 : example. In case of multi-channel images, sums for each channel are accumulated independently.
2604 :
2605 : As a practical example, the next figure shows the calculation of the integral of a straight
2606 : rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the
2607 : original image are shown, as well as the relative pixels in the integral images sum and tilted .
2608 :
2609 : ![integral calculation example](pics/integral.png)
2610 :
2611 : @param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f).