CLAHE Python bindings
[profile/ivi/opencv.git] / modules / imgproc / doc / feature_detection.rst
1 Feature Detection
2 =================
3
4 .. highlight:: cpp
5
6
7
8 Canny
9 ---------
10 Finds edges in an image using the [Canny86]_ algorithm.
11
12 .. ocv:function:: void Canny( InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false )
13
14 .. ocv:pyfunction:: cv2.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) -> edges
15
16 .. ocv:cfunction:: void cvCanny( const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3 )
17
18 .. ocv:pyoldfunction:: cv.Canny(image, edges, threshold1, threshold2, aperture_size=3) -> None
19
20     :param image: single-channel 8-bit input image.
21
22     :param edges: output edge map; it has the same size and type as  ``image`` .
23
24     :param threshold1: first threshold for the hysteresis procedure.
25
26     :param threshold2: second threshold for the hysteresis procedure.
27
28     :param apertureSize: aperture size for the :ocv:func:`Sobel` operator.
29
30     :param L2gradient: a flag, indicating whether a more accurate  :math:`L_2`  norm  :math:`=\sqrt{(dI/dx)^2 + (dI/dy)^2}`  should be used to calculate the image gradient magnitude ( ``L2gradient=true`` ), or whether the default  :math:`L_1`  norm  :math:`=|dI/dx|+|dI/dy|`  is enough ( ``L2gradient=false`` ).
31
32 The function finds edges in the input image ``image`` and marks them in the output map ``edges`` using the Canny algorithm. The smallest value between ``threshold1`` and ``threshold2`` is used for edge linking. The largest value is used to find initial segments of strong edges. See
33 http://en.wikipedia.org/wiki/Canny_edge_detector
34
35
36
37 cornerEigenValsAndVecs
38 ----------------------
39 Calculates eigenvalues and eigenvectors of image blocks for corner detection.
40
41 .. ocv:function:: void cornerEigenValsAndVecs( InputArray src, OutputArray dst, int blockSize, int ksize, int borderType=BORDER_DEFAULT )
42
43 .. ocv:pyfunction:: cv2.cornerEigenValsAndVecs(src, blockSize, ksize[, dst[, borderType]]) -> dst
44
45 .. ocv:cfunction:: void cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv, int block_size, int aperture_size=3 )
46
47 .. ocv:pyoldfunction:: cv.CornerEigenValsAndVecs(image, eigenvv, blockSize, aperture_size=3) -> None
48
49     :param src: Input single-channel 8-bit or floating-point image.
50
51     :param dst: Image to store the results. It has the same size as  ``src``  and the type  ``CV_32FC(6)`` .
52
53     :param blockSize: Neighborhood size (see details below).
54
55     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
56
57     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
58
59 For every pixel
60 :math:`p` , the function ``cornerEigenValsAndVecs`` considers a ``blockSize`` :math:`\times` ``blockSize`` neighborhood
61 :math:`S(p)` . It calculates the covariation matrix of derivatives over the neighborhood as:
62
63 .. math::
64
65     M =  \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 &  \sum _{S(p)}(dI/dx dI/dy)^2  \\ \sum _{S(p)}(dI/dx dI/dy)^2 &  \sum _{S(p)}(dI/dy)^2 \end{bmatrix}
66
67 where the derivatives are computed using the
68 :ocv:func:`Sobel` operator.
69
70 After that, it finds eigenvectors and eigenvalues of
71 :math:`M` and stores them in the destination image as
72 :math:`(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)` where
73
74 * :math:`\lambda_1, \lambda_2` are the non-sorted eigenvalues of :math:`M`
75
76 * :math:`x_1, y_1` are the eigenvectors corresponding to :math:`\lambda_1`
77
78 * :math:`x_2, y_2` are the eigenvectors corresponding to :math:`\lambda_2`
79
80 The output of the function can be used for robust edge or corner detection.
81
82 .. seealso::
83
84     :ocv:func:`cornerMinEigenVal`,
85     :ocv:func:`cornerHarris`,
86     :ocv:func:`preCornerDetect`
87
88
89
90 cornerHarris
91 ------------
92 Harris edge detector.
93
94 .. ocv:function:: void cornerHarris( InputArray src, OutputArray dst, int blockSize, int ksize, double k, int borderType=BORDER_DEFAULT )
95
96 .. ocv:pyfunction:: cv2.cornerHarris(src, blockSize, ksize, k[, dst[, borderType]]) -> dst
97
98 .. ocv:cfunction:: void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 )
99
100 .. ocv:pyoldfunction:: cv.CornerHarris(image, harris_dst, blockSize, aperture_size=3, k=0.04) -> None
101
102     :param src: Input single-channel 8-bit or floating-point image.
103
104     :param dst: Image to store the Harris detector responses. It has the type  ``CV_32FC1``  and the same size as  ``src`` .
105
106     :param blockSize: Neighborhood size (see the details on  :ocv:func:`cornerEigenValsAndVecs` ).
107
108     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
109
110     :param k: Harris detector free parameter. See the formula below.
111
112     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
113
114 The function runs the Harris edge detector on the image. Similarly to
115 :ocv:func:`cornerMinEigenVal` and
116 :ocv:func:`cornerEigenValsAndVecs` , for each pixel
117 :math:`(x, y)` it calculates a
118 :math:`2\times2` gradient covariance matrix
119 :math:`M^{(x,y)}` over a
120 :math:`\texttt{blockSize} \times \texttt{blockSize}` neighborhood. Then, it computes the following characteristic:
121
122 .. math::
123
124     \texttt{dst} (x,y) =  \mathrm{det} M^{(x,y)} - k  \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2
125
126 Corners in the image can be found as the local maxima of this response map.
127
128
129
130 cornerMinEigenVal
131 -----------------
132 Calculates the minimal eigenvalue of gradient matrices for corner detection.
133
134 .. ocv:function:: void cornerMinEigenVal( InputArray src, OutputArray dst, int blockSize, int ksize=3, int borderType=BORDER_DEFAULT )
135
136 .. ocv:pyfunction:: cv2.cornerMinEigenVal(src, blockSize[, dst[, ksize[, borderType]]]) -> dst
137
138 .. ocv:cfunction:: void cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, int block_size, int aperture_size=3 )
139
140 .. ocv:pyoldfunction:: cv.CornerMinEigenVal(image, eigenval, blockSize, aperture_size=3) -> None
141
142     :param src: Input single-channel 8-bit or floating-point image.
143
144     :param dst: Image to store the minimal eigenvalues. It has the type  ``CV_32FC1``  and the same size as  ``src`` .
145
146     :param blockSize: Neighborhood size (see the details on  :ocv:func:`cornerEigenValsAndVecs` ).
147
148     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
149
150     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
151
152 The function is similar to
153 :ocv:func:`cornerEigenValsAndVecs` but it calculates and stores only the minimal eigenvalue of the covariance matrix of derivatives, that is,
154 :math:`\min(\lambda_1, \lambda_2)` in terms of the formulae in the
155 :ocv:func:`cornerEigenValsAndVecs` description.
156
157
158
159 cornerSubPix
160 ----------------
161 Refines the corner locations.
162
163 .. ocv:function:: void cornerSubPix( InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria )
164
165 .. ocv:pyfunction:: cv2.cornerSubPix(image, corners, winSize, zeroZone, criteria) -> None
166
167 .. ocv:cfunction:: void cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, int count, CvSize win, CvSize zero_zone, CvTermCriteria criteria )
168
169 .. ocv:pyoldfunction:: cv.FindCornerSubPix(image, corners, win, zero_zone, criteria) -> corners
170
171     :param image: Input image.
172
173     :param corners: Initial coordinates of the input corners and refined coordinates provided for output.
174
175     :param winSize: Half of the side length of the search window. For example, if  ``winSize=Size(5,5)`` , then a  :math:`5*2+1 \times 5*2+1 = 11 \times 11`  search window is used.
176
177     :param zeroZone: Half of the size of the dead region in the middle of the search zone over which the summation in the formula below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such a size.
178
179     :param criteria: Criteria for termination of the iterative process of corner refinement. That is, the process of corner position refinement stops either after ``criteria.maxCount`` iterations or when the corner position moves by less than ``criteria.epsilon`` on some iteration.
180
181 The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as shown on the figure below.
182
183 .. image:: pics/cornersubpix.png
184
185 Sub-pixel accurate corner locator is based on the observation that every vector from the center
186 :math:`q` to a point
187 :math:`p` located within a neighborhood of
188 :math:`q` is orthogonal to the image gradient at
189 :math:`p` subject to image and measurement noise. Consider the expression:
190
191 .. math::
192
193     \epsilon _i = {DI_{p_i}}^T  \cdot (q - p_i)
194
195 where
196 :math:`{DI_{p_i}}` is an image gradient at one of the points
197 :math:`p_i` in a neighborhood of
198 :math:`q` . The value of
199 :math:`q` is to be found so that
200 :math:`\epsilon_i` is minimized. A system of equations may be set up with
201 :math:`\epsilon_i` set to zero:
202
203 .. math::
204
205     \sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T) -  \sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T  \cdot p_i)
206
207 where the gradients are summed within a neighborhood ("search window") of
208 :math:`q` . Calling the first gradient term
209 :math:`G` and the second gradient term
210 :math:`b` gives:
211
212 .. math::
213
214     q = G^{-1}  \cdot b
215
216 The algorithm sets the center of the neighborhood window at this new center
217 :math:`q` and then iterates until the center stays within a set threshold.
218
219
220
221 goodFeaturesToTrack
222 -------------------
223 Determines strong corners on an image.
224
225 .. ocv:function:: void goodFeaturesToTrack( InputArray image, OutputArray corners, int maxCorners, double qualityLevel, double minDistance, InputArray mask=noArray(), int blockSize=3, bool useHarrisDetector=false, double k=0.04 )
226
227 .. ocv:pyfunction:: cv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]]) -> corners
228
229 .. ocv:cfunction:: void cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, CvArr* temp_image, CvPoint2D32f* corners, int* corner_count, double quality_level, double min_distance, const CvArr* mask=NULL, int block_size=3, int use_harris=0, double k=0.04 )
230
231 .. ocv:pyoldfunction:: cv.GoodFeaturesToTrack(image, eigImage, tempImage, cornerCount, qualityLevel, minDistance, mask=None, blockSize=3, useHarris=0, k=0.04) -> cornerCount
232
233     :param image: Input 8-bit or floating-point 32-bit, single-channel image.
234
235     :param eig_image: The parameter is ignored.
236
237     :param temp_image: The parameter is ignored.
238
239     :param corners: Output vector of detected corners.
240
241     :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned.
242
243     :param qualityLevel: Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see  :ocv:func:`cornerMinEigenVal` ) or the Harris function response (see  :ocv:func:`cornerHarris` ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the  ``qualityLevel=0.01`` , then all the corners with the quality measure less than 15 are rejected.
244
245     :param minDistance: Minimum possible Euclidean distance between the returned corners.
246
247     :param mask: Optional region of interest. If the image is not empty (it needs to have the type  ``CV_8UC1``  and the same size as  ``image`` ), it  specifies the region in which the corners are detected.
248
249     :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See  :ocv:func:`cornerEigenValsAndVecs` .
250
251     :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`cornerHarris`) or :ocv:func:`cornerMinEigenVal`.
252
253     :param k: Free parameter of the Harris detector.
254
255 The function finds the most prominent corners in the image or in the specified image region, as described in [Shi94]_:
256
257 #.
258     Function calculates the corner quality measure at every source image pixel using the
259     :ocv:func:`cornerMinEigenVal`     or
260     :ocv:func:`cornerHarris` .
261
262 #.
263     Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are retained).
264
265 #.
266     The corners with the minimal eigenvalue less than
267     :math:`\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)`   are rejected.
268
269 #.
270     The remaining corners are sorted by the quality measure in the descending order.
271
272 #.
273     Function throws away each corner for which there is a stronger corner at a distance less than ``maxDistance``.
274
275 The function can be used to initialize a point-based tracker of an object.
276
277 .. note:: If the function is called with different values ``A`` and ``B`` of the parameter ``qualityLevel`` , and ``A`` > {B}, the vector of returned corners with ``qualityLevel=A`` will be the prefix of the output vector with ``qualityLevel=B`` .
278
279 .. seealso::
280
281     :ocv:func:`cornerMinEigenVal`,
282     :ocv:func:`cornerHarris`,
283     :ocv:func:`calcOpticalFlowPyrLK`,
284     :ocv:func:`estimateRigidTransform`,
285
286
287 HoughCircles
288 ------------
289 Finds circles in a grayscale image using the Hough transform.
290
291 .. ocv:function:: void HoughCircles( InputArray image, OutputArray circles, int method, double dp, double minDist, double param1=100, double param2=100, int minRadius=0, int maxRadius=0 )
292
293 .. ocv:cfunction:: CvSeq* cvHoughCircles( CvArr* image, void* circle_storage, int method, double dp, double min_dist, double param1=100, double param2=100, int min_radius=0, int max_radius=0 )
294
295 .. ocv:pyfunction:: cv2.HoughCircles(image, method, dp, minDist[, circles[, param1[, param2[, minRadius[, maxRadius]]]]]) -> circles
296
297     :param image: 8-bit, single-channel, grayscale input image.
298
299     :param circles: Output vector of found circles. Each vector is encoded as a 3-element floating-point vector  :math:`(x, y, radius)` .
300
301     :param circle_storage: In C function this is a memory storage that will contain the output sequence of found circles.
302
303     :param method: Detection method to use. Currently, the only implemented method is  ``CV_HOUGH_GRADIENT`` , which is basically  *21HT* , described in  [Yuen90]_.
304
305     :param dp: Inverse ratio of the accumulator resolution to the image resolution. For example, if  ``dp=1`` , the accumulator has the same resolution as the input image. If  ``dp=2`` , the accumulator has half as big width and height.
306
307     :param minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
308
309     :param param1: First method-specific parameter. In case of  ``CV_HOUGH_GRADIENT`` , it is the higher threshold of the two passed to  the :ocv:func:`Canny`  edge detector (the lower one is twice smaller).
310
311     :param param2: Second method-specific parameter. In case of  ``CV_HOUGH_GRADIENT`` , it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
312
313     :param minRadius: Minimum circle radius.
314
315     :param maxRadius: Maximum circle radius.
316
317 The function finds circles in a grayscale image using a modification of the Hough transform.
318
319 Example: ::
320
321     #include <cv.h>
322     #include <highgui.h>
323     #include <math.h>
324
325     using namespace cv;
326
327     int main(int argc, char** argv)
328     {
329         Mat img, gray;
330         if( argc != 2 && !(img=imread(argv[1], 1)).data)
331             return -1;
332         cvtColor(img, gray, CV_BGR2GRAY);
333         // smooth it, otherwise a lot of false circles may be detected
334         GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
335         vector<Vec3f> circles;
336         HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
337                      2, gray->rows/4, 200, 100 );
338         for( size_t i = 0; i < circles.size(); i++ )
339         {
340              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
341              int radius = cvRound(circles[i][2]);
342              // draw the circle center
343              circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
344              // draw the circle outline
345              circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
346         }
347         namedWindow( "circles", 1 );
348         imshow( "circles", img );
349         return 0;
350     }
351
352 .. note:: Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range ( ``minRadius`` and ``maxRadius`` ) if you know it. Or, you may ignore the returned radius, use only the center, and find the correct radius using an additional procedure.
353
354 .. seealso::
355
356     :ocv:func:`fitEllipse`,
357     :ocv:func:`minEnclosingCircle`
358
359
360 HoughLines
361 ----------
362 Finds lines in a binary image using the standard Hough transform.
363
364 .. ocv:function:: void HoughLines( InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0 )
365
366 .. ocv:pyfunction:: cv2.HoughLines(image, rho, theta, threshold[, lines[, srn[, stn]]]) -> lines
367
368 .. ocv:cfunction:: CvSeq* cvHoughLines2( CvArr* image, void* line_storage, int method, double rho, double theta, int threshold, double param1=0, double param2=0 )
369
370 .. ocv:pyoldfunction:: cv.HoughLines2(image, storage, method, rho, theta, threshold, param1=0, param2=0)-> lines
371
372     :param image: 8-bit, single-channel binary source image. The image may be modified by the function.
373
374     :param lines: Output vector of lines. Each line is represented by a two-element vector  :math:`(\rho, \theta)` .  :math:`\rho`  is the distance from the coordinate origin  :math:`(0,0)`  (top-left corner of the image).  :math:`\theta`  is the line rotation angle in radians ( :math:`0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}` ).
375
376     :param rho: Distance resolution of the accumulator in pixels.
377
378     :param theta: Angle resolution of the accumulator in radians.
379
380     :param threshold: Accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` ).
381
382     :param srn: For the multi-scale Hough transform, it is a divisor for the distance resolution  ``rho`` . The coarse accumulator distance resolution is  ``rho``  and the accurate accumulator resolution is  ``rho/srn`` . If both  ``srn=0``  and  ``stn=0`` , the classical Hough transform is used. Otherwise, both these parameters should be positive.
383
384     :param stn: For the multi-scale Hough transform, it is a divisor for the distance resolution  ``theta``.
385
386     :param method: One of the following Hough transform variants:
387
388             * **CV_HOUGH_STANDARD** classical or standard Hough transform. Every line is represented by two floating-point numbers  :math:`(\rho, \theta)` , where  :math:`\rho`  is a distance between (0,0) point and the line, and  :math:`\theta`  is the angle between x-axis and the normal to the line. Thus, the matrix must be (the created sequence will be) of  ``CV_32FC2``  type
389
390
391             * **CV_HOUGH_PROBABILISTIC** probabilistic Hough transform (more efficient in case if the picture contains a few long linear segments). It returns line segments rather than the whole line. Each segment is represented by starting and ending points, and the matrix must be (the created sequence will be) of  the ``CV_32SC4``  type.
392
393             * **CV_HOUGH_MULTI_SCALE** multi-scale variant of the classical Hough transform. The lines are encoded the same way as  ``CV_HOUGH_STANDARD``.
394
395
396     :param param1: First method-dependent parameter:
397
398         *  For the classical Hough transform, it is not used (0).
399
400         *  For the probabilistic Hough transform, it is the minimum line length.
401
402         *  For the multi-scale Hough transform, it is ``srn``.
403
404     :param param2: Second method-dependent parameter:
405
406         *  For the classical Hough transform, it is not used (0).
407
408         *  For the probabilistic Hough transform, it is the maximum gap between line segments lying on the same line to treat them as a single line segment (that is, to join them).
409
410         *  For the multi-scale Hough transform, it is ``stn``.
411
412 The function implements the standard or standard multi-scale Hough transform algorithm for line detection.  See http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm for a good explanation of Hough transform.
413 See also the example in :ocv:func:`HoughLinesP` description.
414
415 HoughLinesP
416 -----------
417 Finds line segments in a binary image using the probabilistic Hough transform.
418
419 .. ocv:function:: void HoughLinesP( InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 )
420
421 .. ocv:pyfunction:: cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]]) -> lines
422
423     :param image: 8-bit, single-channel binary source image. The image may be modified by the function.
424
425     :param lines: Output vector of lines. Each line is represented by a 4-element vector  :math:`(x_1, y_1, x_2, y_2)` , where  :math:`(x_1,y_1)`  and  :math:`(x_2, y_2)`  are the ending points of each detected line segment.
426
427     :param rho: Distance resolution of the accumulator in pixels.
428
429     :param theta: Angle resolution of the accumulator in radians.
430
431     :param threshold: Accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` ).
432
433     :param minLineLength: Minimum line length. Line segments shorter than that are rejected.
434
435     :param maxLineGap: Maximum allowed gap between points on the same line to link them.
436
437 The function implements the probabilistic Hough transform algorithm for line detection, described in
438 [Matas00]_. See the line detection example below: ::
439
440     /* This is a standalone program. Pass an image name as the first parameter
441     of the program.  Switch between standard and probabilistic Hough transform
442     by changing "#if 1" to "#if 0" and back */
443     #include <cv.h>
444     #include <highgui.h>
445     #include <math.h>
446
447     using namespace cv;
448
449     int main(int argc, char** argv)
450     {
451         Mat src, dst, color_dst;
452         if( argc != 2 || !(src=imread(argv[1], 0)).data)
453             return -1;
454
455         Canny( src, dst, 50, 200, 3 );
456         cvtColor( dst, color_dst, CV_GRAY2BGR );
457
458     #if 0
459         vector<Vec2f> lines;
460         HoughLines( dst, lines, 1, CV_PI/180, 100 );
461
462         for( size_t i = 0; i < lines.size(); i++ )
463         {
464             float rho = lines[i][0];
465             float theta = lines[i][1];
466             double a = cos(theta), b = sin(theta);
467             double x0 = a*rho, y0 = b*rho;
468             Point pt1(cvRound(x0 + 1000*(-b)),
469                       cvRound(y0 + 1000*(a)));
470             Point pt2(cvRound(x0 - 1000*(-b)),
471                       cvRound(y0 - 1000*(a)));
472             line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 );
473         }
474     #else
475         vector<Vec4i> lines;
476         HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
477         for( size_t i = 0; i < lines.size(); i++ )
478         {
479             line( color_dst, Point(lines[i][0], lines[i][1]),
480                 Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
481         }
482     #endif
483         namedWindow( "Source", 1 );
484         imshow( "Source", src );
485
486         namedWindow( "Detected Lines", 1 );
487         imshow( "Detected Lines", color_dst );
488
489         waitKey(0);
490         return 0;
491     }
492
493 This is a sample picture the function parameters have been tuned for:
494
495 .. image:: pics/building.jpg
496
497 And this is the output of the above program in case of the probabilistic Hough transform:
498
499 .. image:: pics/houghp.png
500
501
502
503 preCornerDetect
504 ---------------
505 Calculates a feature map for corner detection.
506
507 .. ocv:function:: void preCornerDetect( InputArray src, OutputArray dst, int ksize, int borderType=BORDER_DEFAULT )
508
509 .. ocv:pyfunction:: cv2.preCornerDetect(src, ksize[, dst[, borderType]]) -> dst
510
511 .. ocv:cfunction:: void cvPreCornerDetect( const CvArr* image, CvArr* corners, int aperture_size=3 )
512
513 .. ocv:pyoldfunction:: cv.PreCornerDetect(image, corners, apertureSize=3)-> None
514
515     :param src: Source single-channel 8-bit of floating-point image.
516
517     :param dst: Output image that has the type  ``CV_32F``  and the same size as  ``src`` .
518
519     :param ksize: Aperture size of the :ocv:func:`Sobel` .
520
521     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
522
523 The function calculates the complex spatial derivative-based function of the source image
524
525 .. math::
526
527     \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}
528
529 where
530 :math:`D_x`,:math:`D_y` are the first image derivatives,
531 :math:`D_{xx}`,:math:`D_{yy}` are the second image derivatives, and
532 :math:`D_{xy}` is the mixed derivative.
533
534 The corners can be found as local maximums of the functions, as shown below: ::
535
536     Mat corners, dilated_corners;
537     preCornerDetect(image, corners, 3);
538     // dilation with 3x3 rectangular structuring element
539     dilate(corners, dilated_corners, Mat(), 1);
540     Mat corner_mask = corners == dilated_corners;
541
542 .. [Canny86] J. Canny. *A Computational Approach to Edge Detection*, IEEE Trans. on Pattern Analysis and Machine Intelligence, 8(6), pp. 679-698 (1986).
543
544 .. [Matas00] Matas, J. and Galambos, C. and Kittler, J.V., *Robust Detection of Lines Using the Progressive Probabilistic Hough Transform*. CVIU 78 1, pp 119-137 (2000)
545
546 .. [Shi94] J. Shi and C. Tomasi. *Good Features to Track*. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 593-600, June 1994.
547
548 .. [Yuen90] Yuen, H. K. and Princen, J. and Illingworth, J. and Kittler, J., *Comparative study of Hough transform methods for circle finding*. Image Vision Comput. 8 1, pp 71–77 (1990)