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