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