Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
imgproc.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 #ifndef OPENCV_IMGPROC_HPP 00044 #define OPENCV_IMGPROC_HPP 00045 00046 #include "opencv2/core.hpp" 00047 00048 /** 00049 @defgroup imgproc Image processing 00050 @{ 00051 @defgroup imgproc_filter Image Filtering 00052 00053 Functions and classes described in this section are used to perform various linear or non-linear 00054 filtering operations on 2D images (represented as Mat's). It means that for each pixel location 00055 \f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to 00056 compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of 00057 morphological operations, it is the minimum or maximum values, and so on. The computed response is 00058 stored in the destination image at the same location \f$(x,y)\f$. It means that the output image 00059 will be of the same size as the input image. Normally, the functions support multi-channel arrays, 00060 in which case every channel is processed independently. Therefore, the output image will also have 00061 the same number of channels as the input one. 00062 00063 Another common feature of the functions and classes described in this section is that, unlike 00064 simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For 00065 example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when 00066 processing the left-most pixels in each row, you need pixels to the left of them, that is, outside 00067 of the image. You can let these pixels be the same as the left-most image pixels ("replicated 00068 border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant 00069 border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method. 00070 For details, see cv::BorderTypes 00071 00072 @anchor filter_depths 00073 ### Depth combinations 00074 Input depth (src.depth()) | Output depth (ddepth) 00075 --------------------------|---------------------- 00076 CV_8U | -1/CV_16S/CV_32F/CV_64F 00077 CV_16U/CV_16S | -1/CV_32F/CV_64F 00078 CV_32F | -1/CV_32F/CV_64F 00079 CV_64F | -1/CV_64F 00080 00081 @note when ddepth=-1, the output image will have the same depth as the source. 00082 00083 @defgroup imgproc_transform Geometric Image Transformations 00084 00085 The functions in this section perform various geometrical transformations of 2D images. They do not 00086 change the image content but deform the pixel grid and map this deformed grid to the destination 00087 image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from 00088 destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the 00089 functions compute coordinates of the corresponding "donor" pixel in the source image and copy the 00090 pixel value: 00091 00092 \f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f] 00093 00094 In case when you specify the forward mapping \f$\left<g_x, g_y\right>: \texttt{src} \rightarrow 00095 \texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping 00096 \f$\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula. 00097 00098 The actual implementations of the geometrical transformations, from the most generic remap and to 00099 the simplest and the fastest resize, need to solve two main problems with the above formula: 00100 00101 - Extrapolation of non-existing pixels. Similarly to the filtering functions described in the 00102 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 00103 of them may fall outside of the image. In this case, an extrapolation method needs to be used. 00104 OpenCV provides the same selection of extrapolation methods as in the filtering functions. In 00105 addition, it provides the method BORDER_TRANSPARENT. This means that the corresponding pixels in 00106 the destination image will not be modified at all. 00107 00108 - Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point 00109 numbers. This means that \f$\left<f_x, f_y\right>\f$ can be either an affine or perspective 00110 transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional 00111 coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the 00112 nearest integer coordinates and the corresponding pixel can be used. This is called a 00113 nearest-neighbor interpolation. However, a better result can be achieved by using more 00114 sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) , 00115 where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y), 00116 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 00117 interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See 00118 resize for details. 00119 00120 @defgroup imgproc_misc Miscellaneous Image Transformations 00121 @defgroup imgproc_draw Drawing Functions 00122 00123 Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be 00124 rendered with antialiasing (implemented only for 8-bit images for now). All the functions include 00125 the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) 00126 for color images and brightness for grayscale images. For color images, the channel ordering is 00127 normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a 00128 color using the Scalar constructor, it should look like: 00129 00130 \f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f] 00131 00132 If you are using your own image rendering and I/O functions, you can use any channel ordering. The 00133 drawing functions process each channel independently and do not depend on the channel order or even 00134 on the used color space. The whole image can be converted from BGR to RGB or to a different color 00135 space using cvtColor . 00136 00137 If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, 00138 many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means 00139 that the coordinates can be passed as fixed-point numbers encoded as integers. The number of 00140 fractional bits is specified by the shift parameter and the real point coordinates are calculated as 00141 \f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is 00142 especially effective when rendering antialiased shapes. 00143 00144 @note The functions do not support alpha-transparency when the target image is 4-channel. In this 00145 case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint 00146 semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main 00147 image. 00148 00149 @defgroup imgproc_colormap ColorMaps in OpenCV 00150 00151 The human perception isn't built for observing fine changes in grayscale images. Human eyes are more 00152 sensitive to observing changes between colors, so you often need to recolor your grayscale images to 00153 get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your 00154 computer vision application. 00155 00156 In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample 00157 code reads the path to an image from command line, applies a Jet colormap on it and shows the 00158 result: 00159 00160 @code 00161 #include <opencv2/core.hpp> 00162 #include <opencv2/imgproc.hpp> 00163 #include <opencv2/imgcodecs.hpp> 00164 #include <opencv2/highgui.hpp> 00165 using namespace cv; 00166 00167 #include <iostream> 00168 using namespace std; 00169 00170 int main(int argc, const char *argv[]) 00171 { 00172 // We need an input image. (can be grayscale or color) 00173 if (argc < 2) 00174 { 00175 cerr << "We need an image to process here. Please run: colorMap [path_to_image]" << endl; 00176 return -1; 00177 } 00178 Mat img_in = imread(argv[1]); 00179 if(img_in.empty()) 00180 { 00181 cerr << "Sample image (" << argv[1] << ") is empty. Please adjust your path, so it points to a valid input image!" << endl; 00182 return -1; 00183 } 00184 // Holds the colormap version of the image: 00185 Mat img_color; 00186 // Apply the colormap: 00187 applyColorMap(img_in, img_color, COLORMAP_JET); 00188 // Show the result: 00189 imshow("colorMap", img_color); 00190 waitKey(0); 00191 return 0; 00192 } 00193 @endcode 00194 00195 @see cv::ColormapTypes 00196 00197 @defgroup imgproc_subdiv2d Planar Subdivision 00198 00199 The Subdiv2D class described in this section is used to perform various planar subdivision on 00200 a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles 00201 using the Delaunay’s algorithm, which corresponds to the dual graph of the Voronoi diagram. 00202 In the figure below, the Delaunay’s triangulation is marked with black lines and the Voronoi 00203 diagram with red lines. 00204 00205  00206 00207 The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast 00208 location of points on the plane, building special graphs (such as NNG,RNG), and so forth. 00209 00210 @defgroup imgproc_hist Histograms 00211 @defgroup imgproc_shape Structural Analysis and Shape Descriptors 00212 @defgroup imgproc_motion Motion Analysis and Object Tracking 00213 @defgroup imgproc_feature Feature Detection 00214 @defgroup imgproc_object Object Detection 00215 @defgroup imgproc_c C API 00216 @defgroup imgproc_hal Hardware Acceleration Layer 00217 @{ 00218 @defgroup imgproc_hal_functions Functions 00219 @defgroup imgproc_hal_interface Interface 00220 @} 00221 @} 00222 */ 00223 00224 namespace cv 00225 { 00226 00227 /** @addtogroup imgproc 00228 @{ 00229 */ 00230 00231 //! @addtogroup imgproc_filter 00232 //! @{ 00233 00234 //! type of morphological operation 00235 enum MorphTypes{ 00236 MORPH_ERODE = 0, //!< see cv::erode 00237 MORPH_DILATE = 1, //!< see cv::dilate 00238 MORPH_OPEN = 2, //!< an opening operation 00239 //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f] 00240 MORPH_CLOSE = 3, //!< a closing operation 00241 //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f] 00242 MORPH_GRADIENT = 4, //!< a morphological gradient 00243 //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f] 00244 MORPH_TOPHAT = 5, //!< "top hat" 00245 //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f] 00246 MORPH_BLACKHAT = 6, //!< "black hat" 00247 //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f] 00248 MORPH_HITMISS = 7 //!< "hit and miss" 00249 //!< .- Only supported for CV_8UC1 binary images. Tutorial can be found in [this page](https://web.archive.org/web/20160316070407/http://opencv-code.com/tutorials/hit-or-miss-transform-in-opencv/) 00250 }; 00251 00252 //! shape of the structuring element 00253 enum MorphShapes { 00254 MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f] 00255 MORPH_CROSS = 1, //!< a cross-shaped structuring element: 00256 //!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f] 00257 MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed 00258 //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height) 00259 }; 00260 00261 //! @} imgproc_filter 00262 00263 //! @addtogroup imgproc_transform 00264 //! @{ 00265 00266 //! interpolation algorithm 00267 enum InterpolationFlags{ 00268 /** nearest neighbor interpolation */ 00269 INTER_NEAREST = 0, 00270 /** bilinear interpolation */ 00271 INTER_LINEAR = 1, 00272 /** bicubic interpolation */ 00273 INTER_CUBIC = 2, 00274 /** resampling using pixel area relation. It may be a preferred method for image decimation, as 00275 it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST 00276 method. */ 00277 INTER_AREA = 3, 00278 /** Lanczos interpolation over 8x8 neighborhood */ 00279 INTER_LANCZOS4 = 4, 00280 /** mask for interpolation codes */ 00281 INTER_MAX = 7, 00282 /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the 00283 source image, they are set to zero */ 00284 WARP_FILL_OUTLIERS = 8, 00285 /** flag, inverse transformation 00286 00287 For example, @ref cv::linearPolar or @ref cv::logPolar transforms: 00288 - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$ 00289 - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$ 00290 */ 00291 WARP_INVERSE_MAP = 16 00292 }; 00293 00294 enum InterpolationMasks { 00295 INTER_BITS = 5, 00296 INTER_BITS2 = INTER_BITS * 2, 00297 INTER_TAB_SIZE = 1 << INTER_BITS, 00298 INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE 00299 }; 00300 00301 //! @} imgproc_transform 00302 00303 //! @addtogroup imgproc_misc 00304 //! @{ 00305 00306 //! Distance types for Distance Transform and M-estimators 00307 //! @see cv::distanceTransform, cv::fitLine 00308 enum DistanceTypes { 00309 DIST_USER = -1, //!< User defined distance 00310 DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2| 00311 DIST_L2 = 2, //!< the simple euclidean distance 00312 DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|) 00313 DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) 00314 DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 00315 DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 00316 DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 00317 }; 00318 00319 //! Mask size for distance transform 00320 enum DistanceTransformMasks { 00321 DIST_MASK_3 = 3, //!< mask=3 00322 DIST_MASK_5 = 5, //!< mask=5 00323 DIST_MASK_PRECISE = 0 //!< 00324 }; 00325 00326 //! type of the threshold operation 00327 //!  00328 enum ThresholdTypes { 00329 THRESH_BINARY = 0, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{maxval}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] 00330 THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f] 00331 THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] 00332 THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] 00333 THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] 00334 THRESH_MASK = 7, 00335 THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value 00336 THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value 00337 }; 00338 00339 //! adaptive threshold algorithm 00340 //! see cv::adaptiveThreshold 00341 enum AdaptiveThresholdTypes { 00342 /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times 00343 \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */ 00344 ADAPTIVE_THRESH_MEAN_C = 0, 00345 /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian 00346 window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ 00347 minus C . The default sigma (standard deviation) is used for the specified blockSize . See 00348 cv::getGaussianKernel*/ 00349 ADAPTIVE_THRESH_GAUSSIAN_C = 1 00350 }; 00351 00352 //! cv::undistort mode 00353 enum UndistortTypes { 00354 PROJ_SPHERICAL_ORTHO = 0, 00355 PROJ_SPHERICAL_EQRECT = 1 00356 }; 00357 00358 //! class of the pixel in GrabCut algorithm 00359 enum GrabCutClasses { 00360 GC_BGD = 0, //!< an obvious background pixels 00361 GC_FGD = 1, //!< an obvious foreground (object) pixel 00362 GC_PR_BGD = 2, //!< a possible background pixel 00363 GC_PR_FGD = 3 //!< a possible foreground pixel 00364 }; 00365 00366 //! GrabCut algorithm flags 00367 enum GrabCutModes { 00368 /** The function initializes the state and the mask using the provided rectangle. After that it 00369 runs iterCount iterations of the algorithm. */ 00370 GC_INIT_WITH_RECT = 0, 00371 /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT 00372 and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are 00373 automatically initialized with GC_BGD .*/ 00374 GC_INIT_WITH_MASK = 1, 00375 /** The value means that the algorithm should just resume. */ 00376 GC_EVAL = 2 00377 }; 00378 00379 //! distanceTransform algorithm flags 00380 enum DistanceTransformLabelTypes { 00381 /** each connected component of zeros in src (as well as all the non-zero pixels closest to the 00382 connected component) will be assigned the same label */ 00383 DIST_LABEL_CCOMP = 0, 00384 /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */ 00385 DIST_LABEL_PIXEL = 1 00386 }; 00387 00388 //! floodfill algorithm flags 00389 enum FloodFillFlags { 00390 /** If set, the difference between the current pixel and seed pixel is considered. Otherwise, 00391 the difference between neighbor pixels is considered (that is, the range is floating). */ 00392 FLOODFILL_FIXED_RANGE = 1 << 16, 00393 /** If set, the function does not change the image ( newVal is ignored), and only fills the 00394 mask with the value specified in bits 8-16 of flags as described above. This option only make 00395 sense in function variants that have the mask parameter. */ 00396 FLOODFILL_MASK_ONLY = 1 << 17 00397 }; 00398 00399 //! @} imgproc_misc 00400 00401 //! @addtogroup imgproc_shape 00402 //! @{ 00403 00404 //! connected components algorithm output formats 00405 enum ConnectedComponentsTypes { 00406 CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding 00407 //!< box in the horizontal direction. 00408 CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding 00409 //!< box in the vertical direction. 00410 CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box 00411 CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box 00412 CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component 00413 CC_STAT_MAX = 5 00414 }; 00415 00416 //! connected components algorithm 00417 enum ConnectedComponentsAlgorithmsTypes { 00418 CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity 00419 CCL_DEFAULT = -1, //!< BBDT algortihm for 8-way connectivity, SAUF algorithm for 4-way connectivity 00420 CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity 00421 }; 00422 00423 //! mode of the contour retrieval algorithm 00424 enum RetrievalModes { 00425 /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for 00426 all the contours. */ 00427 RETR_EXTERNAL = 0, 00428 /** retrieves all of the contours without establishing any hierarchical relationships. */ 00429 RETR_LIST = 1, 00430 /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top 00431 level, there are external boundaries of the components. At the second level, there are 00432 boundaries of the holes. If there is another contour inside a hole of a connected component, it 00433 is still put at the top level. */ 00434 RETR_CCOMP = 2, 00435 /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/ 00436 RETR_TREE = 3, 00437 RETR_FLOODFILL = 4 //!< 00438 }; 00439 00440 //! the contour approximation algorithm 00441 enum ContourApproximationModes { 00442 /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and 00443 (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is, 00444 max(abs(x1-x2),abs(y2-y1))==1. */ 00445 CHAIN_APPROX_NONE = 1, 00446 /** compresses horizontal, vertical, and diagonal segments and leaves only their end points. 00447 For example, an up-right rectangular contour is encoded with 4 points. */ 00448 CHAIN_APPROX_SIMPLE = 2, 00449 /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ 00450 CHAIN_APPROX_TC89_L1 = 3, 00451 /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ 00452 CHAIN_APPROX_TC89_KCOS = 4 00453 }; 00454 00455 //! @} imgproc_shape 00456 00457 //! Variants of a Hough transform 00458 enum HoughModes { 00459 00460 /** classical or standard Hough transform. Every line is represented by two floating-point 00461 numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line, 00462 and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must 00463 be (the created sequence will be) of CV_32FC2 type */ 00464 HOUGH_STANDARD = 0, 00465 /** probabilistic Hough transform (more efficient in case if the picture contains a few long 00466 linear segments). It returns line segments rather than the whole line. Each segment is 00467 represented by starting and ending points, and the matrix must be (the created sequence will 00468 be) of the CV_32SC4 type. */ 00469 HOUGH_PROBABILISTIC = 1, 00470 /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as 00471 HOUGH_STANDARD. */ 00472 HOUGH_MULTI_SCALE = 2, 00473 HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90 00474 }; 00475 00476 //! Variants of Line Segment %Detector 00477 //! @ingroup imgproc_feature 00478 enum LineSegmentDetectorModes { 00479 LSD_REFINE_NONE = 0, //!< No refinement applied 00480 LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations. 00481 LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are 00482 //!< refined through increase of precision, decrement in size, etc. 00483 }; 00484 00485 /** Histogram comparison methods 00486 @ingroup imgproc_hist 00487 */ 00488 enum HistCompMethods { 00489 /** Correlation 00490 \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] 00491 where 00492 \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f] 00493 and \f$N\f$ is a total number of histogram bins. */ 00494 HISTCMP_CORREL = 0, 00495 /** Chi-Square 00496 \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */ 00497 HISTCMP_CHISQR = 1, 00498 /** Intersection 00499 \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */ 00500 HISTCMP_INTERSECT = 2, 00501 /** Bhattacharyya distance 00502 (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.) 00503 \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] */ 00504 HISTCMP_BHATTACHARYYA = 3, 00505 HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA 00506 /** Alternative Chi-Square 00507 \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] 00508 This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */ 00509 HISTCMP_CHISQR_ALT = 4, 00510 /** Kullback-Leibler divergence 00511 \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */ 00512 HISTCMP_KL_DIV = 5 00513 }; 00514 00515 /** the color conversion code 00516 @see @ref imgproc_color_conversions 00517 @ingroup imgproc_misc 00518 */ 00519 enum ColorConversionCodes { 00520 COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image 00521 COLOR_RGB2RGBA = COLOR_BGR2BGRA, 00522 00523 COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image 00524 COLOR_RGBA2RGB = COLOR_BGRA2BGR, 00525 00526 COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel) 00527 COLOR_RGB2BGRA = COLOR_BGR2RGBA, 00528 00529 COLOR_RGBA2BGR = 3, 00530 COLOR_BGRA2RGB = COLOR_RGBA2BGR, 00531 00532 COLOR_BGR2RGB = 4, 00533 COLOR_RGB2BGR = COLOR_BGR2RGB, 00534 00535 COLOR_BGRA2RGBA = 5, 00536 COLOR_RGBA2BGRA = COLOR_BGRA2RGBA, 00537 00538 COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions" 00539 COLOR_RGB2GRAY = 7, 00540 COLOR_GRAY2BGR = 8, 00541 COLOR_GRAY2RGB = COLOR_GRAY2BGR, 00542 COLOR_GRAY2BGRA = 9, 00543 COLOR_GRAY2RGBA = COLOR_GRAY2BGRA, 00544 COLOR_BGRA2GRAY = 10, 00545 COLOR_RGBA2GRAY = 11, 00546 00547 COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images) 00548 COLOR_RGB2BGR565 = 13, 00549 COLOR_BGR5652BGR = 14, 00550 COLOR_BGR5652RGB = 15, 00551 COLOR_BGRA2BGR565 = 16, 00552 COLOR_RGBA2BGR565 = 17, 00553 COLOR_BGR5652BGRA = 18, 00554 COLOR_BGR5652RGBA = 19, 00555 00556 COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images) 00557 COLOR_BGR5652GRAY = 21, 00558 00559 COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images) 00560 COLOR_RGB2BGR555 = 23, 00561 COLOR_BGR5552BGR = 24, 00562 COLOR_BGR5552RGB = 25, 00563 COLOR_BGRA2BGR555 = 26, 00564 COLOR_RGBA2BGR555 = 27, 00565 COLOR_BGR5552BGRA = 28, 00566 COLOR_BGR5552RGBA = 29, 00567 00568 COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images) 00569 COLOR_BGR5552GRAY = 31, 00570 00571 COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions" 00572 COLOR_RGB2XYZ = 33, 00573 COLOR_XYZ2BGR = 34, 00574 COLOR_XYZ2RGB = 35, 00575 00576 COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions" 00577 COLOR_RGB2YCrCb = 37, 00578 COLOR_YCrCb2BGR = 38, 00579 COLOR_YCrCb2RGB = 39, 00580 00581 COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions" 00582 COLOR_RGB2HSV = 41, 00583 00584 COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions" 00585 COLOR_RGB2Lab = 45, 00586 00587 COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions" 00588 COLOR_RGB2Luv = 51, 00589 COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions" 00590 COLOR_RGB2HLS = 53, 00591 00592 COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR 00593 COLOR_HSV2RGB = 55, 00594 00595 COLOR_Lab2BGR = 56, 00596 COLOR_Lab2RGB = 57, 00597 COLOR_Luv2BGR = 58, 00598 COLOR_Luv2RGB = 59, 00599 COLOR_HLS2BGR = 60, 00600 COLOR_HLS2RGB = 61, 00601 00602 COLOR_BGR2HSV_FULL = 66, //!< 00603 COLOR_RGB2HSV_FULL = 67, 00604 COLOR_BGR2HLS_FULL = 68, 00605 COLOR_RGB2HLS_FULL = 69, 00606 00607 COLOR_HSV2BGR_FULL = 70, 00608 COLOR_HSV2RGB_FULL = 71, 00609 COLOR_HLS2BGR_FULL = 72, 00610 COLOR_HLS2RGB_FULL = 73, 00611 00612 COLOR_LBGR2Lab = 74, 00613 COLOR_LRGB2Lab = 75, 00614 COLOR_LBGR2Luv = 76, 00615 COLOR_LRGB2Luv = 77, 00616 00617 COLOR_Lab2LBGR = 78, 00618 COLOR_Lab2LRGB = 79, 00619 COLOR_Luv2LBGR = 80, 00620 COLOR_Luv2LRGB = 81, 00621 00622 COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV 00623 COLOR_RGB2YUV = 83, 00624 COLOR_YUV2BGR = 84, 00625 COLOR_YUV2RGB = 85, 00626 00627 //! YUV 4:2:0 family to RGB 00628 COLOR_YUV2RGB_NV12 = 90, 00629 COLOR_YUV2BGR_NV12 = 91, 00630 COLOR_YUV2RGB_NV21 = 92, 00631 COLOR_YUV2BGR_NV21 = 93, 00632 COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21, 00633 COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21, 00634 00635 COLOR_YUV2RGBA_NV12 = 94, 00636 COLOR_YUV2BGRA_NV12 = 95, 00637 COLOR_YUV2RGBA_NV21 = 96, 00638 COLOR_YUV2BGRA_NV21 = 97, 00639 COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21, 00640 COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21, 00641 00642 COLOR_YUV2RGB_YV12 = 98, 00643 COLOR_YUV2BGR_YV12 = 99, 00644 COLOR_YUV2RGB_IYUV = 100, 00645 COLOR_YUV2BGR_IYUV = 101, 00646 COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV, 00647 COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV, 00648 COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12, 00649 COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12, 00650 00651 COLOR_YUV2RGBA_YV12 = 102, 00652 COLOR_YUV2BGRA_YV12 = 103, 00653 COLOR_YUV2RGBA_IYUV = 104, 00654 COLOR_YUV2BGRA_IYUV = 105, 00655 COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV, 00656 COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV, 00657 COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12, 00658 COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12, 00659 00660 COLOR_YUV2GRAY_420 = 106, 00661 COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420, 00662 COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420, 00663 COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420, 00664 COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420, 00665 COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420, 00666 COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420, 00667 COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420, 00668 00669 //! YUV 4:2:2 family to RGB 00670 COLOR_YUV2RGB_UYVY = 107, 00671 COLOR_YUV2BGR_UYVY = 108, 00672 //COLOR_YUV2RGB_VYUY = 109, 00673 //COLOR_YUV2BGR_VYUY = 110, 00674 COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY, 00675 COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY, 00676 COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY, 00677 COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY, 00678 00679 COLOR_YUV2RGBA_UYVY = 111, 00680 COLOR_YUV2BGRA_UYVY = 112, 00681 //COLOR_YUV2RGBA_VYUY = 113, 00682 //COLOR_YUV2BGRA_VYUY = 114, 00683 COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY, 00684 COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY, 00685 COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY, 00686 COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY, 00687 00688 COLOR_YUV2RGB_YUY2 = 115, 00689 COLOR_YUV2BGR_YUY2 = 116, 00690 COLOR_YUV2RGB_YVYU = 117, 00691 COLOR_YUV2BGR_YVYU = 118, 00692 COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2, 00693 COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2, 00694 COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2, 00695 COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2, 00696 00697 COLOR_YUV2RGBA_YUY2 = 119, 00698 COLOR_YUV2BGRA_YUY2 = 120, 00699 COLOR_YUV2RGBA_YVYU = 121, 00700 COLOR_YUV2BGRA_YVYU = 122, 00701 COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2, 00702 COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2, 00703 COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2, 00704 COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2, 00705 00706 COLOR_YUV2GRAY_UYVY = 123, 00707 COLOR_YUV2GRAY_YUY2 = 124, 00708 //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY, 00709 COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY, 00710 COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY, 00711 COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2, 00712 COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2, 00713 COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2, 00714 00715 //! alpha premultiplication 00716 COLOR_RGBA2mRGBA = 125, 00717 COLOR_mRGBA2RGBA = 126, 00718 00719 //! RGB to YUV 4:2:0 family 00720 COLOR_RGB2YUV_I420 = 127, 00721 COLOR_BGR2YUV_I420 = 128, 00722 COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420, 00723 COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420, 00724 00725 COLOR_RGBA2YUV_I420 = 129, 00726 COLOR_BGRA2YUV_I420 = 130, 00727 COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420, 00728 COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420, 00729 COLOR_RGB2YUV_YV12 = 131, 00730 COLOR_BGR2YUV_YV12 = 132, 00731 COLOR_RGBA2YUV_YV12 = 133, 00732 COLOR_BGRA2YUV_YV12 = 134, 00733 00734 //! Demosaicing 00735 COLOR_BayerBG2BGR = 46, 00736 COLOR_BayerGB2BGR = 47, 00737 COLOR_BayerRG2BGR = 48, 00738 COLOR_BayerGR2BGR = 49, 00739 00740 COLOR_BayerBG2RGB = COLOR_BayerRG2BGR, 00741 COLOR_BayerGB2RGB = COLOR_BayerGR2BGR, 00742 COLOR_BayerRG2RGB = COLOR_BayerBG2BGR, 00743 COLOR_BayerGR2RGB = COLOR_BayerGB2BGR, 00744 00745 COLOR_BayerBG2GRAY = 86, 00746 COLOR_BayerGB2GRAY = 87, 00747 COLOR_BayerRG2GRAY = 88, 00748 COLOR_BayerGR2GRAY = 89, 00749 00750 //! Demosaicing using Variable Number of Gradients 00751 COLOR_BayerBG2BGR_VNG = 62, 00752 COLOR_BayerGB2BGR_VNG = 63, 00753 COLOR_BayerRG2BGR_VNG = 64, 00754 COLOR_BayerGR2BGR_VNG = 65, 00755 00756 COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG, 00757 COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG, 00758 COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG, 00759 COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG, 00760 00761 //! Edge-Aware Demosaicing 00762 COLOR_BayerBG2BGR_EA = 135, 00763 COLOR_BayerGB2BGR_EA = 136, 00764 COLOR_BayerRG2BGR_EA = 137, 00765 COLOR_BayerGR2BGR_EA = 138, 00766 00767 COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA, 00768 COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA, 00769 COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA, 00770 COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA, 00771 00772 00773 COLOR_COLORCVT_MAX = 139 00774 }; 00775 00776 /** types of intersection between rectangles 00777 @ingroup imgproc_shape 00778 */ 00779 enum RectanglesIntersectTypes { 00780 INTERSECT_NONE = 0, //!< No intersection 00781 INTERSECT_PARTIAL = 1, //!< There is a partial intersection 00782 INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other 00783 }; 00784 00785 //! finds arbitrary template in the grayscale image using Generalized Hough Transform 00786 class CV_EXPORTS GeneralizedHough : public Algorithm 00787 { 00788 public: 00789 //! set template to search 00790 virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0; 00791 virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0; 00792 00793 //! find template on image 00794 virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0; 00795 virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0; 00796 00797 //! Canny low threshold. 00798 virtual void setCannyLowThresh(int cannyLowThresh) = 0; 00799 virtual int getCannyLowThresh() const = 0; 00800 00801 //! Canny high threshold. 00802 virtual void setCannyHighThresh(int cannyHighThresh) = 0; 00803 virtual int getCannyHighThresh() const = 0; 00804 00805 //! Minimum distance between the centers of the detected objects. 00806 virtual void setMinDist(double minDist) = 0; 00807 virtual double getMinDist() const = 0; 00808 00809 //! Inverse ratio of the accumulator resolution to the image resolution. 00810 virtual void setDp(double dp) = 0; 00811 virtual double getDp() const = 0; 00812 00813 //! Maximal size of inner buffers. 00814 virtual void setMaxBufferSize(int maxBufferSize) = 0; 00815 virtual int getMaxBufferSize() const = 0; 00816 }; 00817 00818 //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. 00819 //! Detects position only without traslation and rotation 00820 class CV_EXPORTS GeneralizedHoughBallard : public GeneralizedHough 00821 { 00822 public: 00823 //! R-Table levels. 00824 virtual void setLevels(int levels) = 0; 00825 virtual int getLevels() const = 0; 00826 00827 //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected. 00828 virtual void setVotesThreshold(int votesThreshold) = 0; 00829 virtual int getVotesThreshold() const = 0; 00830 }; 00831 00832 //! 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. 00833 //! Detects position, traslation and rotation 00834 class CV_EXPORTS GeneralizedHoughGuil : public GeneralizedHough 00835 { 00836 public: 00837 //! Angle difference in degrees between two points in feature. 00838 virtual void setXi(double xi) = 0; 00839 virtual double getXi() const = 0; 00840 00841 //! Feature table levels. 00842 virtual void setLevels(int levels) = 0; 00843 virtual int getLevels() const = 0; 00844 00845 //! Maximal difference between angles that treated as equal. 00846 virtual void setAngleEpsilon(double angleEpsilon) = 0; 00847 virtual double getAngleEpsilon() const = 0; 00848 00849 //! Minimal rotation angle to detect in degrees. 00850 virtual void setMinAngle(double minAngle) = 0; 00851 virtual double getMinAngle() const = 0; 00852 00853 //! Maximal rotation angle to detect in degrees. 00854 virtual void setMaxAngle(double maxAngle) = 0; 00855 virtual double getMaxAngle() const = 0; 00856 00857 //! Angle step in degrees. 00858 virtual void setAngleStep(double angleStep) = 0; 00859 virtual double getAngleStep() const = 0; 00860 00861 //! Angle votes threshold. 00862 virtual void setAngleThresh(int angleThresh) = 0; 00863 virtual int getAngleThresh() const = 0; 00864 00865 //! Minimal scale to detect. 00866 virtual void setMinScale(double minScale) = 0; 00867 virtual double getMinScale() const = 0; 00868 00869 //! Maximal scale to detect. 00870 virtual void setMaxScale(double maxScale) = 0; 00871 virtual double getMaxScale() const = 0; 00872 00873 //! Scale step. 00874 virtual void setScaleStep(double scaleStep) = 0; 00875 virtual double getScaleStep() const = 0; 00876 00877 //! Scale votes threshold. 00878 virtual void setScaleThresh(int scaleThresh) = 0; 00879 virtual int getScaleThresh() const = 0; 00880 00881 //! Position votes threshold. 00882 virtual void setPosThresh(int posThresh) = 0; 00883 virtual int getPosThresh() const = 0; 00884 }; 00885 00886 00887 class CV_EXPORTS_W CLAHE : public Algorithm 00888 { 00889 public: 00890 CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0; 00891 00892 CV_WRAP virtual void setClipLimit(double clipLimit) = 0; 00893 CV_WRAP virtual double getClipLimit() const = 0; 00894 00895 CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0; 00896 CV_WRAP virtual Size getTilesGridSize() const = 0; 00897 00898 CV_WRAP virtual void collectGarbage() = 0; 00899 }; 00900 00901 00902 //! @addtogroup imgproc_subdiv2d 00903 //! @{ 00904 00905 class CV_EXPORTS_W Subdiv2D 00906 { 00907 public: 00908 /** Subdiv2D point location cases */ 00909 enum { PTLOC_ERROR = -2, //!< Point location error 00910 PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect 00911 PTLOC_INSIDE = 0, //!< Point inside some facet 00912 PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices 00913 PTLOC_ON_EDGE = 2 //!< Point on some edge 00914 }; 00915 00916 /** Subdiv2D edge type navigation (see: getEdge()) */ 00917 enum { NEXT_AROUND_ORG = 0x00, 00918 NEXT_AROUND_DST = 0x22, 00919 PREV_AROUND_ORG = 0x11, 00920 PREV_AROUND_DST = 0x33, 00921 NEXT_AROUND_LEFT = 0x13, 00922 NEXT_AROUND_RIGHT = 0x31, 00923 PREV_AROUND_LEFT = 0x20, 00924 PREV_AROUND_RIGHT = 0x02 00925 }; 00926 00927 /** creates an empty Subdiv2D object. 00928 To create a new empty Delaunay subdivision you need to use the initDelaunay() function. 00929 */ 00930 CV_WRAP Subdiv2D(); 00931 00932 /** @overload 00933 00934 @param rect – Rectangle that includes all of the 2D points that are to be added to the subdivision. 00935 00936 The function creates an empty Delaunay subdivision where 2D points can be added using the function 00937 insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime 00938 error is raised. 00939 */ 00940 CV_WRAP Subdiv2D(Rect rect); 00941 00942 /** @brief Creates a new empty Delaunay subdivision 00943 00944 @param rect – Rectangle that includes all of the 2D points that are to be added to the subdivision. 00945 00946 */ 00947 CV_WRAP void initDelaunay(Rect rect); 00948 00949 /** @brief Insert a single point into a Delaunay triangulation. 00950 00951 @param pt – Point to insert. 00952 00953 The function inserts a single point into a subdivision and modifies the subdivision topology 00954 appropriately. If a point with the same coordinates exists already, no new point is added. 00955 @returns the ID of the point. 00956 00957 @note If the point is outside of the triangulation specified rect a runtime error is raised. 00958 */ 00959 CV_WRAP int insert(Point2f pt); 00960 00961 /** @brief Insert multiple points into a Delaunay triangulation. 00962 00963 @param ptvec – Points to insert. 00964 00965 The function inserts a vector of points into a subdivision and modifies the subdivision topology 00966 appropriately. 00967 */ 00968 CV_WRAP void insert(const std::vector<Point2f>& ptvec); 00969 00970 /** @brief Returns the location of a point within a Delaunay triangulation. 00971 00972 @param pt – Point to locate. 00973 @param edge – Output edge that the point belongs to or is located to the right of it. 00974 @param vertex – Optional output vertex the input point coincides with. 00975 00976 The function locates the input point within the subdivision and gives one of the triangle edges 00977 or vertices. 00978 00979 @returns an integer which specify one of the following five cases for point location: 00980 - The point falls into some facet. The function returns PTLOC_INSIDE and edge will contain one of 00981 edges of the facet. 00982 - The point falls onto the edge. The function returns PTLOC_ON_EDGE and edge will contain this edge. 00983 - The point coincides with one of the subdivision vertices. The function returns PTLOC_VERTEX and 00984 vertex will contain a pointer to the vertex. 00985 - The point is outside the subdivision reference rectangle. The function returns PTLOC_OUTSIDE_RECT 00986 and no pointers are filled. 00987 - One of input arguments is invalid. A runtime error is raised or, if silent or “parent” error 00988 processing mode is selected, CV_PTLOC_ERROR is returnd. 00989 */ 00990 CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex); 00991 00992 /** @brief Finds the subdivision vertex closest to the given point. 00993 00994 @param pt – Input point. 00995 @param nearestPt – Output subdivision vertex point. 00996 00997 The function is another function that locates the input point within the subdivision. It finds the 00998 subdivision vertex that is the closest to the input point. It is not necessarily one of vertices 00999 of the facet containing the input point, though the facet (located using locate() ) is used as a 01000 starting point. 01001 01002 @returns vertex ID. 01003 */ 01004 CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0); 01005 01006 /** @brief Returns a list of all edges. 01007 01008 @param edgeList – Output vector. 01009 01010 The function gives each edge as a 4 numbers vector, where each two are one of the edge 01011 vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3]. 01012 */ 01013 CV_WRAP void getEdgeList(CV_OUT std::vector<Vec4f>& edgeList) const; 01014 01015 /** @brief Returns a list of the leading edge ID connected to each triangle. 01016 01017 @param leadingEdgeList – Output vector. 01018 01019 The function gives one edge ID for each triangle. 01020 */ 01021 CV_WRAP void getLeadingEdgeList(CV_OUT std::vector<int>& leadingEdgeList) const; 01022 01023 /** @brief Returns a list of all triangles. 01024 01025 @param triangleList – Output vector. 01026 01027 The function gives each triangle as a 6 numbers vector, where each two are one of the triangle 01028 vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5]. 01029 */ 01030 CV_WRAP void getTriangleList(CV_OUT std::vector<Vec6f>& triangleList) const; 01031 01032 /** @brief Returns a list of all Voroni facets. 01033 01034 @param idx – Vector of vertices IDs to consider. For all vertices you can pass empty vector. 01035 @param facetList – Output vector of the Voroni facets. 01036 @param facetCenters – Output vector of the Voroni facets center points. 01037 01038 */ 01039 CV_WRAP void getVoronoiFacetList(const std::vector<int>& idx, CV_OUT std::vector<std::vector<Point2f> >& facetList, 01040 CV_OUT std::vector<Point2f>& facetCenters); 01041 01042 /** @brief Returns vertex location from vertex ID. 01043 01044 @param vertex – vertex ID. 01045 @param firstEdge – Optional. The first edge ID which is connected to the vertex. 01046 @returns vertex (x,y) 01047 01048 */ 01049 CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const; 01050 01051 /** @brief Returns one of the edges related to the given edge. 01052 01053 @param edge – Subdivision edge ID. 01054 @param nextEdgeType - Parameter specifying which of the related edges to return. 01055 The following values are possible: 01056 - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge) 01057 - NEXT_AROUND_DST next around the edge vertex ( eDnext ) 01058 - PREV_AROUND_ORG previous around the edge origin (reversed eRnext ) 01059 - PREV_AROUND_DST previous around the edge destination (reversed eLnext ) 01060 - NEXT_AROUND_LEFT next around the left facet ( eLnext ) 01061 - NEXT_AROUND_RIGHT next around the right facet ( eRnext ) 01062 - PREV_AROUND_LEFT previous around the left facet (reversed eOnext ) 01063 - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext ) 01064 01065  01066 01067 @returns edge ID related to the input edge. 01068 */ 01069 CV_WRAP int getEdge( int edge, int nextEdgeType ) const; 01070 01071 /** @brief Returns next edge around the edge origin. 01072 01073 @param edge – Subdivision edge ID. 01074 01075 @returns an integer which is next edge ID around the edge origin: eOnext on the 01076 picture above if e is the input edge). 01077 */ 01078 CV_WRAP int nextEdge(int edge) const; 01079 01080 /** @brief Returns another edge of the same quad-edge. 01081 01082 @param edge – Subdivision edge ID. 01083 @param rotate - Parameter specifying which of the edges of the same quad-edge as the input 01084 one to return. The following values are possible: 01085 - 0 - the input edge ( e on the picture below if e is the input edge) 01086 - 1 - the rotated edge ( eRot ) 01087 - 2 - the reversed edge (reversed e (in green)) 01088 - 3 - the reversed rotated edge (reversed eRot (in green)) 01089 01090 @returns one of the edges ID of the same quad-edge as the input edge. 01091 */ 01092 CV_WRAP int rotateEdge(int edge, int rotate) const; 01093 CV_WRAP int symEdge(int edge) const; 01094 01095 /** @brief Returns the edge origin. 01096 01097 @param edge – Subdivision edge ID. 01098 @param orgpt – Output vertex location. 01099 01100 @returns vertex ID. 01101 */ 01102 CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const; 01103 01104 /** @brief Returns the edge destination. 01105 01106 @param edge – Subdivision edge ID. 01107 @param dstpt – Output vertex location. 01108 01109 @returns vertex ID. 01110 */ 01111 CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const; 01112 01113 protected: 01114 int newEdge(); 01115 void deleteEdge(int edge); 01116 int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0); 01117 void deletePoint(int vtx); 01118 void setEdgePoints( int edge, int orgPt, int dstPt ); 01119 void splice( int edgeA, int edgeB ); 01120 int connectEdges( int edgeA, int edgeB ); 01121 void swapEdges( int edge ); 01122 int isRightOf(Point2f pt, int edge) const; 01123 void calcVoronoi(); 01124 void clearVoronoi(); 01125 void checkSubdiv() const; 01126 01127 struct CV_EXPORTS Vertex 01128 { 01129 Vertex(); 01130 Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0); 01131 bool isvirtual() const; 01132 bool isfree() const; 01133 01134 int firstEdge; 01135 int type; 01136 Point2f pt; 01137 }; 01138 01139 struct CV_EXPORTS QuadEdge 01140 { 01141 QuadEdge(); 01142 QuadEdge(int edgeidx); 01143 bool isfree() const; 01144 01145 int next[4]; 01146 int pt[4]; 01147 }; 01148 01149 //! All of the vertices 01150 std::vector<Vertex> vtx; 01151 //! All of the edges 01152 std::vector<QuadEdge> qedges; 01153 int freeQEdge; 01154 int freePoint; 01155 bool validGeometry; 01156 01157 int recentEdge; 01158 //! Top left corner of the bounding rect 01159 Point2f topLeft; 01160 //! Bottom right corner of the bounding rect 01161 Point2f bottomRight; 01162 }; 01163 01164 //! @} imgproc_subdiv2d 01165 01166 //! @addtogroup imgproc_feature 01167 //! @{ 01168 01169 /** @example lsd_lines.cpp 01170 An example using the LineSegmentDetector 01171 */ 01172 01173 /** @brief Line segment detector class 01174 01175 following the algorithm described at @cite Rafael12 . 01176 */ 01177 class CV_EXPORTS_W LineSegmentDetector : public Algorithm 01178 { 01179 public: 01180 01181 /** @brief Finds lines in the input image. 01182 01183 This is the output of the default parameters of the algorithm on the above shown image. 01184 01185  01186 01187 @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: 01188 `lsd_ptr->detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` 01189 @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where 01190 Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly 01191 oriented depending on the gradient. 01192 @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. 01193 @param prec Vector of precisions with which the lines are found. 01194 @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The 01195 bigger the value, logarithmically better the detection. 01196 - -1 corresponds to 10 mean false alarms 01197 - 0 corresponds to 1 mean false alarm 01198 - 1 corresponds to 0.1 mean false alarms 01199 This vector will be calculated only when the objects type is LSD_REFINE_ADV. 01200 */ 01201 CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, 01202 OutputArray width = noArray(), OutputArray prec = noArray(), 01203 OutputArray nfa = noArray()) = 0; 01204 01205 /** @brief Draws the line segments on a given image. 01206 @param _image The image, where the liens will be drawn. Should be bigger or equal to the image, 01207 where the lines were found. 01208 @param lines A vector of the lines that needed to be drawn. 01209 */ 01210 CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; 01211 01212 /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. 01213 01214 @param size The size of the image, where lines1 and lines2 were found. 01215 @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. 01216 @param lines2 The second group of lines. They visualized in red color. 01217 @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) 01218 in order for lines1 and lines2 to be drawn in the above mentioned colors. 01219 */ 01220 CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; 01221 01222 virtual ~LineSegmentDetector() { } 01223 }; 01224 01225 /** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it. 01226 01227 The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want 01228 to edit those, as to tailor it for their own application. 01229 01230 @param _refine The way found lines will be refined, see cv::LineSegmentDetectorModes 01231 @param _scale The scale of the image that will be used to find the lines. Range (0..1]. 01232 @param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. 01233 @param _quant Bound to the quantization error on the gradient norm. 01234 @param _ang_th Gradient angle tolerance in degrees. 01235 @param _log_eps Detection threshold: -log10(NFA) > log_eps. Used only when advancent refinement 01236 is chosen. 01237 @param _density_th Minimal density of aligned region points in the enclosing rectangle. 01238 @param _n_bins Number of bins in pseudo-ordering of gradient modulus. 01239 */ 01240 CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector( 01241 int _refine = LSD_REFINE_STD, double _scale = 0.8, 01242 double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, 01243 double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); 01244 01245 //! @} imgproc_feature 01246 01247 //! @addtogroup imgproc_filter 01248 //! @{ 01249 01250 /** @brief Returns Gaussian filter coefficients. 01251 01252 The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter 01253 coefficients: 01254 01255 \f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f] 01256 01257 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$. 01258 01259 Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize 01260 smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly. 01261 You may also use the higher-level GaussianBlur. 01262 @param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive. 01263 @param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as 01264 `sigma = 0.3\*((ksize-1)\*0.5 - 1) + 0.8`. 01265 @param ktype Type of filter coefficients. It can be CV_32F or CV_64F . 01266 @sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur 01267 */ 01268 CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F ); 01269 01270 /** @brief Returns filter coefficients for computing spatial image derivatives. 01271 01272 The function computes and returns the filter coefficients for spatial image derivatives. When 01273 `ksize=CV_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see cv::Scharr). Otherwise, Sobel 01274 kernels are generated (see cv::Sobel). The filters are normally passed to sepFilter2D or to 01275 01276 @param kx Output matrix of row filter coefficients. It has the type ktype . 01277 @param ky Output matrix of column filter coefficients. It has the type ktype . 01278 @param dx Derivative order in respect of x. 01279 @param dy Derivative order in respect of y. 01280 @param ksize Aperture size. It can be CV_SCHARR, 1, 3, 5, or 7. 01281 @param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not. 01282 Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are 01283 going to filter floating-point images, you are likely to use the normalized kernels. But if you 01284 compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve 01285 all the fractional bits, you may want to set normalize=false . 01286 @param ktype Type of filter coefficients. It can be CV_32f or CV_64F . 01287 */ 01288 CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky, 01289 int dx, int dy, int ksize, 01290 bool normalize = false, int ktype = CV_32F ); 01291 01292 /** @brief Returns Gabor filter coefficients. 01293 01294 For more details about gabor filter equations and parameters, see: [Gabor 01295 Filter](http://en.wikipedia.org/wiki/Gabor_filter). 01296 01297 @param ksize Size of the filter returned. 01298 @param sigma Standard deviation of the gaussian envelope. 01299 @param theta Orientation of the normal to the parallel stripes of a Gabor function. 01300 @param lambd Wavelength of the sinusoidal factor. 01301 @param gamma Spatial aspect ratio. 01302 @param psi Phase offset. 01303 @param ktype Type of filter coefficients. It can be CV_32F or CV_64F . 01304 */ 01305 CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd, 01306 double gamma, double psi = CV_PI*0.5, int ktype = CV_64F ); 01307 01308 //! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation. 01309 static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); } 01310 01311 /** @brief Returns a structuring element of the specified size and shape for morphological operations. 01312 01313 The function constructs and returns the structuring element that can be further passed to cv::erode, 01314 cv::dilate or cv::morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as 01315 the structuring element. 01316 01317 @param shape Element shape that could be one of cv::MorphShapes 01318 @param ksize Size of the structuring element. 01319 @param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the 01320 anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor 01321 position. In other cases the anchor just regulates how much the result of the morphological 01322 operation is shifted. 01323 */ 01324 CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); 01325 01326 /** @brief Blurs an image using the median filter. 01327 01328 The function smoothes an image using the median filter with the \f$\texttt{ksize} \times 01329 \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. 01330 In-place operation is supported. 01331 01332 @note The median filter uses BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes 01333 01334 @param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be 01335 CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U. 01336 @param dst destination array of the same size and type as src. 01337 @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ... 01338 @sa bilateralFilter, blur, boxFilter, GaussianBlur 01339 */ 01340 CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize ); 01341 01342 /** @brief Blurs an image using a Gaussian filter. 01343 01344 The function convolves the source image with the specified Gaussian kernel. In-place filtering is 01345 supported. 01346 01347 @param src input image; the image can have any number of channels, which are processed 01348 independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. 01349 @param dst output image of the same size and type as src. 01350 @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be 01351 positive and odd. Or, they can be zero's and then they are computed from sigma. 01352 @param sigmaX Gaussian kernel standard deviation in X direction. 01353 @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be 01354 equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, 01355 respectively (see cv::getGaussianKernel for details); to fully control the result regardless of 01356 possible future modifications of all this semantics, it is recommended to specify all of ksize, 01357 sigmaX, and sigmaY. 01358 @param borderType pixel extrapolation method, see cv::BorderTypes 01359 01360 @sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur 01361 */ 01362 CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize, 01363 double sigmaX, double sigmaY = 0, 01364 int borderType = BORDER_DEFAULT ); 01365 01366 /** @brief Applies the bilateral filter to an image. 01367 01368 The function applies bilateral filtering to the input image, as described in 01369 http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html 01370 bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is 01371 very slow compared to most filters. 01372 01373 _Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (< 01374 10), the filter will not have much effect, whereas if they are large (> 150), they will have a very 01375 strong effect, making the image look "cartoonish". 01376 01377 _Filter size_: Large filters (d > 5) are very slow, so it is recommended to use d=5 for real-time 01378 applications, and perhaps d=9 for offline applications that need heavy noise filtering. 01379 01380 This filter does not work inplace. 01381 @param src Source 8-bit or floating-point, 1-channel or 3-channel image. 01382 @param dst Destination image of the same size and type as src . 01383 @param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, 01384 it is computed from sigmaSpace. 01385 @param sigmaColor Filter sigma in the color space. A larger value of the parameter means that 01386 farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting 01387 in larger areas of semi-equal color. 01388 @param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that 01389 farther pixels will influence each other as long as their colors are close enough (see sigmaColor 01390 ). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is 01391 proportional to sigmaSpace. 01392 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes 01393 */ 01394 CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d, 01395 double sigmaColor, double sigmaSpace, 01396 int borderType = BORDER_DEFAULT ); 01397 01398 /** @brief Blurs an image using the box filter. 01399 01400 The function smoothes an image using the kernel: 01401 01402 \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] 01403 01404 where 01405 01406 \f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f] 01407 01408 Unnormalized box filter is useful for computing various integral characteristics over each pixel 01409 neighborhood, such as covariance matrices of image derivatives (used in dense optical flow 01410 algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral. 01411 01412 @param src input image. 01413 @param dst output image of the same size and type as src. 01414 @param ddepth the output image depth (-1 to use src.depth()). 01415 @param ksize blurring kernel size. 01416 @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel 01417 center. 01418 @param normalize flag, specifying whether the kernel is normalized by its area or not. 01419 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes 01420 @sa blur, bilateralFilter, GaussianBlur, medianBlur, integral 01421 */ 01422 CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth, 01423 Size ksize, Point anchor = Point(-1,-1), 01424 bool normalize = true, 01425 int borderType = BORDER_DEFAULT ); 01426 01427 /** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter. 01428 01429 For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring 01430 pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$. 01431 01432 The unnormalized square box filter can be useful in computing local image statistics such as the the local 01433 variance and standard deviation around the neighborhood of a pixel. 01434 01435 @param _src input image 01436 @param _dst output image of the same size and type as _src 01437 @param ddepth the output image depth (-1 to use src.depth()) 01438 @param ksize kernel size 01439 @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel 01440 center. 01441 @param normalize flag, specifying whether the kernel is to be normalized by it's area or not. 01442 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes 01443 @sa boxFilter 01444 */ 01445 CV_EXPORTS_W void sqrBoxFilter( InputArray _src, OutputArray _dst, int ddepth, 01446 Size ksize, Point anchor = Point(-1, -1), 01447 bool normalize = true, 01448 int borderType = BORDER_DEFAULT ); 01449 01450 /** @brief Blurs an image using the normalized box filter. 01451 01452 The function smoothes an image using the kernel: 01453 01454 \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] 01455 01456 The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(), 01457 anchor, true, borderType)`. 01458 01459 @param src input image; it can have any number of channels, which are processed independently, but 01460 the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. 01461 @param dst output image of the same size and type as src. 01462 @param ksize blurring kernel size. 01463 @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel 01464 center. 01465 @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes 01466 @sa boxFilter, bilateralFilter, GaussianBlur, medianBlur 01467 */ 01468 CV_EXPORTS_W void blur( InputArray src, OutputArray dst, 01469 Size ksize, Point anchor = Point(-1,-1), 01470 int borderType = BORDER_DEFAULT ); 01471 01472 /** @brief Convolves an image with the kernel. 01473 01474 The function applies an arbitrary linear filter to an image. In-place operation is supported. When 01475 the aperture is partially outside the image, the function interpolates outlier pixel values 01476 according to the specified border mode. 01477 01478 The function does actually compute correlation, not the convolution: 01479 01480 \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] 01481 01482 That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip 01483 the kernel using cv::flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows - 01484 anchor.y - 1)`. 01485 01486 The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or 01487 larger) and the direct algorithm for small kernels. 01488 01489 @param src input image. 01490 @param dst output image of the same size and the same number of channels as src. 01491 @param ddepth desired depth of the destination image, see @ref filter_depths "combinations" 01492 @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point 01493 matrix; if you want to apply different kernels to different channels, split the image into 01494 separate color planes using split and process them individually. 01495 @param anchor anchor of the kernel that indicates the relative position of a filtered point within 01496 the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor 01497 is at the kernel center. 01498 @param delta optional value added to the filtered pixels before storing them in dst. 01499 @param borderType pixel extrapolation method, see cv::BorderTypes 01500 @sa sepFilter2D, dft, matchTemplate 01501 */ 01502 CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth, 01503 InputArray kernel, Point anchor = Point(-1,-1), 01504 double delta = 0, int borderType = BORDER_DEFAULT ); 01505 01506 /** @brief Applies a separable linear filter to an image. 01507 01508 The function applies a separable linear filter to the image. That is, first, every row of src is 01509 filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D 01510 kernel kernelY. The final result shifted by delta is stored in dst . 01511 01512 @param src Source image. 01513 @param dst Destination image of the same size and the same number of channels as src . 01514 @param ddepth Destination image depth, see @ref filter_depths "combinations" 01515 @param kernelX Coefficients for filtering each row. 01516 @param kernelY Coefficients for filtering each column. 01517 @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor 01518 is at the kernel center. 01519 @param delta Value added to the filtered results before storing them. 01520 @param borderType Pixel extrapolation method, see cv::BorderTypes 01521 @sa filter2D, Sobel, GaussianBlur, boxFilter, blur 01522 */ 01523 CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth, 01524 InputArray kernelX, InputArray kernelY, 01525 Point anchor = Point(-1,-1), 01526 double delta = 0, int borderType = BORDER_DEFAULT ); 01527 01528 /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. 01529 01530 In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to 01531 calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ 01532 kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first 01533 or the second x- or y- derivatives. 01534 01535 There is also the special value `ksize = CV_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr 01536 filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is 01537 01538 \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] 01539 01540 for the x-derivative, or transposed for the y-derivative. 01541 01542 The function calculates an image derivative by convolving the image with the appropriate kernel: 01543 01544 \f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] 01545 01546 The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less 01547 resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) 01548 or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first 01549 case corresponds to a kernel of: 01550 01551 \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] 01552 01553 The second case corresponds to a kernel of: 01554 01555 \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] 01556 01557 @param src input image. 01558 @param dst output image of the same size and the same number of channels as src . 01559 @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of 01560 8-bit input images it will result in truncated derivatives. 01561 @param dx order of the derivative x. 01562 @param dy order of the derivative y. 01563 @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. 01564 @param scale optional scale factor for the computed derivative values; by default, no scaling is 01565 applied (see cv::getDerivKernels for details). 01566 @param delta optional delta value that is added to the results prior to storing them in dst. 01567 @param borderType pixel extrapolation method, see cv::BorderTypes 01568 @sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar 01569 */ 01570 CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth, 01571 int dx, int dy, int ksize = 3, 01572 double scale = 1, double delta = 0, 01573 int borderType = BORDER_DEFAULT ); 01574 01575 /** @brief Calculates the first order image derivative in both x and y using a Sobel operator 01576 01577 Equivalent to calling: 01578 01579 @code 01580 Sobel( src, dx, CV_16SC1, 1, 0, 3 ); 01581 Sobel( src, dy, CV_16SC1, 0, 1, 3 ); 01582 @endcode 01583 01584 @param src input image. 01585 @param dx output image with first-order derivative in x. 01586 @param dy output image with first-order derivative in y. 01587 @param ksize size of Sobel kernel. It must be 3. 01588 @param borderType pixel extrapolation method, see cv::BorderTypes 01589 01590 @sa Sobel 01591 */ 01592 01593 CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx, 01594 OutputArray dy, int ksize = 3, 01595 int borderType = BORDER_DEFAULT ); 01596 01597 /** @brief Calculates the first x- or y- image derivative using Scharr operator. 01598 01599 The function computes the first x- or y- spatial image derivative using the Scharr operator. The 01600 call 01601 01602 \f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f] 01603 01604 is equivalent to 01605 01606 \f[\texttt{Sobel(src, dst, ddepth, dx, dy, CV\_SCHARR, scale, delta, borderType)} .\f] 01607 01608 @param src input image. 01609 @param dst output image of the same size and the same number of channels as src. 01610 @param ddepth output image depth, see @ref filter_depths "combinations" 01611 @param dx order of the derivative x. 01612 @param dy order of the derivative y. 01613 @param scale optional scale factor for the computed derivative values; by default, no scaling is 01614 applied (see getDerivKernels for details). 01615 @param delta optional delta value that is added to the results prior to storing them in dst. 01616 @param borderType pixel extrapolation method, see cv::BorderTypes 01617 @sa cartToPolar 01618 */ 01619 CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth, 01620 int dx, int dy, double scale = 1, double delta = 0, 01621 int borderType = BORDER_DEFAULT ); 01622 01623 /** @example laplace.cpp 01624 An example using Laplace transformations for edge detection 01625 */ 01626 01627 /** @brief Calculates the Laplacian of an image. 01628 01629 The function calculates the Laplacian of the source image by adding up the second x and y 01630 derivatives calculated using the Sobel operator: 01631 01632 \f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f] 01633 01634 This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image 01635 with the following \f$3 \times 3\f$ aperture: 01636 01637 \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f] 01638 01639 @param src Source image. 01640 @param dst Destination image of the same size and the same number of channels as src . 01641 @param ddepth Desired depth of the destination image. 01642 @param ksize Aperture size used to compute the second-derivative filters. See getDerivKernels for 01643 details. The size must be positive and odd. 01644 @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is 01645 applied. See getDerivKernels for details. 01646 @param delta Optional delta value that is added to the results prior to storing them in dst . 01647 @param borderType Pixel extrapolation method, see cv::BorderTypes 01648 @sa Sobel, Scharr 01649 */ 01650 CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth, 01651 int ksize = 1, double scale = 1, double delta = 0, 01652 int borderType = BORDER_DEFAULT ); 01653 01654 //! @} imgproc_filter 01655 01656 //! @addtogroup imgproc_feature 01657 //! @{ 01658 01659 /** @example edge.cpp 01660 An example on using the canny edge detector 01661 */ 01662 01663 /** @brief Finds edges in an image using the Canny algorithm @cite Canny86 . 01664 01665 The function finds edges in the input image image and marks them in the output map edges using the 01666 Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The 01667 largest value is used to find initial segments of strong edges. See 01668 <http://en.wikipedia.org/wiki/Canny_edge_detector> 01669 01670 @param image 8-bit input image. 01671 @param edges output edge map; single channels 8-bit image, which has the same size as image . 01672 @param threshold1 first threshold for the hysteresis procedure. 01673 @param threshold2 second threshold for the hysteresis procedure. 01674 @param apertureSize aperture size for the Sobel operator. 01675 @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm 01676 \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( 01677 L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( 01678 L2gradient=false ). 01679 */ 01680 CV_EXPORTS_W void Canny( InputArray image, OutputArray edges, 01681 double threshold1, double threshold2, 01682 int apertureSize = 3, bool L2gradient = false ); 01683 01684 /** \overload 01685 01686 Finds edges in an image using the Canny algorithm with custom image gradient. 01687 01688 @param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3). 01689 @param dy 16-bit y derivative of input image (same type as dx). 01690 @param edges,threshold1,threshold2,L2gradient See cv::Canny 01691 */ 01692 CV_EXPORTS_W void Canny( InputArray dx, InputArray dy, 01693 OutputArray edges, 01694 double threshold1, double threshold2, 01695 bool L2gradient = false ); 01696 01697 /** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection. 01698 01699 The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal 01700 eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms 01701 of the formulae in the cornerEigenValsAndVecs description. 01702 01703 @param src Input single-channel 8-bit or floating-point image. 01704 @param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as 01705 src . 01706 @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ). 01707 @param ksize Aperture parameter for the Sobel operator. 01708 @param borderType Pixel extrapolation method. See cv::BorderTypes. 01709 */ 01710 CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst, 01711 int blockSize, int ksize = 3, 01712 int borderType = BORDER_DEFAULT ); 01713 01714 /** @brief Harris corner detector. 01715 01716 The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and 01717 cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance 01718 matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it 01719 computes the following characteristic: 01720 01721 \f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f] 01722 01723 Corners in the image can be found as the local maxima of this response map. 01724 01725 @param src Input single-channel 8-bit or floating-point image. 01726 @param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same 01727 size as src . 01728 @param blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ). 01729 @param ksize Aperture parameter for the Sobel operator. 01730 @param k Harris detector free parameter. See the formula below. 01731 @param borderType Pixel extrapolation method. See cv::BorderTypes. 01732 */ 01733 CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize, 01734 int ksize, double k, 01735 int borderType = BORDER_DEFAULT ); 01736 01737 /** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection. 01738 01739 For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize 01740 neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as: 01741 01742 \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] 01743 01744 where the derivatives are computed using the Sobel operator. 01745 01746 After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as 01747 \f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where 01748 01749 - \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$ 01750 - \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$ 01751 - \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$ 01752 01753 The output of the function can be used for robust edge or corner detection. 01754 01755 @param src Input single-channel 8-bit or floating-point image. 01756 @param dst Image to store the results. It has the same size as src and the type CV_32FC(6) . 01757 @param blockSize Neighborhood size (see details below). 01758 @param ksize Aperture parameter for the Sobel operator. 01759 @param borderType Pixel extrapolation method. See cv::BorderTypes. 01760 01761 @sa cornerMinEigenVal, cornerHarris, preCornerDetect 01762 */ 01763 CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst, 01764 int blockSize, int ksize, 01765 int borderType = BORDER_DEFAULT ); 01766 01767 /** @brief Calculates a feature map for corner detection. 01768 01769 The function calculates the complex spatial derivative-based function of the source image 01770 01771 \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] 01772 01773 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 01774 derivatives, and \f$D_{xy}\f$ is the mixed derivative. 01775 01776 The corners can be found as local maximums of the functions, as shown below: 01777 @code 01778 Mat corners, dilated_corners; 01779 preCornerDetect(image, corners, 3); 01780 // dilation with 3x3 rectangular structuring element 01781 dilate(corners, dilated_corners, Mat(), 1); 01782 Mat corner_mask = corners == dilated_corners; 01783 @endcode 01784 01785 @param src Source single-channel 8-bit of floating-point image. 01786 @param dst Output image that has the type CV_32F and the same size as src . 01787 @param ksize %Aperture size of the Sobel . 01788 @param borderType Pixel extrapolation method. See cv::BorderTypes. 01789 */ 01790 CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize, 01791 int borderType = BORDER_DEFAULT ); 01792 01793 /** @brief Refines the corner locations. 01794 01795 The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as 01796 shown on the figure below. 01797 01798  01799 01800 Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$ 01801 to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$ 01802 subject to image and measurement noise. Consider the expression: 01803 01804 \f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f] 01805 01806 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 01807 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 01808 with \f$\epsilon_i\f$ set to zero: 01809 01810 \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] 01811 01812 where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first 01813 gradient term \f$G\f$ and the second gradient term \f$b\f$ gives: 01814 01815 \f[q = G^{-1} \cdot b\f] 01816 01817 The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates 01818 until the center stays within a set threshold. 01819 01820 @param image Input image. 01821 @param corners Initial coordinates of the input corners and refined coordinates provided for 01822 output. 01823 @param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) , 01824 then a \f$5*2+1 \times 5*2+1 = 11 \times 11\f$ search window is used. 01825 @param zeroZone Half of the size of the dead region in the middle of the search zone over which 01826 the summation in the formula below is not done. It is used sometimes to avoid possible 01827 singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such 01828 a size. 01829 @param criteria Criteria for termination of the iterative process of corner refinement. That is, 01830 the process of corner position refinement stops either after criteria.maxCount iterations or when 01831 the corner position moves by less than criteria.epsilon on some iteration. 01832 */ 01833 CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners, 01834 Size winSize, Size zeroZone, 01835 TermCriteria criteria ); 01836 01837 /** @brief Determines strong corners on an image. 01838 01839 The function finds the most prominent corners in the image or in the specified image region, as 01840 described in @cite Shi94 01841 01842 - Function calculates the corner quality measure at every source image pixel using the 01843 cornerMinEigenVal or cornerHarris . 01844 - Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are 01845 retained). 01846 - The corners with the minimal eigenvalue less than 01847 \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected. 01848 - The remaining corners are sorted by the quality measure in the descending order. 01849 - Function throws away each corner for which there is a stronger corner at a distance less than 01850 maxDistance. 01851 01852 The function can be used to initialize a point-based tracker of an object. 01853 01854 @note If the function is called with different values A and B of the parameter qualityLevel , and 01855 A > B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector 01856 with qualityLevel=B . 01857 01858 @param image Input 8-bit or floating-point 32-bit, single-channel image. 01859 @param corners Output vector of detected corners. 01860 @param maxCorners Maximum number of corners to return. If there are more corners than are found, 01861 the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set 01862 and all detected corners are returned. 01863 @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The 01864 parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue 01865 (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the 01866 quality measure less than the product are rejected. For example, if the best corner has the 01867 quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure 01868 less than 15 are rejected. 01869 @param minDistance Minimum possible Euclidean distance between the returned corners. 01870 @param mask Optional region of interest. If the image is not empty (it needs to have the type 01871 CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected. 01872 @param blockSize Size of an average block for computing a derivative covariation matrix over each 01873 pixel neighborhood. See cornerEigenValsAndVecs . 01874 @param useHarrisDetector Parameter indicating whether to use a Harris detector (see cornerHarris) 01875 or cornerMinEigenVal. 01876 @param k Free parameter of the Harris detector. 01877 01878 @sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform, 01879 */ 01880 CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, 01881 int maxCorners, double qualityLevel, double minDistance, 01882 InputArray mask = noArray(), int blockSize = 3, 01883 bool useHarrisDetector = false, double k = 0.04 ); 01884 01885 /** @example houghlines.cpp 01886 An example using the Hough line detector 01887 */ 01888 01889 /** @brief Finds lines in a binary image using the standard Hough transform. 01890 01891 The function implements the standard or standard multi-scale Hough transform algorithm for line 01892 detection. See <http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm> for a good explanation of Hough 01893 transform. 01894 01895 @param image 8-bit, single-channel binary source image. The image may be modified by the function. 01896 @param lines Output vector of lines. Each line is represented by a two-element vector 01897 \f$(\rho, \theta)\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of 01898 the image). \f$\theta\f$ is the line rotation angle in radians ( 01899 \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ). 01900 @param rho Distance resolution of the accumulator in pixels. 01901 @param theta Angle resolution of the accumulator in radians. 01902 @param threshold Accumulator threshold parameter. Only those lines are returned that get enough 01903 votes ( \f$>\texttt{threshold}\f$ ). 01904 @param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho . 01905 The coarse accumulator distance resolution is rho and the accurate accumulator resolution is 01906 rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these 01907 parameters should be positive. 01908 @param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta. 01909 @param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines. 01910 Must fall between 0 and max_theta. 01911 @param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines. 01912 Must fall between min_theta and CV_PI. 01913 */ 01914 CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines, 01915 double rho, double theta, int threshold, 01916 double srn = 0, double stn = 0, 01917 double min_theta = 0, double max_theta = CV_PI ); 01918 01919 /** @brief Finds line segments in a binary image using the probabilistic Hough transform. 01920 01921 The function implements the probabilistic Hough transform algorithm for line detection, described 01922 in @cite Matas00 01923 01924 See the line detection example below: 01925 01926 @code 01927 #include <opencv2/imgproc.hpp> 01928 #include <opencv2/highgui.hpp> 01929 01930 using namespace cv; 01931 using namespace std; 01932 01933 int main(int argc, char** argv) 01934 { 01935 Mat src, dst, color_dst; 01936 if( argc != 2 || !(src=imread(argv[1], 0)).data) 01937 return -1; 01938 01939 Canny( src, dst, 50, 200, 3 ); 01940 cvtColor( dst, color_dst, COLOR_GRAY2BGR ); 01941 01942 #if 0 01943 vector<Vec2f> lines; 01944 HoughLines( dst, lines, 1, CV_PI/180, 100 ); 01945 01946 for( size_t i = 0; i < lines.size(); i++ ) 01947 { 01948 float rho = lines[i][0]; 01949 float theta = lines[i][1]; 01950 double a = cos(theta), b = sin(theta); 01951 double x0 = a*rho, y0 = b*rho; 01952 Point pt1(cvRound(x0 + 1000*(-b)), 01953 cvRound(y0 + 1000*(a))); 01954 Point pt2(cvRound(x0 - 1000*(-b)), 01955 cvRound(y0 - 1000*(a))); 01956 line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 ); 01957 } 01958 #else 01959 vector<Vec4i> lines; 01960 HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 ); 01961 for( size_t i = 0; i < lines.size(); i++ ) 01962 { 01963 line( color_dst, Point(lines[i][0], lines[i][1]), 01964 Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 ); 01965 } 01966 #endif 01967 namedWindow( "Source", 1 ); 01968 imshow( "Source", src ); 01969 01970 namedWindow( "Detected Lines", 1 ); 01971 imshow( "Detected Lines", color_dst ); 01972 01973 waitKey(0); 01974 return 0; 01975 } 01976 @endcode 01977 This is a sample picture the function parameters have been tuned for: 01978 01979  01980 01981 And this is the output of the above program in case of the probabilistic Hough transform: 01982 01983  01984 01985 @param image 8-bit, single-channel binary source image. The image may be modified by the function. 01986 @param lines Output vector of lines. Each line is represented by a 4-element vector 01987 \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 01988 line segment. 01989 @param rho Distance resolution of the accumulator in pixels. 01990 @param theta Angle resolution of the accumulator in radians. 01991 @param threshold Accumulator threshold parameter. Only those lines are returned that get enough 01992 votes ( \f$>\texttt{threshold}\f$ ). 01993 @param minLineLength Minimum line length. Line segments shorter than that are rejected. 01994 @param maxLineGap Maximum allowed gap between points on the same line to link them. 01995 01996 @sa LineSegmentDetector 01997 */ 01998 CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines, 01999 double rho, double theta, int threshold, 02000 double minLineLength = 0, double maxLineGap = 0 ); 02001 02002 /** @example houghcircles.cpp 02003 An example using the Hough circle detector 02004 */ 02005 02006 /** @brief Finds circles in a grayscale image using the Hough transform. 02007 02008 The function finds circles in a grayscale image using a modification of the Hough transform. 02009 02010 Example: : 02011 @code 02012 #include <opencv2/imgproc.hpp> 02013 #include <opencv2/highgui.hpp> 02014 #include <math.h> 02015 02016 using namespace cv; 02017 using namespace std; 02018 02019 int main(int argc, char** argv) 02020 { 02021 Mat img, gray; 02022 if( argc != 2 || !(img=imread(argv[1], 1)).data) 02023 return -1; 02024 cvtColor(img, gray, COLOR_BGR2GRAY); 02025 // smooth it, otherwise a lot of false circles may be detected 02026 GaussianBlur( gray, gray, Size(9, 9), 2, 2 ); 02027 vector<Vec3f> circles; 02028 HoughCircles(gray, circles, HOUGH_GRADIENT, 02029 2, gray.rows/4, 200, 100 ); 02030 for( size_t i = 0; i < circles.size(); i++ ) 02031 { 02032 Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); 02033 int radius = cvRound(circles[i][2]); 02034 // draw the circle center 02035 circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 ); 02036 // draw the circle outline 02037 circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 ); 02038 } 02039 namedWindow( "circles", 1 ); 02040 imshow( "circles", img ); 02041 02042 waitKey(0); 02043 return 0; 02044 } 02045 @endcode 02046 02047 @note Usually the function detects the centers of circles well. However, it may fail to find correct 02048 radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if 02049 you know it. Or, you may ignore the returned radius, use only the center, and find the correct 02050 radius using an additional procedure. 02051 02052 @param image 8-bit, single-channel, grayscale input image. 02053 @param circles Output vector of found circles. Each vector is encoded as a 3-element 02054 floating-point vector \f$(x, y, radius)\f$ . 02055 @param method Detection method, see cv::HoughModes. Currently, the only implemented method is HOUGH_GRADIENT 02056 @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if 02057 dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has 02058 half as big width and height. 02059 @param minDist Minimum distance between the centers of the detected circles. If the parameter is 02060 too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is 02061 too large, some circles may be missed. 02062 @param param1 First method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the higher 02063 threshold of the two passed to the Canny edge detector (the lower one is twice smaller). 02064 @param param2 Second method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the 02065 accumulator threshold for the circle centers at the detection stage. The smaller it is, the more 02066 false circles may be detected. Circles, corresponding to the larger accumulator values, will be 02067 returned first. 02068 @param minRadius Minimum circle radius. 02069 @param maxRadius Maximum circle radius. 02070 02071 @sa fitEllipse, minEnclosingCircle 02072 */ 02073 CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles, 02074 int method, double dp, double minDist, 02075 double param1 = 100, double param2 = 100, 02076 int minRadius = 0, int maxRadius = 0 ); 02077 02078 //! @} imgproc_feature 02079 02080 //! @addtogroup imgproc_filter 02081 //! @{ 02082 02083 /** @example morphology2.cpp 02084 An example using the morphological operations 02085 */ 02086 02087 /** @brief Erodes an image by using a specific structuring element. 02088 02089 The function erodes the source image using the specified structuring element that determines the 02090 shape of a pixel neighborhood over which the minimum is taken: 02091 02092 \f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] 02093 02094 The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In 02095 case of multi-channel images, each channel is processed independently. 02096 02097 @param src input image; the number of channels can be arbitrary, but the depth should be one of 02098 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. 02099 @param dst output image of the same size and type as src. 02100 @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular 02101 structuring element is used. Kernel can be created using getStructuringElement. 02102 @param anchor position of the anchor within the element; default value (-1, -1) means that the 02103 anchor is at the element center. 02104 @param iterations number of times erosion is applied. 02105 @param borderType pixel extrapolation method, see cv::BorderTypes 02106 @param borderValue border value in case of a constant border 02107 @sa dilate, morphologyEx, getStructuringElement 02108 */ 02109 CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, 02110 Point anchor = Point(-1,-1), int iterations = 1, 02111 int borderType = BORDER_CONSTANT, 02112 const Scalar& borderValue = morphologyDefaultBorderValue() ); 02113 02114 /** @brief Dilates an image by using a specific structuring element. 02115 02116 The function dilates the source image using the specified structuring element that determines the 02117 shape of a pixel neighborhood over which the maximum is taken: 02118 \f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] 02119 02120 The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In 02121 case of multi-channel images, each channel is processed independently. 02122 02123 @param src input image; the number of channels can be arbitrary, but the depth should be one of 02124 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. 02125 @param dst output image of the same size and type as src\`. 02126 @param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular 02127 structuring element is used. Kernel can be created using getStructuringElement 02128 @param anchor position of the anchor within the element; default value (-1, -1) means that the 02129 anchor is at the element center. 02130 @param iterations number of times dilation is applied. 02131 @param borderType pixel extrapolation method, see cv::BorderTypes 02132 @param borderValue border value in case of a constant border 02133 @sa erode, morphologyEx, getStructuringElement 02134 */ 02135 CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel, 02136 Point anchor = Point(-1,-1), int iterations = 1, 02137 int borderType = BORDER_CONSTANT, 02138 const Scalar& borderValue = morphologyDefaultBorderValue() ); 02139 02140 /** @brief Performs advanced morphological transformations. 02141 02142 The function morphologyEx can perform advanced morphological transformations using an erosion and dilation as 02143 basic operations. 02144 02145 Any of the operations can be done in-place. In case of multi-channel images, each channel is 02146 processed independently. 02147 02148 @param src Source image. The number of channels can be arbitrary. The depth should be one of 02149 CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. 02150 @param dst Destination image of the same size and type as source image. 02151 @param op Type of a morphological operation, see cv::MorphTypes 02152 @param kernel Structuring element. It can be created using cv::getStructuringElement. 02153 @param anchor Anchor position with the kernel. Negative values mean that the anchor is at the 02154 kernel center. 02155 @param iterations Number of times erosion and dilation are applied. 02156 @param borderType Pixel extrapolation method, see cv::BorderTypes 02157 @param borderValue Border value in case of a constant border. The default value has a special 02158 meaning. 02159 @sa dilate, erode, getStructuringElement 02160 */ 02161 CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, 02162 int op, InputArray kernel, 02163 Point anchor = Point(-1,-1), int iterations = 1, 02164 int borderType = BORDER_CONSTANT, 02165 const Scalar& borderValue = morphologyDefaultBorderValue() ); 02166 02167 //! @} imgproc_filter 02168 02169 //! @addtogroup imgproc_transform 02170 //! @{ 02171 02172 /** @brief Resizes an image. 02173 02174 The function resize resizes the image src down to or up to the specified size. Note that the 02175 initial dst type or size are not taken into account. Instead, the size and type are derived from 02176 the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst, 02177 you may call the function as follows: 02178 @code 02179 // explicitly specify dsize=dst.size(); fx and fy will be computed from that. 02180 resize(src, dst, dst.size(), 0, 0, interpolation); 02181 @endcode 02182 If you want to decimate the image by factor of 2 in each direction, you can call the function this 02183 way: 02184 @code 02185 // specify fx and fy and let the function compute the destination image size. 02186 resize(src, dst, Size(), 0.5, 0.5, interpolation); 02187 @endcode 02188 To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to 02189 enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR 02190 (faster but still looks OK). 02191 02192 @param src input image. 02193 @param dst output image; it has the size dsize (when it is non-zero) or the size computed from 02194 src.size(), fx, and fy; the type of dst is the same as of src. 02195 @param dsize output image size; if it equals zero, it is computed as: 02196 \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] 02197 Either dsize or both fx and fy must be non-zero. 02198 @param fx scale factor along the horizontal axis; when it equals 0, it is computed as 02199 \f[\texttt{(double)dsize.width/src.cols}\f] 02200 @param fy scale factor along the vertical axis; when it equals 0, it is computed as 02201 \f[\texttt{(double)dsize.height/src.rows}\f] 02202 @param interpolation interpolation method, see cv::InterpolationFlags 02203 02204 @sa warpAffine, warpPerspective, remap 02205 */ 02206 CV_EXPORTS_W void resize( InputArray src, OutputArray dst, 02207 Size dsize, double fx = 0, double fy = 0, 02208 int interpolation = INTER_LINEAR ); 02209 02210 /** @brief Applies an affine transformation to an image. 02211 02212 The function warpAffine transforms the source image using the specified matrix: 02213 02214 \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] 02215 02216 when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted 02217 with cv::invertAffineTransform and then put in the formula above instead of M. The function cannot 02218 operate in-place. 02219 02220 @param src input image. 02221 @param dst output image that has the size dsize and the same type as src . 02222 @param M \f$2\times 3\f$ transformation matrix. 02223 @param dsize size of the output image. 02224 @param flags combination of interpolation methods (see cv::InterpolationFlags) and the optional 02225 flag WARP_INVERSE_MAP that means that M is the inverse transformation ( 02226 \f$\texttt{dst}\rightarrow\texttt{src}\f$ ). 02227 @param borderMode pixel extrapolation method (see cv::BorderTypes); when 02228 borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to 02229 the "outliers" in the source image are not modified by the function. 02230 @param borderValue value used in case of a constant border; by default, it is 0. 02231 02232 @sa warpPerspective, resize, remap, getRectSubPix, transform 02233 */ 02234 CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst, 02235 InputArray M, Size dsize, 02236 int flags = INTER_LINEAR, 02237 int borderMode = BORDER_CONSTANT, 02238 const Scalar& borderValue = Scalar()); 02239 02240 /** @brief Applies a perspective transformation to an image. 02241 02242 The function warpPerspective transforms the source image using the specified matrix: 02243 02244 \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}} , 02245 \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f] 02246 02247 when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert 02248 and then put in the formula above instead of M. The function cannot operate in-place. 02249 02250 @param src input image. 02251 @param dst output image that has the size dsize and the same type as src . 02252 @param M \f$3\times 3\f$ transformation matrix. 02253 @param dsize size of the output image. 02254 @param flags combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the 02255 optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation ( 02256 \f$\texttt{dst}\rightarrow\texttt{src}\f$ ). 02257 @param borderMode pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE). 02258 @param borderValue value used in case of a constant border; by default, it equals 0. 02259 02260 @sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform 02261 */ 02262 CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst, 02263 InputArray M, Size dsize, 02264 int flags = INTER_LINEAR, 02265 int borderMode = BORDER_CONSTANT, 02266 const Scalar& borderValue = Scalar()); 02267 02268 /** @brief Applies a generic geometrical transformation to an image. 02269 02270 The function remap transforms the source image using the specified map: 02271 02272 \f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f] 02273 02274 where values of pixels with non-integer coordinates are computed using one of available 02275 interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps 02276 in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in 02277 \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to 02278 convert from floating to fixed-point representations of a map is that they can yield much faster 02279 (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x), 02280 cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients. 02281 02282 This function cannot operate in-place. 02283 02284 @param src Source image. 02285 @param dst Destination image. It has the same size as map1 and the same type as src . 02286 @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 , 02287 CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point 02288 representation to fixed-point for speed. 02289 @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map 02290 if map1 is (x,y) points), respectively. 02291 @param interpolation Interpolation method (see cv::InterpolationFlags). The method INTER_AREA is 02292 not supported by this function. 02293 @param borderMode Pixel extrapolation method (see cv::BorderTypes). When 02294 borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that 02295 corresponds to the "outliers" in the source image are not modified by the function. 02296 @param borderValue Value used in case of a constant border. By default, it is 0. 02297 @note 02298 Due to current implementaion limitations the size of an input and output images should be less than 32767x32767. 02299 */ 02300 CV_EXPORTS_W void remap( InputArray src, OutputArray dst, 02301 InputArray map1, InputArray map2, 02302 int interpolation, int borderMode = BORDER_CONSTANT, 02303 const Scalar& borderValue = Scalar()); 02304 02305 /** @brief Converts image transformation maps from one representation to another. 02306 02307 The function converts a pair of maps for remap from one representation to another. The following 02308 options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are 02309 supported: 02310 02311 - \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the 02312 most frequently used conversion operation, in which the original floating-point maps (see remap ) 02313 are converted to a more compact and much faster fixed-point representation. The first output array 02314 contains the rounded coordinates and the second array (created only when nninterpolation=false ) 02315 contains indices in the interpolation tables. 02316 02317 - \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but 02318 the original maps are stored in one 2-channel matrix. 02319 02320 - Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same 02321 as the originals. 02322 02323 @param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 . 02324 @param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix), 02325 respectively. 02326 @param dstmap1 The first output map that has the type dstmap1type and the same size as src . 02327 @param dstmap2 The second output map. 02328 @param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or 02329 CV_32FC2 . 02330 @param nninterpolation Flag indicating whether the fixed-point maps are used for the 02331 nearest-neighbor or for a more complex interpolation. 02332 02333 @sa remap, undistort, initUndistortRectifyMap 02334 */ 02335 CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2, 02336 OutputArray dstmap1, OutputArray dstmap2, 02337 int dstmap1type, bool nninterpolation = false ); 02338 02339 /** @brief Calculates an affine matrix of 2D rotation. 02340 02341 The function calculates the following matrix: 02342 02343 \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] 02344 02345 where 02346 02347 \f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f] 02348 02349 The transformation maps the rotation center to itself. If this is not the target, adjust the shift. 02350 02351 @param center Center of the rotation in the source image. 02352 @param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the 02353 coordinate origin is assumed to be the top-left corner). 02354 @param scale Isotropic scale factor. 02355 02356 @sa getAffineTransform, warpAffine, transform 02357 */ 02358 CV_EXPORTS_W Mat getRotationMatrix2D( Point2f center, double angle, double scale ); 02359 02360 //! returns 3x3 perspective transformation for the corresponding 4 point pairs. 02361 CV_EXPORTS Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] ); 02362 02363 /** @brief Calculates an affine transform from three pairs of the corresponding points. 02364 02365 The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that: 02366 02367 \f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] 02368 02369 where 02370 02371 \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f] 02372 02373 @param src Coordinates of triangle vertices in the source image. 02374 @param dst Coordinates of the corresponding triangle vertices in the destination image. 02375 02376 @sa warpAffine, transform 02377 */ 02378 CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] ); 02379 02380 /** @brief Inverts an affine transformation. 02381 02382 The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M: 02383 02384 \f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f] 02385 02386 The result is also a \f$2 \times 3\f$ matrix of the same type as M. 02387 02388 @param M Original affine transformation. 02389 @param iM Output reverse affine transformation. 02390 */ 02391 CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM ); 02392 02393 /** @brief Calculates a perspective transform from four pairs of the corresponding points. 02394 02395 The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that: 02396 02397 \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] 02398 02399 where 02400 02401 \f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f] 02402 02403 @param src Coordinates of quadrangle vertices in the source image. 02404 @param dst Coordinates of the corresponding quadrangle vertices in the destination image. 02405 02406 @sa findHomography, warpPerspective, perspectiveTransform 02407 */ 02408 CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst ); 02409 02410 CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); 02411 02412 /** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy. 02413 02414 The function getRectSubPix extracts pixels from src: 02415 02416 \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] 02417 02418 where the values of the pixels at non-integer coordinates are retrieved using bilinear 02419 interpolation. Every channel of multi-channel images is processed independently. While the center of 02420 the rectangle must be inside the image, parts of the rectangle may be outside. In this case, the 02421 replication border mode (see cv::BorderTypes) is used to extrapolate the pixel values outside of 02422 the image. 02423 02424 @param image Source image. 02425 @param patchSize Size of the extracted patch. 02426 @param center Floating point coordinates of the center of the extracted rectangle within the 02427 source image. The center must be inside the image. 02428 @param patch Extracted patch that has the size patchSize and the same number of channels as src . 02429 @param patchType Depth of the extracted pixels. By default, they have the same depth as src . 02430 02431 @sa warpAffine, warpPerspective 02432 */ 02433 CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize, 02434 Point2f center, OutputArray patch, int patchType = -1 ); 02435 02436 /** @example polar_transforms.cpp 02437 An example using the cv::linearPolar and cv::logPolar operations 02438 */ 02439 02440 /** @brief Remaps an image to semilog-polar coordinates space. 02441 02442 Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image"): 02443 \f[\begin{array}{l} 02444 dst( \rho , \phi ) = src(x,y) \\ 02445 dst.size() \leftarrow src.size() 02446 \end{array}\f] 02447 02448 where 02449 \f[\begin{array}{l} 02450 I = (dx,dy) = (x - center.x,y - center.y) \\ 02451 \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\ 02452 \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} \\ 02453 \end{array}\f] 02454 02455 and 02456 \f[\begin{array}{l} 02457 M = src.cols / log_e(maxRadius) \\ 02458 Ky = src.rows / 360 \\ 02459 \end{array}\f] 02460 02461 The function emulates the human "foveal" vision and can be used for fast scale and 02462 rotation-invariant template matching, for object tracking and so forth. 02463 @param src Source image 02464 @param dst Destination image. It will have same size and type as src. 02465 @param center The transformation center; where the output precision is maximal 02466 @param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too. 02467 @param flags A combination of interpolation methods, see cv::InterpolationFlags 02468 02469 @note 02470 - The function can not operate in-place. 02471 - To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. 02472 */ 02473 CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst, 02474 Point2f center, double M, int flags ); 02475 02476 /** @brief Remaps an image to polar coordinates space. 02477 02478 @anchor polar_remaps_reference_image 02479  02480 02481 Transform the source image using the following transformation: 02482 \f[\begin{array}{l} 02483 dst( \rho , \phi ) = src(x,y) \\ 02484 dst.size() \leftarrow src.size() 02485 \end{array}\f] 02486 02487 where 02488 \f[\begin{array}{l} 02489 I = (dx,dy) = (x - center.x,y - center.y) \\ 02490 \rho = Kx \cdot \texttt{magnitude} (I) ,\\ 02491 \phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} 02492 \end{array}\f] 02493 02494 and 02495 \f[\begin{array}{l} 02496 Kx = src.cols / maxRadius \\ 02497 Ky = src.rows / 360 02498 \end{array}\f] 02499 02500 02501 @param src Source image 02502 @param dst Destination image. It will have same size and type as src. 02503 @param center The transformation center; 02504 @param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. 02505 @param flags A combination of interpolation methods, see cv::InterpolationFlags 02506 02507 @note 02508 - The function can not operate in-place. 02509 - To calculate magnitude and angle in degrees @ref cv::cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. 02510 02511 */ 02512 CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst, 02513 Point2f center, double maxRadius, int flags ); 02514 02515 //! @} imgproc_transform 02516 02517 //! @addtogroup imgproc_misc 02518 //! @{ 02519 02520 /** @overload */ 02521 CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 ); 02522 02523 /** @overload */ 02524 CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, 02525 OutputArray sqsum, int sdepth = -1, int sqdepth = -1 ); 02526 02527 /** @brief Calculates the integral of an image. 02528 02529 The function calculates one or more integral images for the source image as follows: 02530 02531 \f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f] 02532 02533 \f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f] 02534 02535 \f[\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)\f] 02536 02537 Using these integral images, you can calculate sum, mean, and standard deviation over a specific 02538 up-right or rotated rectangular region of the image in a constant time, for example: 02539 02540 \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] 02541 02542 It makes possible to do a fast blurring or fast block correlation with a variable window size, for 02543 example. In case of multi-channel images, sums for each channel are accumulated independently. 02544 02545 As a practical example, the next figure shows the calculation of the integral of a straight 02546 rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the 02547 original image are shown, as well as the relative pixels in the integral images sum and tilted . 02548 02549  02550 02551 @param src input image as \f$W \times H\f$, 8-bit or floating-point (32f or 64f). 02552 @param sum integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f). 02553 @param sqsum integral image for squared pixel values; it is \f$(W+1)\times (H+1)\f$, double-precision 02554 floating-point (64f) array. 02555 @param tilted integral for the image rotated by 45 degrees; it is \f$(W+1)\times (H+1)\f$ array with 02556 the same data type as sum. 02557 @param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or 02558 CV_64F. 02559 @param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F. 02560 */ 02561 CV_EXPORTS_AS(integral3) void integral( InputArray src, OutputArray sum, 02562 OutputArray sqsum, OutputArray tilted, 02563 int sdepth = -1, int sqdepth = -1 ); 02564 02565 //! @} imgproc_misc 02566 02567 //! @addtogroup imgproc_motion 02568 //! @{ 02569 02570 /** @brief Adds an image to the accumulator. 02571 02572 The function adds src or some of its elements to dst : 02573 02574 \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] 02575 02576 The function supports multi-channel images. Each channel is processed independently. 02577 02578 The functions accumulate\* can be used, for example, to collect statistics of a scene background 02579 viewed by a still camera and for the further foreground-background segmentation. 02580 02581 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point. 02582 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit 02583 floating-point. 02584 @param mask Optional operation mask. 02585 02586 @sa accumulateSquare, accumulateProduct, accumulateWeighted 02587 */ 02588 CV_EXPORTS_W void accumulate( InputArray src, InputOutputArray dst, 02589 InputArray mask = noArray() ); 02590 02591 /** @brief Adds the square of a source image to the accumulator. 02592 02593 The function adds the input image src or its selected region, raised to a power of 2, to the 02594 accumulator dst : 02595 02596 \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] 02597 02598 The function supports multi-channel images. Each channel is processed independently. 02599 02600 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point. 02601 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit 02602 floating-point. 02603 @param mask Optional operation mask. 02604 02605 @sa accumulateSquare, accumulateProduct, accumulateWeighted 02606 */ 02607 CV_EXPORTS_W void accumulateSquare( InputArray src, InputOutputArray dst, 02608 InputArray mask = noArray() ); 02609 02610 /** @brief Adds the per-element product of two input images to the accumulator. 02611 02612 The function adds the product of two images or their selected regions to the accumulator dst : 02613 02614 \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] 02615 02616 The function supports multi-channel images. Each channel is processed independently. 02617 02618 @param src1 First input image, 1- or 3-channel, 8-bit or 32-bit floating point. 02619 @param src2 Second input image of the same type and the same size as src1 . 02620 @param dst %Accumulator with the same number of channels as input images, 32-bit or 64-bit 02621 floating-point. 02622 @param mask Optional operation mask. 02623 02624 @sa accumulate, accumulateSquare, accumulateWeighted 02625 */ 02626 CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2, 02627 InputOutputArray dst, InputArray mask=noArray() ); 02628 02629 /** @brief Updates a running average. 02630 02631 The function calculates the weighted sum of the input image src and the accumulator dst so that dst 02632 becomes a running average of a frame sequence: 02633 02634 \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] 02635 02636 That is, alpha regulates the update speed (how fast the accumulator "forgets" about earlier images). 02637 The function supports multi-channel images. Each channel is processed independently. 02638 02639 @param src Input image as 1- or 3-channel, 8-bit or 32-bit floating point. 02640 @param dst %Accumulator image with the same number of channels as input image, 32-bit or 64-bit 02641 floating-point. 02642 @param alpha Weight of the input image. 02643 @param mask Optional operation mask. 02644 02645 @sa accumulate, accumulateSquare, accumulateProduct 02646 */ 02647 CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst, 02648 double alpha, InputArray mask = noArray() ); 02649 02650 /** @brief The function is used to detect translational shifts that occur between two images. 02651 02652 The operation takes advantage of the Fourier shift theorem for detecting the translational shift in 02653 the frequency domain. It can be used for fast image registration as well as motion estimation. For 02654 more information please see <http://en.wikipedia.org/wiki/Phase_correlation> 02655 02656 Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed 02657 with getOptimalDFTSize. 02658 02659 The function performs the following equations: 02660 - First it applies a Hanning window (see <http://en.wikipedia.org/wiki/Hann_function>) to each 02661 image to remove possible edge effects. This window is cached until the array size changes to speed 02662 up processing time. 02663 - Next it computes the forward DFTs of each source array: 02664 \f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f] 02665 where \f$\mathcal{F}\f$ is the forward DFT. 02666 - It then computes the cross-power spectrum of each frequency domain array: 02667 \f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f] 02668 - Next the cross-correlation is converted back into the time domain via the inverse DFT: 02669 \f[r = \mathcal{F}^{-1}\{R\}\f] 02670 - Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to 02671 achieve sub-pixel accuracy. 02672 \f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f] 02673 - If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5 02674 centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single 02675 peak) and will be smaller when there are multiple peaks. 02676 02677 @param src1 Source floating point array (CV_32FC1 or CV_64FC1) 02678 @param src2 Source floating point array (CV_32FC1 or CV_64FC1) 02679 @param window Floating point array with windowing coefficients to reduce edge effects (optional). 02680 @param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional). 02681 @returns detected phase shift (sub-pixel) between the two arrays. 02682 02683 @sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow 02684 */ 02685 CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, 02686 InputArray window = noArray(), CV_OUT double* response = 0); 02687 02688 /** @brief This function computes a Hanning window coefficients in two dimensions. 02689 02690 See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function) 02691 for more information. 02692 02693 An example is shown below: 02694 @code 02695 // create hanning window of size 100x100 and type CV_32F 02696 Mat hann; 02697 createHanningWindow(hann, Size(100, 100), CV_32F); 02698 @endcode 02699 @param dst Destination array to place Hann coefficients in 02700 @param winSize The window size specifications 02701 @param type Created array type 02702 */ 02703 CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); 02704 02705 //! @} imgproc_motion 02706 02707 //! @addtogroup imgproc_misc 02708 //! @{ 02709 02710 /** @brief Applies a fixed-level threshold to each array element. 02711 02712 The function applies fixed-level thresholding to a single-channel array. The function is typically 02713 used to get a bi-level (binary) image out of a grayscale image ( cv::compare could be also used for 02714 this purpose) or for removing a noise, that is, filtering out pixels with too small or too large 02715 values. There are several types of thresholding supported by the function. They are determined by 02716 type parameter. 02717 02718 Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the 02719 above values. In these cases, the function determines the optimal threshold value using the Otsu's 02720 or Triangle algorithm and uses it instead of the specified thresh . The function returns the 02721 computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit 02722 images. 02723 02724 @param src input array (single-channel, 8-bit or 32-bit floating point). 02725 @param dst output array of the same size and type as src. 02726 @param thresh threshold value. 02727 @param maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding 02728 types. 02729 @param type thresholding type (see the cv::ThresholdTypes). 02730 02731 @sa adaptiveThreshold, findContours, compare, min, max 02732 */ 02733 CV_EXPORTS_W double threshold( InputArray src, OutputArray dst, 02734 double thresh, double maxval, int type ); 02735 02736 02737 /** @brief Applies an adaptive threshold to an array. 02738 02739 The function transforms a grayscale image to a binary image according to the formulae: 02740 - **THRESH_BINARY** 02741 \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f] 02742 - **THRESH_BINARY_INV** 02743 \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f] 02744 where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter). 02745 02746 The function can process the image in-place. 02747 02748 @param src Source 8-bit single-channel image. 02749 @param dst Destination image of the same size and the same type as src. 02750 @param maxValue Non-zero value assigned to the pixels for which the condition is satisfied 02751 @param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes 02752 @param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV, 02753 see cv::ThresholdTypes. 02754 @param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the 02755 pixel: 3, 5, 7, and so on. 02756 @param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it 02757 is positive but may be zero or negative as well. 02758 02759 @sa threshold, blur, GaussianBlur 02760 */ 02761 CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst, 02762 double maxValue, int adaptiveMethod, 02763 int thresholdType, int blockSize, double C ); 02764 02765 //! @} imgproc_misc 02766 02767 //! @addtogroup imgproc_filter 02768 //! @{ 02769 02770 /** @brief Blurs an image and downsamples it. 02771 02772 By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in 02773 any case, the following conditions should be satisfied: 02774 02775 \f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f] 02776 02777 The function performs the downsampling step of the Gaussian pyramid construction. First, it 02778 convolves the source image with the kernel: 02779 02780 \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] 02781 02782 Then, it downsamples the image by rejecting even rows and columns. 02783 02784 @param src input image. 02785 @param dst output image; it has the specified size and the same type as src. 02786 @param dstsize size of the output image. 02787 @param borderType Pixel extrapolation method, see cv::BorderTypes (BORDER_CONSTANT isn't supported) 02788 */ 02789 CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst, 02790 const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); 02791 02792 /** @brief Upsamples an image and then blurs it. 02793 02794 By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any 02795 case, the following conditions should be satisfied: 02796 02797 \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] 02798 02799 The function performs the upsampling step of the Gaussian pyramid construction, though it can 02800 actually be used to construct the Laplacian pyramid. First, it upsamples the source image by 02801 injecting even zero rows and columns and then convolves the result with the same kernel as in 02802 pyrDown multiplied by 4. 02803 02804 @param src input image. 02805 @param dst output image. It has the specified size and the same type as src . 02806 @param dstsize size of the output image. 02807 @param borderType Pixel extrapolation method, see cv::BorderTypes (only BORDER_DEFAULT is supported) 02808 */ 02809 CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst, 02810 const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); 02811 02812 /** @brief Constructs the Gaussian pyramid for an image. 02813 02814 The function constructs a vector of images and builds the Gaussian pyramid by recursively applying 02815 pyrDown to the previously built pyramid layers, starting from `dst[0]==src`. 02816 02817 @param src Source image. Check pyrDown for the list of supported types. 02818 @param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the 02819 same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on. 02820 @param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative. 02821 @param borderType Pixel extrapolation method, see cv::BorderTypes (BORDER_CONSTANT isn't supported) 02822 */ 02823 CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst, 02824 int maxlevel, int borderType = BORDER_DEFAULT ); 02825 02826 //! @} imgproc_filter 02827 02828 //! @addtogroup imgproc_transform 02829 //! @{ 02830 02831 /** @brief Transforms an image to compensate for lens distortion. 02832 02833 The function transforms an image to compensate radial and tangential lens distortion. 02834 02835 The function is simply a combination of cv::initUndistortRectifyMap (with unity R ) and cv::remap 02836 (with bilinear interpolation). See the former function for details of the transformation being 02837 performed. 02838 02839 Those pixels in the destination image, for which there is no correspondent pixels in the source 02840 image, are filled with zeros (black color). 02841 02842 A particular subset of the source image that will be visible in the corrected image can be regulated 02843 by newCameraMatrix. You can use cv::getOptimalNewCameraMatrix to compute the appropriate 02844 newCameraMatrix depending on your requirements. 02845 02846 The camera matrix and the distortion parameters can be determined using cv::calibrateCamera. If 02847 the resolution of images is different from the resolution used at the calibration stage, \f$f_x, 02848 f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain 02849 the same. 02850 02851 @param src Input (distorted) image. 02852 @param dst Output (corrected) image that has the same size and type as src . 02853 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . 02854 @param distCoeffs Input vector of distortion coefficients 02855 \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$ 02856 of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. 02857 @param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as 02858 cameraMatrix but you may additionally scale and shift the result by using a different matrix. 02859 */ 02860 CV_EXPORTS_W void undistort( InputArray src, OutputArray dst, 02861 InputArray cameraMatrix, 02862 InputArray distCoeffs, 02863 InputArray newCameraMatrix = noArray() ); 02864 02865 /** @brief Computes the undistortion and rectification transformation map. 02866 02867 The function computes the joint undistortion and rectification transformation and represents the 02868 result in the form of maps for remap. The undistorted image looks like original, as if it is 02869 captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a 02870 monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by 02871 cv::getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera, 02872 newCameraMatrix is normally set to P1 or P2 computed by cv::stereoRectify . 02873 02874 Also, this new camera is oriented differently in the coordinate space, according to R. That, for 02875 example, helps to align two heads of a stereo camera so that the epipolar lines on both images 02876 become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera). 02877 02878 The function actually builds the maps for the inverse mapping algorithm that is used by remap. That 02879 is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function 02880 computes the corresponding coordinates in the source image (that is, in the original image from 02881 camera). The following process is applied: 02882 \f[ 02883 \begin{array}{l} 02884 x \leftarrow (u - {c'}_x)/{f'}_x \\ 02885 y \leftarrow (v - {c'}_y)/{f'}_y \\ 02886 {[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ 02887 x' \leftarrow X/W \\ 02888 y' \leftarrow Y/W \\ 02889 r^2 \leftarrow x'^2 + y'^2 \\ 02890 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} 02891 + 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\ 02892 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} 02893 + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ 02894 s\vecthree{x'''}{y'''}{1} = 02895 \vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} 02896 {0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} 02897 {0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ 02898 map_x(u,v) \leftarrow x''' f_x + c_x \\ 02899 map_y(u,v) \leftarrow y''' f_y + c_y 02900 \end{array} 02901 \f] 02902 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$ 02903 are the distortion coefficients. 02904 02905 In case of a stereo camera, this function is called twice: once for each camera head, after 02906 stereoRectify, which in its turn is called after cv::stereoCalibrate. But if the stereo camera 02907 was not calibrated, it is still possible to compute the rectification transformations directly from 02908 the fundamental matrix using cv::stereoRectifyUncalibrated. For each camera, the function computes 02909 homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D 02910 space. R can be computed from H as 02911 \f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] 02912 where cameraMatrix can be chosen arbitrarily. 02913 02914 @param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . 02915 @param distCoeffs Input vector of distortion coefficients 02916 \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$ 02917 of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. 02918 @param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 , 02919 computed by stereoRectify can be passed here. If the matrix is empty, the identity transformation 02920 is assumed. In cvInitUndistortMap R assumed to be an identity matrix. 02921 @param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. 02922 @param size Undistorted image size. 02923 @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2, see cv::convertMaps 02924 @param map1 The first output map. 02925 @param map2 The second output map. 02926 */ 02927 CV_EXPORTS_W void initUndistortRectifyMap( InputArray cameraMatrix, InputArray distCoeffs, 02928 InputArray R, InputArray newCameraMatrix, 02929 Size size, int m1type, OutputArray map1, OutputArray map2 ); 02930 02931 //! initializes maps for cv::remap() for wide-angle 02932 CV_EXPORTS_W float initWideAngleProjMap( InputArray cameraMatrix, InputArray distCoeffs, 02933 Size imageSize, int destImageWidth, 02934 int m1type, OutputArray map1, OutputArray map2, 02935 int projType = PROJ_SPHERICAL_EQRECT, double alpha = 0); 02936 02937 /** @brief Returns the default new camera matrix. 02938 02939 The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when 02940 centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true). 02941 02942 In the latter case, the new camera matrix will be: 02943 02944 \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] 02945 02946 where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively. 02947 02948 By default, the undistortion functions in OpenCV (see initUndistortRectifyMap, undistort) do not 02949 move the principal point. However, when you work with stereo, it is important to move the principal 02950 points in both views to the same y-coordinate (which is required by most of stereo correspondence 02951 algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for 02952 each view where the principal points are located at the center. 02953 02954 @param cameraMatrix Input camera matrix. 02955 @param imgsize Camera view image size in pixels. 02956 @param centerPrincipalPoint Location of the principal point in the new camera matrix. The 02957 parameter indicates whether this location should be at the image center or not. 02958 */ 02959 CV_EXPORTS_W Mat getDefaultNewCameraMatrix( InputArray cameraMatrix, Size imgsize = Size(), 02960 bool centerPrincipalPoint = false ); 02961 02962 /** @brief Computes the ideal point coordinates from the observed point coordinates. 02963 02964 The function is similar to cv::undistort and cv::initUndistortRectifyMap but it operates on a 02965 sparse set of points instead of a raster image. Also the function performs a reverse transformation 02966 to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a 02967 planar object, it does, up to a translation vector, if the proper R is specified. 02968 02969 For each observed point coordinate \f$(u, v)\f$ the function computes: 02970 \f[ 02971 \begin{array}{l} 02972 x^{"} \leftarrow (u - c_x)/f_x \\ 02973 y^{"} \leftarrow (v - c_y)/f_y \\ 02974 (x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ 02975 {[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ 02976 x \leftarrow X/W \\ 02977 y \leftarrow Y/W \\ 02978 \text{only performed if P is specified:} \\ 02979 u' \leftarrow x {f'}_x + {c'}_x \\ 02980 v' \leftarrow y {f'}_y + {c'}_y 02981 \end{array} 02982 \f] 02983 02984 where *undistort* is an approximate iterative algorithm that estimates the normalized original 02985 point coordinates out of the normalized distorted point coordinates ("normalized" means that the 02986 coordinates do not depend on the camera matrix). 02987 02988 The function can be used for both a stereo camera head or a monocular camera (when R is empty). 02989 02990 @param src Observed point coordinates, 1xN or Nx1 2-channel (CV_32FC2 or CV_64FC2). 02991 @param dst Output ideal point coordinates after undistortion and reverse perspective 02992 transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates. 02993 @param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . 02994 @param distCoeffs Input vector of distortion coefficients 02995 \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$ 02996 of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. 02997 @param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by 02998 cv::stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. 02999 @param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by 03000 cv::stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. 03001 */ 03002 CV_EXPORTS_W void undistortPoints( InputArray src, OutputArray dst, 03003 InputArray cameraMatrix, InputArray distCoeffs, 03004 InputArray R = noArray(), InputArray P = noArray()); 03005 03006 //! @} imgproc_transform 03007 03008 //! @addtogroup imgproc_hist 03009 //! @{ 03010 03011 /** @example demhist.cpp 03012 An example for creating histograms of an image 03013 */ 03014 03015 /** @brief Calculates a histogram of a set of arrays. 03016 03017 The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used 03018 to increment a histogram bin are taken from the corresponding input arrays at the same location. The 03019 sample below shows how to compute a 2D Hue-Saturation histogram for a color image. : 03020 @code 03021 #include <opencv2/imgproc.hpp> 03022 #include <opencv2/highgui.hpp> 03023 03024 using namespace cv; 03025 03026 int main( int argc, char** argv ) 03027 { 03028 Mat src, hsv; 03029 if( argc != 2 || !(src=imread(argv[1], 1)).data ) 03030 return -1; 03031 03032 cvtColor(src, hsv, COLOR_BGR2HSV); 03033 03034 // Quantize the hue to 30 levels 03035 // and the saturation to 32 levels 03036 int hbins = 30, sbins = 32; 03037 int histSize[] = {hbins, sbins}; 03038 // hue varies from 0 to 179, see cvtColor 03039 float hranges[] = { 0, 180 }; 03040 // saturation varies from 0 (black-gray-white) to 03041 // 255 (pure spectrum color) 03042 float sranges[] = { 0, 256 }; 03043 const float* ranges[] = { hranges, sranges }; 03044 MatND hist; 03045 // we compute the histogram from the 0-th and 1-st channels 03046 int channels[] = {0, 1}; 03047 03048 calcHist( &hsv, 1, channels, Mat(), // do not use mask 03049 hist, 2, histSize, ranges, 03050 true, // the histogram is uniform 03051 false ); 03052 double maxVal=0; 03053 minMaxLoc(hist, 0, &maxVal, 0, 0); 03054 03055 int scale = 10; 03056 Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3); 03057 03058 for( int h = 0; h < hbins; h++ ) 03059 for( int s = 0; s < sbins; s++ ) 03060 { 03061 float binVal = hist.at<float>(h, s); 03062 int intensity = cvRound(binVal*255/maxVal); 03063 rectangle( histImg, Point(h*scale, s*scale), 03064 Point( (h+1)*scale - 1, (s+1)*scale - 1), 03065 Scalar::all(intensity), 03066 CV_FILLED ); 03067 } 03068 03069 namedWindow( "Source", 1 ); 03070 imshow( "Source", src ); 03071 03072 namedWindow( "H-S Histogram", 1 ); 03073 imshow( "H-S Histogram", histImg ); 03074 waitKey(); 03075 } 03076 @endcode 03077 03078 @param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same 03079 size. Each of them can have an arbitrary number of channels. 03080 @param nimages Number of source images. 03081 @param channels List of the dims channels used to compute the histogram. The first array channels 03082 are numerated from 0 to images[0].channels()-1 , the second array channels are counted from 03083 images[0].channels() to images[0].channels() + images[1].channels()-1, and so on. 03084 @param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size 03085 as images[i] . The non-zero mask elements mark the array elements counted in the histogram. 03086 @param hist Output histogram, which is a dense or sparse dims -dimensional array. 03087 @param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS 03088 (equal to 32 in the current OpenCV version). 03089 @param histSize Array of histogram sizes in each dimension. 03090 @param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the 03091 histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower 03092 (inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary 03093 \f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a 03094 uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform ( 03095 uniform=false ), then each of ranges[i] contains histSize[i]+1 elements: 03096 \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$ 03097 . The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not 03098 counted in the histogram. 03099 @param uniform Flag indicating whether the histogram is uniform or not (see above). 03100 @param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning 03101 when it is allocated. This feature enables you to compute a single histogram from several sets of 03102 arrays, or to update the histogram in time. 03103 */ 03104 CV_EXPORTS void calcHist( const Mat* images, int nimages, 03105 const int* channels, InputArray mask, 03106 OutputArray hist, int dims, const int* histSize, 03107 const float** ranges, bool uniform = true, bool accumulate = false ); 03108 03109 /** @overload 03110 03111 this variant uses cv::SparseMat for output 03112 */ 03113 CV_EXPORTS void calcHist( const Mat* images, int nimages, 03114 const int* channels, InputArray mask, 03115 SparseMat& hist, int dims, 03116 const int* histSize, const float** ranges, 03117 bool uniform = true, bool accumulate = false ); 03118 03119 /** @overload */ 03120 CV_EXPORTS_W void calcHist( InputArrayOfArrays images, 03121 const std::vector<int>& channels, 03122 InputArray mask, OutputArray hist, 03123 const std::vector<int>& histSize, 03124 const std::vector<float>& ranges, 03125 bool accumulate = false ); 03126 03127 /** @brief Calculates the back projection of a histogram. 03128 03129 The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to 03130 cv::calcHist , at each location (x, y) the function collects the values from the selected channels 03131 in the input images and finds the corresponding histogram bin. But instead of incrementing it, the 03132 function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of 03133 statistics, the function computes probability of each element value in respect with the empirical 03134 probability distribution represented by the histogram. See how, for example, you can find and track 03135 a bright-colored object in a scene: 03136 03137 - Before tracking, show the object to the camera so that it covers almost the whole frame. 03138 Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant 03139 colors in the object. 03140 03141 - When tracking, calculate a back projection of a hue plane of each input video frame using that 03142 pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make 03143 sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels. 03144 03145 - Find connected components in the resulting picture and choose, for example, the largest 03146 component. 03147 03148 This is an approximate algorithm of the CamShift color object tracker. 03149 03150 @param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same 03151 size. Each of them can have an arbitrary number of channels. 03152 @param nimages Number of source images. 03153 @param channels The list of channels used to compute the back projection. The number of channels 03154 must match the histogram dimensionality. The first array channels are numerated from 0 to 03155 images[0].channels()-1 , the second array channels are counted from images[0].channels() to 03156 images[0].channels() + images[1].channels()-1, and so on. 03157 @param hist Input histogram that can be dense or sparse. 03158 @param backProject Destination back projection array that is a single-channel array of the same 03159 size and depth as images[0] . 03160 @param ranges Array of arrays of the histogram bin boundaries in each dimension. See cv::calcHist . 03161 @param scale Optional scale factor for the output back projection. 03162 @param uniform Flag indicating whether the histogram is uniform or not (see above). 03163 03164 @sa cv::calcHist, cv::compareHist 03165 */ 03166 CV_EXPORTS void calcBackProject( const Mat* images, int nimages, 03167 const int* channels, InputArray hist, 03168 OutputArray backProject, const float** ranges, 03169 double scale = 1, bool uniform = true ); 03170 03171 /** @overload */ 03172 CV_EXPORTS void calcBackProject( const Mat* images, int nimages, 03173 const int* channels, const SparseMat& hist, 03174 OutputArray backProject, const float** ranges, 03175 double scale = 1, bool uniform = true ); 03176 03177 /** @overload */ 03178 CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector<int>& channels, 03179 InputArray hist, OutputArray dst, 03180 const std::vector<float>& ranges, 03181 double scale ); 03182 03183 /** @brief Compares two histograms. 03184 03185 The function cv::compareHist compares two dense or two sparse histograms using the specified method. 03186 03187 The function returns \f$d(H_1, H_2)\f$ . 03188 03189 While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable 03190 for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling 03191 problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms 03192 or more general sparse configurations of weighted points, consider using the cv::EMD function. 03193 03194 @param H1 First compared histogram. 03195 @param H2 Second compared histogram of the same size as H1 . 03196 @param method Comparison method, see cv::HistCompMethods 03197 */ 03198 CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method ); 03199 03200 /** @overload */ 03201 CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method ); 03202 03203 /** @brief Equalizes the histogram of a grayscale image. 03204 03205 The function equalizes the histogram of the input image using the following algorithm: 03206 03207 - Calculate the histogram \f$H\f$ for src . 03208 - Normalize the histogram so that the sum of histogram bins is 255. 03209 - Compute the integral of the histogram: 03210 \f[H'_i = \sum _{0 \le j < i} H(j)\f] 03211 - Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$ 03212 03213 The algorithm normalizes the brightness and increases the contrast of the image. 03214 03215 @param src Source 8-bit single channel image. 03216 @param dst Destination image of the same size and type as src . 03217 */ 03218 CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); 03219 03220 /** @brief Computes the "minimal work" distance between two weighted point configurations. 03221 03222 The function computes the earth mover distance and/or a lower boundary of the distance between the 03223 two weighted point configurations. One of the applications described in @cite RubnerSept98, 03224 @cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation 03225 problem that is solved using some modification of a simplex algorithm, thus the complexity is 03226 exponential in the worst case, though, on average it is much faster. In the case of a real metric 03227 the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used 03228 to determine roughly whether the two signatures are far enough so that they cannot relate to the 03229 same object. 03230 03231 @param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix. 03232 Each row stores the point weight followed by the point coordinates. The matrix is allowed to have 03233 a single column (weights only) if the user-defined cost matrix is used. The weights must be 03234 non-negative and have at least one non-zero value. 03235 @param signature2 Second signature of the same format as signature1 , though the number of rows 03236 may be different. The total weights may be different. In this case an extra "dummy" point is added 03237 to either signature1 or signature2. The weights must be non-negative and have at least one non-zero 03238 value. 03239 @param distType Used metric. See cv::DistanceTypes. 03240 @param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix 03241 is used, lower boundary lowerBound cannot be calculated because it needs a metric function. 03242 @param lowerBound Optional input/output parameter: lower boundary of a distance between the two 03243 signatures that is a distance between mass centers. The lower boundary may not be calculated if 03244 the user-defined cost matrix is used, the total weights of point configurations are not equal, or 03245 if the signatures consist of weights only (the signature matrices have a single column). You 03246 **must** initialize \*lowerBound . If the calculated distance between mass centers is greater or 03247 equal to \*lowerBound (it means that the signatures are far enough), the function does not 03248 calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on 03249 return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound 03250 should be set to 0. 03251 @param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is 03252 a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 . 03253 */ 03254 CV_EXPORTS float EMD( InputArray signature1, InputArray signature2, 03255 int distType, InputArray cost=noArray(), 03256 float* lowerBound = 0, OutputArray flow = noArray() ); 03257 03258 //! @} imgproc_hist 03259 03260 /** @example watershed.cpp 03261 An example using the watershed algorithm 03262 */ 03263 03264 /** @brief Performs a marker-based image segmentation using the watershed algorithm. 03265 03266 The function implements one of the variants of watershed, non-parametric marker-based segmentation 03267 algorithm, described in @cite Meyer92 . 03268 03269 Before passing the image to the function, you have to roughly outline the desired regions in the 03270 image markers with positive (>0) indices. So, every region is represented as one or more connected 03271 components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary 03272 mask using findContours and drawContours (see the watershed.cpp demo). The markers are "seeds" of 03273 the future image regions. All the other pixels in markers , whose relation to the outlined regions 03274 is not known and should be defined by the algorithm, should be set to 0's. In the function output, 03275 each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the 03276 regions. 03277 03278 @note Any two neighbor connected components are not necessarily separated by a watershed boundary 03279 (-1's pixels); for example, they can touch each other in the initial marker image passed to the 03280 function. 03281 03282 @param image Input 8-bit 3-channel image. 03283 @param markers Input/output 32-bit single-channel image (map) of markers. It should have the same 03284 size as image . 03285 03286 @sa findContours 03287 03288 @ingroup imgproc_misc 03289 */ 03290 CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers ); 03291 03292 //! @addtogroup imgproc_filter 03293 //! @{ 03294 03295 /** @brief Performs initial step of meanshift segmentation of an image. 03296 03297 The function implements the filtering stage of meanshift segmentation, that is, the output of the 03298 function is the filtered "posterized" image with color gradients and fine-grain texture flattened. 03299 At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes 03300 meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is 03301 considered: 03302 03303 \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] 03304 03305 where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively 03306 (though, the algorithm does not depend on the color space used, so any 3-component color space can 03307 be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector 03308 (R',G',B') are found and they act as the neighborhood center on the next iteration: 03309 03310 \f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f] 03311 03312 After the iterations over, the color components of the initial pixel (that is, the pixel from where 03313 the iterations started) are set to the final value (average color at the last iteration): 03314 03315 \f[I(X,Y) <- (R*,G*,B*)\f] 03316 03317 When maxLevel > 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is 03318 run on the smallest layer first. After that, the results are propagated to the larger layer and the 03319 iterations are run again only on those pixels where the layer colors differ by more than sr from the 03320 lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the 03321 results will be actually different from the ones obtained by running the meanshift procedure on the 03322 whole original image (i.e. when maxLevel==0). 03323 03324 @param src The source 8-bit, 3-channel image. 03325 @param dst The destination image of the same format and the same size as the source. 03326 @param sp The spatial window radius. 03327 @param sr The color window radius. 03328 @param maxLevel Maximum level of the pyramid for the segmentation. 03329 @param termcrit Termination criteria: when to stop meanshift iterations. 03330 */ 03331 CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, 03332 double sp, double sr, int maxLevel = 1, 03333 TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) ); 03334 03335 //! @} 03336 03337 //! @addtogroup imgproc_misc 03338 //! @{ 03339 03340 /** @example grabcut.cpp 03341 An example using the GrabCut algorithm 03342 */ 03343 03344 /** @brief Runs the GrabCut algorithm. 03345 03346 The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut). 03347 03348 @param img Input 8-bit 3-channel image. 03349 @param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when 03350 mode is set to GC_INIT_WITH_RECT. Its elements may have one of the cv::GrabCutClasses. 03351 @param rect ROI containing a segmented object. The pixels outside of the ROI are marked as 03352 "obvious background". The parameter is only used when mode==GC_INIT_WITH_RECT . 03353 @param bgdModel Temporary array for the background model. Do not modify it while you are 03354 processing the same image. 03355 @param fgdModel Temporary arrays for the foreground model. Do not modify it while you are 03356 processing the same image. 03357 @param iterCount Number of iterations the algorithm should make before returning the result. Note 03358 that the result can be refined with further calls with mode==GC_INIT_WITH_MASK or 03359 mode==GC_EVAL . 03360 @param mode Operation mode that could be one of the cv::GrabCutModes 03361 */ 03362 CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect, 03363 InputOutputArray bgdModel, InputOutputArray fgdModel, 03364 int iterCount, int mode = GC_EVAL ); 03365 03366 /** @example distrans.cpp 03367 An example on using the distance transform\ 03368 */ 03369 03370 03371 /** @brief Calculates the distance to the closest zero pixel for each pixel of the source image. 03372 03373 The function cv::distanceTransform calculates the approximate or precise distance from every binary 03374 image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero. 03375 03376 When maskSize == DIST_MASK_PRECISE and distanceType == DIST_L2 , the function runs the 03377 algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library. 03378 03379 In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function 03380 finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical, 03381 diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall 03382 distance is calculated as a sum of these basic distances. Since the distance function should be 03383 symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all 03384 the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the 03385 same cost (denoted as `c`). For the cv::DIST_C and cv::DIST_L1 types, the distance is calculated 03386 precisely, whereas for cv::DIST_L2 (Euclidean distance) the distance can be calculated only with a 03387 relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV 03388 uses the values suggested in the original paper: 03389 - DIST_L1: `a = 1, b = 2` 03390 - DIST_L2: 03391 - `3 x 3`: `a=0.955, b=1.3693` 03392 - `5 x 5`: `a=1, b=1.4, c=2.1969` 03393 - DIST_C: `a = 1, b = 1` 03394 03395 Typically, for a fast, coarse distance estimation DIST_L2, a \f$3\times 3\f$ mask is used. For a 03396 more accurate distance estimation DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used. 03397 Note that both the precise and the approximate algorithms are linear on the number of pixels. 03398 03399 This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$ 03400 but also identifies the nearest connected component consisting of zero pixels 03401 (labelType==DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==DIST_LABEL_PIXEL). Index of the 03402 component/pixel is stored in `labels(x, y)`. When labelType==DIST_LABEL_CCOMP, the function 03403 automatically finds connected components of zero pixels in the input image and marks them with 03404 distinct labels. When labelType==DIST_LABEL_CCOMP, the function scans through the input image and 03405 marks all the zero pixels with distinct labels. 03406 03407 In this mode, the complexity is still linear. That is, the function provides a very fast way to 03408 compute the Voronoi diagram for a binary image. Currently, the second variant can use only the 03409 approximate distance transform algorithm, i.e. maskSize=DIST_MASK_PRECISE is not supported 03410 yet. 03411 03412 @param src 8-bit, single-channel (binary) source image. 03413 @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, 03414 single-channel image of the same size as src. 03415 @param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type 03416 CV_32SC1 and the same size as src. 03417 @param distanceType Type of distance, see cv::DistanceTypes 03418 @param maskSize Size of the distance transform mask, see cv::DistanceTransformMasks. 03419 DIST_MASK_PRECISE is not supported by this variant. In case of the DIST_L1 or DIST_C distance type, 03420 the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times 03421 5\f$ or any larger aperture. 03422 @param labelType Type of the label array to build, see cv::DistanceTransformLabelTypes. 03423 */ 03424 CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst, 03425 OutputArray labels, int distanceType, int maskSize, 03426 int labelType = DIST_LABEL_CCOMP ); 03427 03428 /** @overload 03429 @param src 8-bit, single-channel (binary) source image. 03430 @param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, 03431 single-channel image of the same size as src . 03432 @param distanceType Type of distance, see cv::DistanceTypes 03433 @param maskSize Size of the distance transform mask, see cv::DistanceTransformMasks. In case of the 03434 DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives 03435 the same result as \f$5\times 5\f$ or any larger aperture. 03436 @param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for 03437 the first variant of the function and distanceType == DIST_L1. 03438 */ 03439 CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst, 03440 int distanceType, int maskSize, int dstType=CV_32F); 03441 03442 /** @example ffilldemo.cpp 03443 An example using the FloodFill technique 03444 */ 03445 03446 /** @overload 03447 03448 variant without `mask` parameter 03449 */ 03450 CV_EXPORTS int floodFill( InputOutputArray image, 03451 Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0, 03452 Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), 03453 int flags = 4 ); 03454 03455 /** @brief Fills a connected component with the given color. 03456 03457 The function cv::floodFill fills a connected component starting from the seed point with the specified 03458 color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The 03459 pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if: 03460 03461 - in case of a grayscale image and floating range 03462 \f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}\f] 03463 03464 03465 - in case of a grayscale image and fixed range 03466 \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] 03467 03468 03469 - in case of a color image and floating range 03470 \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] 03471 \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] 03472 and 03473 \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] 03474 03475 03476 - in case of a color image and fixed range 03477 \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] 03478 \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] 03479 and 03480 \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] 03481 03482 03483 where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the 03484 component. That is, to be added to the connected component, a color/brightness of the pixel should 03485 be close enough to: 03486 - Color/brightness of one of its neighbors that already belong to the connected component in case 03487 of a floating range. 03488 - Color/brightness of the seed point in case of a fixed range. 03489 03490 Use these functions to either mark a connected component with the specified color in-place, or build 03491 a mask and then extract the contour, or copy the region to another image, and so on. 03492 03493 @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the 03494 function unless the FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See 03495 the details below. 03496 @param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels 03497 taller than image. Since this is both an input and output parameter, you must take responsibility 03498 of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, 03499 an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the 03500 mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags 03501 as described below. It is therefore possible to use the same mask in multiple calls to the function 03502 to make sure the filled areas do not overlap. 03503 @param seedPoint Starting point. 03504 @param newVal New value of the repainted domain pixels. 03505 @param loDiff Maximal lower brightness/color difference between the currently observed pixel and 03506 one of its neighbors belonging to the component, or a seed pixel being added to the component. 03507 @param upDiff Maximal upper brightness/color difference between the currently observed pixel and 03508 one of its neighbors belonging to the component, or a seed pixel being added to the component. 03509 @param rect Optional output parameter set by the function to the minimum bounding rectangle of the 03510 repainted domain. 03511 @param flags Operation flags. The first 8 bits contain a connectivity value. The default value of 03512 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A 03513 connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) 03514 will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill 03515 the mask (the default value is 1). For example, 4 | ( 255 << 8 ) will consider 4 nearest 03516 neighbours and fill the mask with a value of 255. The following additional options occupy higher 03517 bits and therefore may be further combined with the connectivity and mask fill values using 03518 bit-wise or (|), see cv::FloodFillFlags. 03519 03520 @note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the 03521 pixel \f$(x+1, y+1)\f$ in the mask . 03522 03523 @sa findContours 03524 */ 03525 CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask, 03526 Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0, 03527 Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), 03528 int flags = 4 ); 03529 03530 /** @brief Converts an image from one color space to another. 03531 03532 The function converts an input image from one color space to another. In case of a transformation 03533 to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note 03534 that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the 03535 bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue 03536 component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and 03537 sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on. 03538 03539 The conventional ranges for R, G, and B channel values are: 03540 - 0 to 255 for CV_8U images 03541 - 0 to 65535 for CV_16U images 03542 - 0 to 1 for CV_32F images 03543 03544 In case of linear transformations, the range does not matter. But in case of a non-linear 03545 transformation, an input RGB image should be normalized to the proper value range to get the correct 03546 results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a 03547 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will 03548 have the 0..255 value range instead of 0..1 assumed by the function. So, before calling cvtColor , 03549 you need first to scale the image down: 03550 @code 03551 img *= 1./255; 03552 cvtColor(img, img, COLOR_BGR2Luv); 03553 @endcode 03554 If you use cvtColor with 8-bit images, the conversion will have some information lost. For many 03555 applications, this will not be noticeable but it is recommended to use 32-bit images in applications 03556 that need the full range of colors or that convert an image before an operation and then convert 03557 back. 03558 03559 If conversion adds the alpha channel, its value will set to the maximum of corresponding channel 03560 range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F. 03561 03562 @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision 03563 floating-point. 03564 @param dst output image of the same size and depth as src. 03565 @param code color space conversion code (see cv::ColorConversionCodes). 03566 @param dstCn number of channels in the destination image; if the parameter is 0, the number of the 03567 channels is derived automatically from src and code. 03568 03569 @see @ref imgproc_color_conversions 03570 */ 03571 CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 ); 03572 03573 //! @} imgproc_misc 03574 03575 // main function for all demosaicing procceses 03576 CV_EXPORTS_W void demosaicing(InputArray _src, OutputArray _dst, int code, int dcn = 0); 03577 03578 //! @addtogroup imgproc_shape 03579 //! @{ 03580 03581 /** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape. 03582 03583 The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The 03584 results are returned in the structure cv::Moments. 03585 03586 @param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array ( 03587 \f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ). 03588 @param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is 03589 used for images only. 03590 @returns moments. 03591 03592 @note Only applicable to contour moments calculations from Python bindings: Note that the numpy 03593 type for the input array should be either np.int32 or np.float32. 03594 03595 @sa contourArea, arcLength 03596 */ 03597 CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false ); 03598 03599 /** @brief Calculates seven Hu invariants. 03600 03601 The function calculates seven Hu invariants (introduced in @cite Hu62; see also 03602 <http://en.wikipedia.org/wiki/Image_moment>) defined as: 03603 03604 \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] 03605 03606 where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ . 03607 03608 These values are proved to be invariants to the image scale, rotation, and reflection except the 03609 seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of 03610 infinite image resolution. In case of raster images, the computed Hu invariants for the original and 03611 transformed images are a bit different. 03612 03613 @param moments Input moments computed with moments . 03614 @param hu Output Hu invariants. 03615 03616 @sa matchShapes 03617 */ 03618 CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] ); 03619 03620 /** @overload */ 03621 CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu ); 03622 03623 //! @} imgproc_shape 03624 03625 //! @addtogroup imgproc_object 03626 //! @{ 03627 03628 //! type of the template matching operation 03629 enum TemplateMatchModes { 03630 TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f] 03631 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] 03632 TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f] 03633 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] 03634 TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f] 03635 //!< where 03636 //!< \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] 03637 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] 03638 }; 03639 03640 /** @brief Compares a template against overlapped image regions. 03641 03642 The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against 03643 templ using the specified method and stores the comparison results in result . Here are the formulae 03644 for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation 03645 is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$ 03646 03647 After the function finishes the comparison, the best matches can be found as global minimums (when 03648 TM_SQDIFF was used) or maximums (when TM_CCORR or TM_CCOEFF was used) using the 03649 minMaxLoc function. In case of a color image, template summation in the numerator and each sum in 03650 the denominator is done over all of the channels and separate mean values are used for each channel. 03651 That is, the function can take a color template and a color image. The result will still be a 03652 single-channel image, which is easier to analyze. 03653 03654 @param image Image where the search is running. It must be 8-bit or 32-bit floating-point. 03655 @param templ Searched template. It must be not greater than the source image and have the same 03656 data type. 03657 @param result Map of comparison results. It must be single-channel 32-bit floating-point. If image 03658 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$ . 03659 @param method Parameter specifying the comparison method, see cv::TemplateMatchModes 03660 @param mask Mask of searched template. It must have the same datatype and size with templ. It is 03661 not set by default. 03662 */ 03663 CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, 03664 OutputArray result, int method, InputArray mask = noArray() ); 03665 03666 //! @} 03667 03668 //! @addtogroup imgproc_shape 03669 //! @{ 03670 03671 /** @brief computes the connected components labeled image of boolean image 03672 03673 image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 03674 represents the background label. ltype specifies the output label image type, an important 03675 consideration based on the total number of labels or alternatively the total number of pixels in 03676 the source image. ccltype specifies the connected components labeling algorithm to use, currently 03677 Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes 03678 for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. 03679 03680 @param image the 8-bit single-channel image to be labeled 03681 @param labels destination labeled image 03682 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively 03683 @param ltype output image label type. Currently CV_32S and CV_16U are supported. 03684 @param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes). 03685 */ 03686 CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels, 03687 int connectivity, int ltype, int ccltype); 03688 03689 03690 /** @overload 03691 03692 @param image the 8-bit single-channel image to be labeled 03693 @param labels destination labeled image 03694 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively 03695 @param ltype output image label type. Currently CV_32S and CV_16U are supported. 03696 */ 03697 CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels, 03698 int connectivity = 8, int ltype = CV_32S); 03699 03700 03701 /** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label 03702 03703 image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 03704 represents the background label. ltype specifies the output label image type, an important 03705 consideration based on the total number of labels or alternatively the total number of pixels in 03706 the source image. ccltype specifies the connected components labeling algorithm to use, currently 03707 Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes 03708 for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. 03709 03710 03711 @param image the 8-bit single-channel image to be labeled 03712 @param labels destination labeled image 03713 @param stats statistics output for each label, including the background label, see below for 03714 available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of 03715 cv::ConnectedComponentsTypes. The data type is CV_32S. 03716 @param centroids centroid output for each label, including the background label. Centroids are 03717 accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. 03718 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively 03719 @param ltype output image label type. Currently CV_32S and CV_16U are supported. 03720 @param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes). 03721 */ 03722 CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels, 03723 OutputArray stats, OutputArray centroids, 03724 int connectivity, int ltype, int ccltype); 03725 03726 /** @overload 03727 @param image the 8-bit single-channel image to be labeled 03728 @param labels destination labeled image 03729 @param stats statistics output for each label, including the background label, see below for 03730 available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of 03731 cv::ConnectedComponentsTypes. The data type is CV_32S. 03732 @param centroids centroid output for each label, including the background label. Centroids are 03733 accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. 03734 @param connectivity 8 or 4 for 8-way or 4-way connectivity respectively 03735 @param ltype output image label type. Currently CV_32S and CV_16U are supported. 03736 */ 03737 CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels, 03738 OutputArray stats, OutputArray centroids, 03739 int connectivity = 8, int ltype = CV_32S); 03740 03741 03742 /** @brief Finds contours in a binary image. 03743 03744 The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours 03745 are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the 03746 OpenCV sample directory. 03747 03748 @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero 03749 pixels remain 0's, so the image is treated as binary . You can use cv::compare, cv::inRange, cv::threshold , 03750 cv::adaptiveThreshold, cv::Canny, and others to create a binary image out of a grayscale or color one. 03751 If mode equals to cv::RETR_CCOMP or cv::RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). 03752 @param contours Detected contours. Each contour is stored as a vector of points (e.g. 03753 std::vector<std::vector<cv::Point> >). 03754 @param hierarchy Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has 03755 as many elements as the number of contours. For each i-th contour contours[i], the elements 03756 hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices 03757 in contours of the next and previous contours at the same hierarchical level, the first child 03758 contour and the parent contour, respectively. If for the contour i there are no next, previous, 03759 parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. 03760 @param mode Contour retrieval mode, see cv::RetrievalModes 03761 @param method Contour approximation method, see cv::ContourApproximationModes 03762 @param offset Optional offset by which every contour point is shifted. This is useful if the 03763 contours are extracted from the image ROI and then they should be analyzed in the whole image 03764 context. 03765 */ 03766 CV_EXPORTS_W void findContours( InputOutputArray image, OutputArrayOfArrays contours, 03767 OutputArray hierarchy, int mode, 03768 int method, Point offset = Point()); 03769 03770 /** @overload */ 03771 CV_EXPORTS void findContours( InputOutputArray image, OutputArrayOfArrays contours, 03772 int mode, int method, Point offset = Point()); 03773 03774 /** @brief Approximates a polygonal curve(s) with the specified precision. 03775 03776 The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less 03777 vertices so that the distance between them is less or equal to the specified precision. It uses the 03778 Douglas-Peucker algorithm <http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm> 03779 03780 @param curve Input vector of a 2D point stored in std::vector or Mat 03781 @param approxCurve Result of the approximation. The type should match the type of the input curve. 03782 @param epsilon Parameter specifying the approximation accuracy. This is the maximum distance 03783 between the original curve and its approximation. 03784 @param closed If true, the approximated curve is closed (its first and last vertices are 03785 connected). Otherwise, it is not closed. 03786 */ 03787 CV_EXPORTS_W void approxPolyDP( InputArray curve, 03788 OutputArray approxCurve, 03789 double epsilon, bool closed ); 03790 03791 /** @brief Calculates a contour perimeter or a curve length. 03792 03793 The function computes a curve length or a closed contour perimeter. 03794 03795 @param curve Input vector of 2D points, stored in std::vector or Mat. 03796 @param closed Flag indicating whether the curve is closed or not. 03797 */ 03798 CV_EXPORTS_W double arcLength( InputArray curve, bool closed ); 03799 03800 /** @brief Calculates the up-right bounding rectangle of a point set. 03801 03802 The function calculates and returns the minimal up-right bounding rectangle for the specified point set. 03803 03804 @param points Input 2D point set, stored in std::vector or Mat. 03805 */ 03806 CV_EXPORTS_W Rect boundingRect( InputArray points ); 03807 03808 /** @brief Calculates a contour area. 03809 03810 The function computes a contour area. Similarly to moments , the area is computed using the Green 03811 formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using 03812 drawContours or fillPoly , can be different. Also, the function will most certainly give a wrong 03813 results for contours with self-intersections. 03814 03815 Example: 03816 @code 03817 vector<Point> contour; 03818 contour.push_back(Point2f(0, 0)); 03819 contour.push_back(Point2f(10, 0)); 03820 contour.push_back(Point2f(10, 10)); 03821 contour.push_back(Point2f(5, 4)); 03822 03823 double area0 = contourArea(contour); 03824 vector<Point> approx; 03825 approxPolyDP(contour, approx, 5, true); 03826 double area1 = contourArea(approx); 03827 03828 cout << "area0 =" << area0 << endl << 03829 "area1 =" << area1 << endl << 03830 "approx poly vertices" << approx.size() << endl; 03831 @endcode 03832 @param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat. 03833 @param oriented Oriented area flag. If it is true, the function returns a signed area value, 03834 depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can 03835 determine orientation of a contour by taking the sign of an area. By default, the parameter is 03836 false, which means that the absolute value is returned. 03837 */ 03838 CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false ); 03839 03840 /** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set. 03841 03842 The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a 03843 specified point set. See the OpenCV sample minarea.cpp . Developer should keep in mind that the 03844 returned rotatedRect can contain negative indices when data is close to the containing Mat element 03845 boundary. 03846 03847 @param points Input vector of 2D points, stored in std::vector<> or Mat 03848 */ 03849 CV_EXPORTS_W RotatedRect minAreaRect( InputArray points ); 03850 03851 /** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle. 03852 03853 The function finds the four vertices of a rotated rectangle. This function is useful to draw the 03854 rectangle. In C++, instead of using this function, you can directly use box.points() method. Please 03855 visit the [tutorial on bounding 03856 rectangle](http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html#bounding-rects-circles) 03857 for more information. 03858 03859 @param box The input rotated rectangle. It may be the output of 03860 @param points The output array of four vertices of rectangles. 03861 */ 03862 CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points); 03863 03864 /** @brief Finds a circle of the minimum area enclosing a 2D point set. 03865 03866 The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. See 03867 the OpenCV sample minarea.cpp . 03868 03869 @param points Input vector of 2D points, stored in std::vector<> or Mat 03870 @param center Output center of the circle. 03871 @param radius Output radius of the circle. 03872 */ 03873 CV_EXPORTS_W void minEnclosingCircle( InputArray points, 03874 CV_OUT Point2f& center, CV_OUT float& radius ); 03875 03876 /** @example minarea.cpp 03877 */ 03878 03879 /** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area. 03880 03881 The function finds a triangle of minimum area enclosing the given set of 2D points and returns its 03882 area. The output for a given 2D point set is shown in the image below. 2D points are depicted in 03883 *red* and the enclosing triangle in *yellow*. 03884 03885  03886 03887 The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's 03888 @cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal 03889 enclosing triangle of a 2D convex polygon with n vertices. Since the minEnclosingTriangle function 03890 takes a 2D point set as input an additional preprocessing step of computing the convex hull of the 03891 2D point set is required. The complexity of the convexHull function is \f$O(n log(n))\f$ which is higher 03892 than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$. 03893 03894 @param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector<> or Mat 03895 @param triangle Output vector of three 2D points defining the vertices of the triangle. The depth 03896 of the OutputArray must be CV_32F. 03897 */ 03898 CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle ); 03899 03900 /** @brief Compares two shapes. 03901 03902 The function compares two shapes. All three implemented methods use the Hu invariants (see cv::HuMoments) 03903 03904 @param contour1 First contour or grayscale image. 03905 @param contour2 Second contour or grayscale image. 03906 @param method Comparison method, see ::ShapeMatchModes 03907 @param parameter Method-specific parameter (not supported now). 03908 */ 03909 CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2, 03910 int method, double parameter ); 03911 03912 /** @example convexhull.cpp 03913 An example using the convexHull functionality 03914 */ 03915 03916 /** @brief Finds the convex hull of a point set. 03917 03918 The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82 03919 that has *O(N logN)* complexity in the current implementation. See the OpenCV sample convexhull.cpp 03920 that demonstrates the usage of different function variants. 03921 03922 @param points Input 2D point set, stored in std::vector or Mat. 03923 @param hull Output convex hull. It is either an integer vector of indices or vector of points. In 03924 the first case, the hull elements are 0-based indices of the convex hull points in the original 03925 array (since the set of convex hull points is a subset of the original point set). In the second 03926 case, hull elements are the convex hull points themselves. 03927 @param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise. 03928 Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing 03929 to the right, and its Y axis pointing upwards. 03930 @param returnPoints Operation flag. In case of a matrix, when the flag is true, the function 03931 returns convex hull points. Otherwise, it returns indices of the convex hull points. When the 03932 output array is std::vector, the flag is ignored, and the output depends on the type of the 03933 vector: std::vector<int> implies returnPoints=false, std::vector<Point> implies 03934 returnPoints=true. 03935 */ 03936 CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull, 03937 bool clockwise = false, bool returnPoints = true ); 03938 03939 /** @brief Finds the convexity defects of a contour. 03940 03941 The figure below displays convexity defects of a hand contour: 03942 03943  03944 03945 @param contour Input contour. 03946 @param convexhull Convex hull obtained using convexHull that should contain indices of the contour 03947 points that make the hull. 03948 @param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java 03949 interface each convexity defect is represented as 4-element integer vector (a.k.a. cv::Vec4i): 03950 (start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices 03951 in the original contour of the convexity defect beginning, end and the farthest point, and 03952 fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the 03953 farthest contour point and the hull. That is, to get the floating-point value of the depth will be 03954 fixpt_depth/256.0. 03955 */ 03956 CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects ); 03957 03958 /** @brief Tests a contour convexity. 03959 03960 The function tests whether the input contour is convex or not. The contour must be simple, that is, 03961 without self-intersections. Otherwise, the function output is undefined. 03962 03963 @param contour Input vector of 2D points, stored in std::vector<> or Mat 03964 */ 03965 CV_EXPORTS_W bool isContourConvex( InputArray contour ); 03966 03967 //! finds intersection of two convex polygons 03968 CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2, 03969 OutputArray _p12, bool handleNested = true ); 03970 03971 /** @example fitellipse.cpp 03972 An example using the fitEllipse technique 03973 */ 03974 03975 /** @brief Fits an ellipse around a set of 2D points. 03976 03977 The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of 03978 all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon95 03979 is used. Developer should keep in mind that it is possible that the returned 03980 ellipse/rotatedRect data contains negative indices, due to the data points being close to the 03981 border of the containing Mat element. 03982 03983 @param points Input 2D point set, stored in std::vector<> or Mat 03984 */ 03985 CV_EXPORTS_W RotatedRect fitEllipse( InputArray points ); 03986 03987 /** @brief Fits a line to a 2D or 3D point set. 03988 03989 The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where 03990 \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 03991 of the following: 03992 - DIST_L2 03993 \f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f] 03994 - DIST_L1 03995 \f[\rho (r) = r\f] 03996 - DIST_L12 03997 \f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f] 03998 - DIST_FAIR 03999 \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] 04000 - DIST_WELSCH 04001 \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] 04002 - DIST_HUBER 04003 \f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f] 04004 04005 The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique 04006 that iteratively fits the line using the weighted least-squares algorithm. After each iteration the 04007 weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ . 04008 04009 @param points Input vector of 2D or 3D points, stored in std::vector<> or Mat. 04010 @param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements 04011 (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and 04012 (x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like 04013 Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line 04014 and (x0, y0, z0) is a point on the line. 04015 @param distType Distance used by the M-estimator, see cv::DistanceTypes 04016 @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value 04017 is chosen. 04018 @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line). 04019 @param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps. 04020 */ 04021 CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType, 04022 double param, double reps, double aeps ); 04023 04024 /** @brief Performs a point-in-contour test. 04025 04026 The function determines whether the point is inside a contour, outside, or lies on an edge (or 04027 coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) 04028 value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively. 04029 Otherwise, the return value is a signed distance between the point and the nearest contour edge. 04030 04031 See below a sample output of the function where each image pixel is tested against the contour: 04032 04033  04034 04035 @param contour Input contour. 04036 @param pt Point tested against the contour. 04037 @param measureDist If true, the function estimates the signed distance from the point to the 04038 nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not. 04039 */ 04040 CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist ); 04041 04042 /** @brief Finds out if there is any intersection between two rotated rectangles. 04043 04044 If there is then the vertices of the interesecting region are returned as well. 04045 04046 Below are some examples of intersection configurations. The hatched pattern indicates the 04047 intersecting region and the red vertices are returned by the function. 04048 04049  04050 04051 @param rect1 First rectangle 04052 @param rect2 Second rectangle 04053 @param intersectingRegion The output array of the verticies of the intersecting region. It returns 04054 at most 8 vertices. Stored as std::vector<cv::Point2f> or cv::Mat as Mx1 of type CV_32FC2. 04055 @returns One of cv::RectanglesIntersectTypes 04056 */ 04057 CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ); 04058 04059 //! @} imgproc_shape 04060 04061 CV_EXPORTS_W Ptr<CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); 04062 04063 //! Ballard, D.H. (1981). Generalizing the Hough transform to detect arbitrary shapes. Pattern Recognition 13 (2): 111-122. 04064 //! Detects position only without traslation and rotation 04065 CV_EXPORTS Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard(); 04066 04067 //! 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. 04068 //! Detects position, traslation and rotation 04069 CV_EXPORTS Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil(); 04070 04071 //! Performs linear blending of two images 04072 CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); 04073 04074 //! @addtogroup imgproc_colormap 04075 //! @{ 04076 04077 //! GNU Octave/MATLAB equivalent colormaps 04078 enum ColormapTypes 04079 { 04080 COLORMAP_AUTUMN = 0, //!<  04081 COLORMAP_BONE = 1, //!<  04082 COLORMAP_JET = 2, //!<  04083 COLORMAP_WINTER = 3, //!<  04084 COLORMAP_RAINBOW = 4, //!<  04085 COLORMAP_OCEAN = 5, //!<  04086 COLORMAP_SUMMER = 6, //!<  04087 COLORMAP_SPRING = 7, //!<  04088 COLORMAP_COOL = 8, //!<  04089 COLORMAP_HSV = 9, //!<  04090 COLORMAP_PINK = 10, //!<  04091 COLORMAP_HOT = 11, //!<  04092 COLORMAP_PARULA = 12 //!<  04093 }; 04094 04095 /** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image. 04096 04097 @param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. 04098 @param dst The result is the colormapped source image. Note: Mat::create is called on dst. 04099 @param colormap The colormap to apply, see cv::ColormapTypes 04100 */ 04101 CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); 04102 04103 //! @} imgproc_colormap 04104 04105 //! @addtogroup imgproc_draw 04106 //! @{ 04107 04108 /** @brief Draws a line segment connecting two points. 04109 04110 The function line draws the line segment between pt1 and pt2 points in the image. The line is 04111 clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected 04112 or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased 04113 lines are drawn using Gaussian filtering. 04114 04115 @param img Image. 04116 @param pt1 First point of the line segment. 04117 @param pt2 Second point of the line segment. 04118 @param color Line color. 04119 @param thickness Line thickness. 04120 @param lineType Type of the line, see cv::LineTypes. 04121 @param shift Number of fractional bits in the point coordinates. 04122 */ 04123 CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, 04124 int thickness = 1, int lineType = LINE_8, int shift = 0); 04125 04126 /** @brief Draws a arrow segment pointing from the first point to the second one. 04127 04128 The function arrowedLine draws an arrow between pt1 and pt2 points in the image. See also cv::line. 04129 04130 @param img Image. 04131 @param pt1 The point the arrow starts from. 04132 @param pt2 The point the arrow points to. 04133 @param color Line color. 04134 @param thickness Line thickness. 04135 @param line_type Type of the line, see cv::LineTypes 04136 @param shift Number of fractional bits in the point coordinates. 04137 @param tipLength The length of the arrow tip in relation to the arrow length 04138 */ 04139 CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, 04140 int thickness=1, int line_type=8, int shift=0, double tipLength=0.1); 04141 04142 /** @brief Draws a simple, thick, or filled up-right rectangle. 04143 04144 The function rectangle draws a rectangle outline or a filled rectangle whose two opposite corners 04145 are pt1 and pt2. 04146 04147 @param img Image. 04148 @param pt1 Vertex of the rectangle. 04149 @param pt2 Vertex of the rectangle opposite to pt1 . 04150 @param color Rectangle color or brightness (grayscale image). 04151 @param thickness Thickness of lines that make up the rectangle. Negative values, like CV_FILLED , 04152 mean that the function has to draw a filled rectangle. 04153 @param lineType Type of the line. See the line description. 04154 @param shift Number of fractional bits in the point coordinates. 04155 */ 04156 CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2, 04157 const Scalar& color, int thickness = 1, 04158 int lineType = LINE_8, int shift = 0); 04159 04160 /** @overload 04161 04162 use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and 04163 r.br()-Point(1,1)` are opposite corners 04164 */ 04165 CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec, 04166 const Scalar& color, int thickness = 1, 04167 int lineType = LINE_8, int shift = 0); 04168 04169 /** @brief Draws a circle. 04170 04171 The function circle draws a simple or filled circle with a given center and radius. 04172 @param img Image where the circle is drawn. 04173 @param center Center of the circle. 04174 @param radius Radius of the circle. 04175 @param color Circle color. 04176 @param thickness Thickness of the circle outline, if positive. Negative thickness means that a 04177 filled circle is to be drawn. 04178 @param lineType Type of the circle boundary. See the line description. 04179 @param shift Number of fractional bits in the coordinates of the center and in the radius value. 04180 */ 04181 CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius, 04182 const Scalar& color, int thickness = 1, 04183 int lineType = LINE_8, int shift = 0); 04184 04185 /** @brief Draws a simple or thick elliptic arc or fills an ellipse sector. 04186 04187 The function cv::ellipse with less parameters draws an ellipse outline, a filled ellipse, an elliptic 04188 arc, or a filled ellipse sector. A piecewise-linear curve is used to approximate the elliptic arc 04189 boundary. If you need more control of the ellipse rendering, you can retrieve the curve using 04190 ellipse2Poly and then render it with polylines or fill it with fillPoly . If you use the first 04191 variant of the function and want to draw the whole ellipse, not an arc, pass startAngle=0 and 04192 endAngle=360 . The figure below explains the meaning of the parameters. 04193 04194  04195 04196 @param img Image. 04197 @param center Center of the ellipse. 04198 @param axes Half of the size of the ellipse main axes. 04199 @param angle Ellipse rotation angle in degrees. 04200 @param startAngle Starting angle of the elliptic arc in degrees. 04201 @param endAngle Ending angle of the elliptic arc in degrees. 04202 @param color Ellipse color. 04203 @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that 04204 a filled ellipse sector is to be drawn. 04205 @param lineType Type of the ellipse boundary. See the line description. 04206 @param shift Number of fractional bits in the coordinates of the center and values of axes. 04207 */ 04208 CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes, 04209 double angle, double startAngle, double endAngle, 04210 const Scalar& color, int thickness = 1, 04211 int lineType = LINE_8, int shift = 0); 04212 04213 /** @overload 04214 @param img Image. 04215 @param box Alternative ellipse representation via RotatedRect. This means that the function draws 04216 an ellipse inscribed in the rotated rectangle. 04217 @param color Ellipse color. 04218 @param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that 04219 a filled ellipse sector is to be drawn. 04220 @param lineType Type of the ellipse boundary. See the line description. 04221 */ 04222 CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color, 04223 int thickness = 1, int lineType = LINE_8); 04224 04225 /* ----------------------------------------------------------------------------------------- */ 04226 /* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */ 04227 /* ----------------------------------------------------------------------------------------- */ 04228 04229 //! Possible set of marker types used for the cv::drawMarker function 04230 enum MarkerTypes 04231 { 04232 MARKER_CROSS = 0, //!< A crosshair marker shape 04233 MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape 04234 MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross 04235 MARKER_DIAMOND = 3, //!< A diamond marker shape 04236 MARKER_SQUARE = 4, //!< A square marker shape 04237 MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape 04238 MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape 04239 }; 04240 04241 /** @brief Draws a marker on a predefined position in an image. 04242 04243 The function drawMarker draws a marker on a given position in the image. For the moment several 04244 marker types are supported, see cv::MarkerTypes for more information. 04245 04246 @param img Image. 04247 @param position The point where the crosshair is positioned. 04248 @param color Line color. 04249 @param markerType The specific type of marker you want to use, see cv::MarkerTypes 04250 @param thickness Line thickness. 04251 @param line_type Type of the line, see cv::LineTypes 04252 @param markerSize The length of the marker axis [default = 20 pixels] 04253 */ 04254 CV_EXPORTS_W void drawMarker(CV_IN_OUT Mat& img, Point position, const Scalar& color, 04255 int markerType = MARKER_CROSS, int markerSize=20, int thickness=1, 04256 int line_type=8); 04257 04258 /* ----------------------------------------------------------------------------------------- */ 04259 /* END OF MARKER SECTION */ 04260 /* ----------------------------------------------------------------------------------------- */ 04261 04262 /** @overload */ 04263 CV_EXPORTS void fillConvexPoly (Mat& img, const Point* pts, int npts, 04264 const Scalar& color, int lineType = LINE_8, 04265 int shift = 0); 04266 04267 /** @brief Fills a convex polygon. 04268 04269 The function fillConvexPoly draws a filled convex polygon. This function is much faster than the 04270 function cv::fillPoly . It can fill not only convex polygons but any monotonic polygon without 04271 self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line) 04272 twice at the most (though, its top-most and/or the bottom edge could be horizontal). 04273 04274 @param img Image. 04275 @param points Polygon vertices. 04276 @param color Polygon color. 04277 @param lineType Type of the polygon boundaries. See the line description. 04278 @param shift Number of fractional bits in the vertex coordinates. 04279 */ 04280 CV_EXPORTS_W void fillConvexPoly (InputOutputArray img, InputArray points, 04281 const Scalar& color, int lineType = LINE_8, 04282 int shift = 0); 04283 04284 /** @overload */ 04285 CV_EXPORTS void fillPoly (Mat& img, const Point** pts, 04286 const int* npts, int ncontours, 04287 const Scalar& color, int lineType = LINE_8, int shift = 0, 04288 Point offset = Point() ); 04289 04290 /** @brief Fills the area bounded by one or more polygons. 04291 04292 The function fillPoly fills an area bounded by several polygonal contours. The function can fill 04293 complex areas, for example, areas with holes, contours with self-intersections (some of their 04294 parts), and so forth. 04295 04296 @param img Image. 04297 @param pts Array of polygons where each polygon is represented as an array of points. 04298 @param color Polygon color. 04299 @param lineType Type of the polygon boundaries. See the line description. 04300 @param shift Number of fractional bits in the vertex coordinates. 04301 @param offset Optional offset of all points of the contours. 04302 */ 04303 CV_EXPORTS_W void fillPoly (InputOutputArray img, InputArrayOfArrays pts, 04304 const Scalar& color, int lineType = LINE_8, int shift = 0, 04305 Point offset = Point() ); 04306 04307 /** @overload */ 04308 CV_EXPORTS void polylines (Mat& img, const Point* const* pts, const int* npts, 04309 int ncontours, bool isClosed, const Scalar& color, 04310 int thickness = 1, int lineType = LINE_8, int shift = 0 ); 04311 04312 /** @brief Draws several polygonal curves. 04313 04314 @param img Image. 04315 @param pts Array of polygonal curves. 04316 @param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed, 04317 the function draws a line from the last vertex of each curve to its first vertex. 04318 @param color Polyline color. 04319 @param thickness Thickness of the polyline edges. 04320 @param lineType Type of the line segments. See the line description. 04321 @param shift Number of fractional bits in the vertex coordinates. 04322 04323 The function polylines draws one or more polygonal curves. 04324 */ 04325 CV_EXPORTS_W void polylines (InputOutputArray img, InputArrayOfArrays pts, 04326 bool isClosed, const Scalar& color, 04327 int thickness = 1, int lineType = LINE_8, int shift = 0 ); 04328 04329 /** @example contours2.cpp 04330 An example using the drawContour functionality 04331 */ 04332 04333 /** @example segment_objects.cpp 04334 An example using drawContours to clean up a background segmentation result 04335 */ 04336 04337 /** @brief Draws contours outlines or filled contours. 04338 04339 The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area 04340 bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve 04341 connected components from the binary image and label them: : 04342 @code 04343 #include "opencv2/imgproc.hpp" 04344 #include "opencv2/highgui.hpp" 04345 04346 using namespace cv; 04347 using namespace std; 04348 04349 int main( int argc, char** argv ) 04350 { 04351 Mat src; 04352 // the first command-line parameter must be a filename of the binary 04353 // (black-n-white) image 04354 if( argc != 2 || !(src=imread(argv[1], 0)).data) 04355 return -1; 04356 04357 Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3); 04358 04359 src = src > 1; 04360 namedWindow( "Source", 1 ); 04361 imshow( "Source", src ); 04362 04363 vector<vector<Point> > contours; 04364 vector<Vec4i> hierarchy; 04365 04366 findContours( src, contours, hierarchy, 04367 RETR_CCOMP, CHAIN_APPROX_SIMPLE ); 04368 04369 // iterate through all the top-level contours, 04370 // draw each connected component with its own random color 04371 int idx = 0; 04372 for( ; idx >= 0; idx = hierarchy[idx][0] ) 04373 { 04374 Scalar color( rand()&255, rand()&255, rand()&255 ); 04375 drawContours( dst, contours, idx, color, FILLED, 8, hierarchy ); 04376 } 04377 04378 namedWindow( "Components", 1 ); 04379 imshow( "Components", dst ); 04380 waitKey(0); 04381 } 04382 @endcode 04383 04384 @param image Destination image. 04385 @param contours All the input contours. Each contour is stored as a point vector. 04386 @param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn. 04387 @param color Color of the contours. 04388 @param thickness Thickness of lines the contours are drawn with. If it is negative (for example, 04389 thickness=CV_FILLED ), the contour interiors are drawn. 04390 @param lineType Line connectivity. See cv::LineTypes. 04391 @param hierarchy Optional information about hierarchy. It is only needed if you want to draw only 04392 some of the contours (see maxLevel ). 04393 @param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn. 04394 If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function 04395 draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This 04396 parameter is only taken into account when there is hierarchy available. 04397 @param offset Optional contour shift parameter. Shift all the drawn contours by the specified 04398 \f$\texttt{offset}=(dx,dy)\f$ . 04399 */ 04400 CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, 04401 int contourIdx, const Scalar& color, 04402 int thickness = 1, int lineType = LINE_8, 04403 InputArray hierarchy = noArray(), 04404 int maxLevel = INT_MAX, Point offset = Point() ); 04405 04406 /** @brief Clips the line against the image rectangle. 04407 04408 The function cv::clipLine calculates a part of the line segment that is entirely within the specified 04409 rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise, 04410 it returns true . 04411 @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . 04412 @param pt1 First line point. 04413 @param pt2 Second line point. 04414 */ 04415 CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); 04416 04417 /** @overload 04418 @param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . 04419 @param pt1 First line point. 04420 @param pt2 Second line point. 04421 */ 04422 CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2); 04423 04424 /** @overload 04425 @param imgRect Image rectangle. 04426 @param pt1 First line point. 04427 @param pt2 Second line point. 04428 */ 04429 CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2); 04430 04431 /** @brief Approximates an elliptic arc with a polyline. 04432 04433 The function ellipse2Poly computes the vertices of a polyline that approximates the specified 04434 elliptic arc. It is used by cv::ellipse. 04435 04436 @param center Center of the arc. 04437 @param axes Half of the size of the ellipse main axes. See the ellipse for details. 04438 @param angle Rotation angle of the ellipse in degrees. See the ellipse for details. 04439 @param arcStart Starting angle of the elliptic arc in degrees. 04440 @param arcEnd Ending angle of the elliptic arc in degrees. 04441 @param delta Angle between the subsequent polyline vertices. It defines the approximation 04442 accuracy. 04443 @param pts Output vector of polyline vertices. 04444 */ 04445 CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, 04446 int arcStart, int arcEnd, int delta, 04447 CV_OUT std::vector<Point>& pts ); 04448 04449 /** @overload 04450 @param center Center of the arc. 04451 @param axes Half of the size of the ellipse main axes. See the ellipse for details. 04452 @param angle Rotation angle of the ellipse in degrees. See the ellipse for details. 04453 @param arcStart Starting angle of the elliptic arc in degrees. 04454 @param arcEnd Ending angle of the elliptic arc in degrees. 04455 @param delta Angle between the subsequent polyline vertices. It defines the approximation 04456 accuracy. 04457 @param pts Output vector of polyline vertices. 04458 */ 04459 CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle, 04460 int arcStart, int arcEnd, int delta, 04461 CV_OUT std::vector<Point2d>& pts); 04462 04463 /** @brief Draws a text string. 04464 04465 The function putText renders the specified text string in the image. Symbols that cannot be rendered 04466 using the specified font are replaced by question marks. See getTextSize for a text rendering code 04467 example. 04468 04469 @param img Image. 04470 @param text Text string to be drawn. 04471 @param org Bottom-left corner of the text string in the image. 04472 @param fontFace Font type, see cv::HersheyFonts. 04473 @param fontScale Font scale factor that is multiplied by the font-specific base size. 04474 @param color Text color. 04475 @param thickness Thickness of the lines used to draw a text. 04476 @param lineType Line type. See the line for details. 04477 @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, 04478 it is at the top-left corner. 04479 */ 04480 CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org, 04481 int fontFace, double fontScale, Scalar color, 04482 int thickness = 1, int lineType = LINE_8, 04483 bool bottomLeftOrigin = false ); 04484 04485 /** @brief Calculates the width and height of a text string. 04486 04487 The function getTextSize calculates and returns the size of a box that contains the specified text. 04488 That is, the following code renders some text, the tight box surrounding it, and the baseline: : 04489 @code 04490 String text = "Funny text inside the box"; 04491 int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; 04492 double fontScale = 2; 04493 int thickness = 3; 04494 04495 Mat img(600, 800, CV_8UC3, Scalar::all(0)); 04496 04497 int baseline=0; 04498 Size textSize = getTextSize(text, fontFace, 04499 fontScale, thickness, &baseline); 04500 baseline += thickness; 04501 04502 // center the text 04503 Point textOrg((img.cols - textSize.width)/2, 04504 (img.rows + textSize.height)/2); 04505 04506 // draw the box 04507 rectangle(img, textOrg + Point(0, baseline), 04508 textOrg + Point(textSize.width, -textSize.height), 04509 Scalar(0,0,255)); 04510 // ... and the baseline first 04511 line(img, textOrg + Point(0, thickness), 04512 textOrg + Point(textSize.width, thickness), 04513 Scalar(0, 0, 255)); 04514 04515 // then put the text itself 04516 putText(img, text, textOrg, fontFace, fontScale, 04517 Scalar::all(255), thickness, 8); 04518 @endcode 04519 04520 @param text Input text string. 04521 @param fontFace Font to use, see cv::HersheyFonts. 04522 @param fontScale Font scale factor that is multiplied by the font-specific base size. 04523 @param thickness Thickness of lines used to render the text. See putText for details. 04524 @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text 04525 point. 04526 @return The size of a box that contains the specified text. 04527 04528 @see cv::putText 04529 */ 04530 CV_EXPORTS_W Size getTextSize(const String& text, int fontFace, 04531 double fontScale, int thickness, 04532 CV_OUT int* baseLine); 04533 04534 /** @brief Line iterator 04535 04536 The class is used to iterate over all the pixels on the raster line 04537 segment connecting two specified points. 04538 04539 The class LineIterator is used to get each pixel of a raster line. It 04540 can be treated as versatile implementation of the Bresenham algorithm 04541 where you can stop at each pixel and do some extra processing, for 04542 example, grab pixel values along the line or draw a line with an effect 04543 (for example, with XOR operation). 04544 04545 The number of pixels along the line is stored in LineIterator::count. 04546 The method LineIterator::pos returns the current position in the image: 04547 04548 @code{.cpp} 04549 // grabs pixels along the line (pt1, pt2) 04550 // from 8-bit 3-channel image to the buffer 04551 LineIterator it(img, pt1, pt2, 8); 04552 LineIterator it2 = it; 04553 vector<Vec3b> buf(it.count); 04554 04555 for(int i = 0; i < it.count; i++, ++it) 04556 buf[i] = *(const Vec3b)*it; 04557 04558 // alternative way of iterating through the line 04559 for(int i = 0; i < it2.count; i++, ++it2) 04560 { 04561 Vec3b val = img.at<Vec3b>(it2.pos()); 04562 CV_Assert(buf[i] == val); 04563 } 04564 @endcode 04565 */ 04566 class CV_EXPORTS LineIterator 04567 { 04568 public: 04569 /** @brief intializes the iterator 04570 04571 creates iterators for the line connecting pt1 and pt2 04572 the line will be clipped on the image boundaries 04573 the line is 8-connected or 4-connected 04574 If leftToRight=true, then the iteration is always done 04575 from the left-most point to the right most, 04576 not to depend on the ordering of pt1 and pt2 parameters 04577 */ 04578 LineIterator( const Mat& img, Point pt1, Point pt2, 04579 int connectivity = 8, bool leftToRight = false ); 04580 /** @brief returns pointer to the current pixel 04581 */ 04582 uchar* operator *(); 04583 /** @brief prefix increment operator (++it). shifts iterator to the next pixel 04584 */ 04585 LineIterator& operator ++(); 04586 /** @brief postfix increment operator (it++). shifts iterator to the next pixel 04587 */ 04588 LineIterator operator ++(int); 04589 /** @brief returns coordinates of the current pixel 04590 */ 04591 Point pos() const; 04592 04593 uchar* ptr; 04594 const uchar* ptr0; 04595 int step, elemSize; 04596 int err, count; 04597 int minusDelta, plusDelta; 04598 int minusStep, plusStep; 04599 }; 04600 04601 //! @cond IGNORED 04602 04603 // === LineIterator implementation === 04604 04605 inline 04606 uchar* LineIterator::operator *() 04607 { 04608 return ptr; 04609 } 04610 04611 inline 04612 LineIterator& LineIterator::operator ++() 04613 { 04614 int mask = err < 0 ? -1 : 0; 04615 err += minusDelta + (plusDelta & mask); 04616 ptr += minusStep + (plusStep & mask); 04617 return *this; 04618 } 04619 04620 inline 04621 LineIterator LineIterator::operator ++(int) 04622 { 04623 LineIterator it = *this; 04624 ++(*this); 04625 return it; 04626 } 04627 04628 inline 04629 Point LineIterator::pos() const 04630 { 04631 Point p; 04632 p.y = (int)((ptr - ptr0)/step); 04633 p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize); 04634 return p; 04635 } 04636 04637 //! @endcond 04638 04639 //! @} imgproc_draw 04640 04641 //! @} imgproc 04642 04643 } // cv 04644 04645 #ifndef DISABLE_OPENCV_24_COMPATIBILITY 04646 #include "opencv2/imgproc/imgproc_c.h" 04647 #endif 04648 04649 #endif
Generated on Tue Jul 12 2022 18:20:17 by
