Merge pull request #1263 from abidrahmank:pyCLAHE_24
[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 .. note::
36
37    * An example on using the canny edge detector can be found at opencv_source_code/samples/cpp/edge.cpp
38
39    * (Python) An example on using the canny edge detector can be found at opencv_source_code/samples/cpp/edge.py
40
41 cornerEigenValsAndVecs
42 ----------------------
43 Calculates eigenvalues and eigenvectors of image blocks for corner detection.
44
45 .. ocv:function:: void cornerEigenValsAndVecs( InputArray src, OutputArray dst, int blockSize, int ksize, int borderType=BORDER_DEFAULT )
46
47 .. ocv:pyfunction:: cv2.cornerEigenValsAndVecs(src, blockSize, ksize[, dst[, borderType]]) -> dst
48
49 .. ocv:cfunction:: void cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv, int block_size, int aperture_size=3 )
50
51 .. ocv:pyoldfunction:: cv.CornerEigenValsAndVecs(image, eigenvv, blockSize, aperture_size=3) -> None
52
53     :param src: Input single-channel 8-bit or floating-point image.
54
55     :param dst: Image to store the results. It has the same size as  ``src``  and the type  ``CV_32FC(6)`` .
56
57     :param blockSize: Neighborhood size (see details below).
58
59     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
60
61     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
62
63 For every pixel
64 :math:`p` , the function ``cornerEigenValsAndVecs`` considers a ``blockSize`` :math:`\times` ``blockSize`` neighborhood
65 :math:`S(p)` . It calculates the covariation matrix of derivatives over the neighborhood as:
66
67 .. math::
68
69     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}
70
71 where the derivatives are computed using the
72 :ocv:func:`Sobel` operator.
73
74 After that, it finds eigenvectors and eigenvalues of
75 :math:`M` and stores them in the destination image as
76 :math:`(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)` where
77
78 * :math:`\lambda_1, \lambda_2` are the non-sorted eigenvalues of :math:`M`
79
80 * :math:`x_1, y_1` are the eigenvectors corresponding to :math:`\lambda_1`
81
82 * :math:`x_2, y_2` are the eigenvectors corresponding to :math:`\lambda_2`
83
84 The output of the function can be used for robust edge or corner detection.
85
86 .. seealso::
87
88     :ocv:func:`cornerMinEigenVal`,
89     :ocv:func:`cornerHarris`,
90     :ocv:func:`preCornerDetect`
91
92 .. note::
93
94    * (Python) An example on how to use eigenvectors and eigenvalues to estimate image texture flow direction can be found at opencv_source_code/samples/python2/texture_flow.py
95
96 cornerHarris
97 ------------
98 Harris edge detector.
99
100 .. ocv:function:: void cornerHarris( InputArray src, OutputArray dst, int blockSize, int ksize, double k, int borderType=BORDER_DEFAULT )
101
102 .. ocv:pyfunction:: cv2.cornerHarris(src, blockSize, ksize, k[, dst[, borderType]]) -> dst
103
104 .. ocv:cfunction:: void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 )
105
106 .. ocv:pyoldfunction:: cv.CornerHarris(image, harris_dst, blockSize, aperture_size=3, k=0.04) -> None
107
108     :param src: Input single-channel 8-bit or floating-point image.
109
110     :param dst: Image to store the Harris detector responses. It has the type  ``CV_32FC1``  and the same size as  ``src`` .
111
112     :param blockSize: Neighborhood size (see the details on  :ocv:func:`cornerEigenValsAndVecs` ).
113
114     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
115
116     :param k: Harris detector free parameter. See the formula below.
117
118     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
119
120 The function runs the Harris edge detector on the image. Similarly to
121 :ocv:func:`cornerMinEigenVal` and
122 :ocv:func:`cornerEigenValsAndVecs` , for each pixel
123 :math:`(x, y)` it calculates a
124 :math:`2\times2` gradient covariance matrix
125 :math:`M^{(x,y)}` over a
126 :math:`\texttt{blockSize} \times \texttt{blockSize}` neighborhood. Then, it computes the following characteristic:
127
128 .. math::
129
130     \texttt{dst} (x,y) =  \mathrm{det} M^{(x,y)} - k  \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2
131
132 Corners in the image can be found as the local maxima of this response map.
133
134
135
136 cornerMinEigenVal
137 -----------------
138 Calculates the minimal eigenvalue of gradient matrices for corner detection.
139
140 .. ocv:function:: void cornerMinEigenVal( InputArray src, OutputArray dst, int blockSize, int ksize=3, int borderType=BORDER_DEFAULT )
141
142 .. ocv:pyfunction:: cv2.cornerMinEigenVal(src, blockSize[, dst[, ksize[, borderType]]]) -> dst
143
144 .. ocv:cfunction:: void cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, int block_size, int aperture_size=3 )
145
146 .. ocv:pyoldfunction:: cv.CornerMinEigenVal(image, eigenval, blockSize, aperture_size=3) -> None
147
148     :param src: Input single-channel 8-bit or floating-point image.
149
150     :param dst: Image to store the minimal eigenvalues. It has the type  ``CV_32FC1``  and the same size as  ``src`` .
151
152     :param blockSize: Neighborhood size (see the details on  :ocv:func:`cornerEigenValsAndVecs` ).
153
154     :param ksize: Aperture parameter for the  :ocv:func:`Sobel`  operator.
155
156     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
157
158 The function is similar to
159 :ocv:func:`cornerEigenValsAndVecs` but it calculates and stores only the minimal eigenvalue of the covariance matrix of derivatives, that is,
160 :math:`\min(\lambda_1, \lambda_2)` in terms of the formulae in the
161 :ocv:func:`cornerEigenValsAndVecs` description.
162
163
164
165 cornerSubPix
166 ----------------
167 Refines the corner locations.
168
169 .. ocv:function:: void cornerSubPix( InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria )
170
171 .. ocv:pyfunction:: cv2.cornerSubPix(image, corners, winSize, zeroZone, criteria) -> None
172
173 .. ocv:cfunction:: void cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, int count, CvSize win, CvSize zero_zone, CvTermCriteria criteria )
174
175 .. ocv:pyoldfunction:: cv.FindCornerSubPix(image, corners, win, zero_zone, criteria) -> corners
176
177     :param image: Input image.
178
179     :param corners: Initial coordinates of the input corners and refined coordinates provided for output.
180
181     :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.
182
183     :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.
184
185     :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.
186
187 The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as shown on the figure below.
188
189 .. image:: pics/cornersubpix.png
190
191 Sub-pixel accurate corner locator is based on the observation that every vector from the center
192 :math:`q` to a point
193 :math:`p` located within a neighborhood of
194 :math:`q` is orthogonal to the image gradient at
195 :math:`p` subject to image and measurement noise. Consider the expression:
196
197 .. math::
198
199     \epsilon _i = {DI_{p_i}}^T  \cdot (q - p_i)
200
201 where
202 :math:`{DI_{p_i}}` is an image gradient at one of the points
203 :math:`p_i` in a neighborhood of
204 :math:`q` . The value of
205 :math:`q` is to be found so that
206 :math:`\epsilon_i` is minimized. A system of equations may be set up with
207 :math:`\epsilon_i` set to zero:
208
209 .. math::
210
211     \sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T) -  \sum _i(DI_{p_i}  \cdot {DI_{p_i}}^T  \cdot p_i)
212
213 where the gradients are summed within a neighborhood ("search window") of
214 :math:`q` . Calling the first gradient term
215 :math:`G` and the second gradient term
216 :math:`b` gives:
217
218 .. math::
219
220     q = G^{-1}  \cdot b
221
222 The algorithm sets the center of the neighborhood window at this new center
223 :math:`q` and then iterates until the center stays within a set threshold.
224
225
226
227 goodFeaturesToTrack
228 -------------------
229 Determines strong corners on an image.
230
231 .. 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 )
232
233 .. ocv:pyfunction:: cv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]]) -> corners
234
235 .. 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 )
236
237 .. ocv:pyoldfunction:: cv.GoodFeaturesToTrack(image, eigImage, tempImage, cornerCount, qualityLevel, minDistance, mask=None, blockSize=3, useHarris=0, k=0.04) -> cornerCount
238
239     :param image: Input 8-bit or floating-point 32-bit, single-channel image.
240
241     :param eig_image: The parameter is ignored.
242
243     :param temp_image: The parameter is ignored.
244
245     :param corners: Output vector of detected corners.
246
247     :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned.
248
249     :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.
250
251     :param minDistance: Minimum possible Euclidean distance between the returned corners.
252
253     :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.
254
255     :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See  :ocv:func:`cornerEigenValsAndVecs` .
256
257     :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`cornerHarris`) or :ocv:func:`cornerMinEigenVal`.
258
259     :param k: Free parameter of the Harris detector.
260
261 The function finds the most prominent corners in the image or in the specified image region, as described in [Shi94]_:
262
263 #.
264     Function calculates the corner quality measure at every source image pixel using the
265     :ocv:func:`cornerMinEigenVal`     or
266     :ocv:func:`cornerHarris` .
267
268 #.
269     Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are retained).
270
271 #.
272     The corners with the minimal eigenvalue less than
273     :math:`\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)`   are rejected.
274
275 #.
276     The remaining corners are sorted by the quality measure in the descending order.
277
278 #.
279     Function throws away each corner for which there is a stronger corner at a distance less than ``maxDistance``.
280
281 The function can be used to initialize a point-based tracker of an object.
282
283 .. 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`` .
284
285 .. seealso::
286
287     :ocv:func:`cornerMinEigenVal`,
288     :ocv:func:`cornerHarris`,
289     :ocv:func:`calcOpticalFlowPyrLK`,
290     :ocv:func:`estimateRigidTransform`,
291
292
293 HoughCircles
294 ------------
295 Finds circles in a grayscale image using the Hough transform.
296
297 .. 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 )
298
299 .. 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 )
300
301 .. ocv:pyfunction:: cv2.HoughCircles(image, method, dp, minDist[, circles[, param1[, param2[, minRadius[, maxRadius]]]]]) -> circles
302
303     :param image: 8-bit, single-channel, grayscale input image.
304
305     :param circles: Output vector of found circles. Each vector is encoded as a 3-element floating-point vector  :math:`(x, y, radius)` .
306
307     :param circle_storage: In C function this is a memory storage that will contain the output sequence of found circles.
308
309     :param method: Detection method to use. Currently, the only implemented method is  ``CV_HOUGH_GRADIENT`` , which is basically  *21HT* , described in  [Yuen90]_.
310
311     :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.
312
313     :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.
314
315     :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).
316
317     :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.
318
319     :param minRadius: Minimum circle radius.
320
321     :param maxRadius: Maximum circle radius.
322
323 The function finds circles in a grayscale image using a modification of the Hough transform.
324
325 Example: ::
326
327     #include <cv.h>
328     #include <highgui.h>
329     #include <math.h>
330
331     using namespace cv;
332
333     int main(int argc, char** argv)
334     {
335         Mat img, gray;
336         if( argc != 2 && !(img=imread(argv[1], 1)).data)
337             return -1;
338         cvtColor(img, gray, CV_BGR2GRAY);
339         // smooth it, otherwise a lot of false circles may be detected
340         GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
341         vector<Vec3f> circles;
342         HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
343                      2, gray->rows/4, 200, 100 );
344         for( size_t i = 0; i < circles.size(); i++ )
345         {
346              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
347              int radius = cvRound(circles[i][2]);
348              // draw the circle center
349              circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
350              // draw the circle outline
351              circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
352         }
353         namedWindow( "circles", 1 );
354         imshow( "circles", img );
355         return 0;
356     }
357
358 .. 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.
359
360 .. seealso::
361
362     :ocv:func:`fitEllipse`,
363     :ocv:func:`minEnclosingCircle`
364
365 .. note::
366
367    * An example using the Hough circle detector can be found at opencv_source_code/samples/cpp/houghcircles.cpp
368
369 HoughLines
370 ----------
371 Finds lines in a binary image using the standard Hough transform.
372
373 .. ocv:function:: void HoughLines( InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0 )
374
375 .. ocv:pyfunction:: cv2.HoughLines(image, rho, theta, threshold[, lines[, srn[, stn]]]) -> lines
376
377 .. ocv:cfunction:: CvSeq* cvHoughLines2( CvArr* image, void* line_storage, int method, double rho, double theta, int threshold, double param1=0, double param2=0 )
378
379 .. ocv:pyoldfunction:: cv.HoughLines2(image, storage, method, rho, theta, threshold, param1=0, param2=0)-> lines
380
381     :param image: 8-bit, single-channel binary source image. The image may be modified by the function.
382
383     :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}` ).
384
385     :param rho: Distance resolution of the accumulator in pixels.
386
387     :param theta: Angle resolution of the accumulator in radians.
388
389     :param threshold: Accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` ).
390
391     :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.
392
393     :param stn: For the multi-scale Hough transform, it is a divisor for the distance resolution  ``theta``.
394
395     :param method: One of the following Hough transform variants:
396
397             * **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
398
399
400             * **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.
401
402             * **CV_HOUGH_MULTI_SCALE** multi-scale variant of the classical Hough transform. The lines are encoded the same way as  ``CV_HOUGH_STANDARD``.
403
404
405     :param param1: First method-dependent parameter:
406
407         *  For the classical Hough transform, it is not used (0).
408
409         *  For the probabilistic Hough transform, it is the minimum line length.
410
411         *  For the multi-scale Hough transform, it is ``srn``.
412
413     :param param2: Second method-dependent parameter:
414
415         *  For the classical Hough transform, it is not used (0).
416
417         *  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).
418
419         *  For the multi-scale Hough transform, it is ``stn``.
420
421 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.
422 See also the example in :ocv:func:`HoughLinesP` description.
423
424 .. note::
425
426    * An example using the Hough line detector can be found at opencv_source_code/samples/cpp/houghlines.cpp
427
428 HoughLinesP
429 -----------
430 Finds line segments in a binary image using the probabilistic Hough transform.
431
432 .. ocv:function:: void HoughLinesP( InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 )
433
434 .. ocv:pyfunction:: cv2.HoughLinesP(image, rho, theta, threshold[, lines[, minLineLength[, maxLineGap]]]) -> lines
435
436     :param image: 8-bit, single-channel binary source image. The image may be modified by the function.
437
438     :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.
439
440     :param rho: Distance resolution of the accumulator in pixels.
441
442     :param theta: Angle resolution of the accumulator in radians.
443
444     :param threshold: Accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` ).
445
446     :param minLineLength: Minimum line length. Line segments shorter than that are rejected.
447
448     :param maxLineGap: Maximum allowed gap between points on the same line to link them.
449
450 The function implements the probabilistic Hough transform algorithm for line detection, described in
451 [Matas00]_. See the line detection example below: ::
452
453     /* This is a standalone program. Pass an image name as the first parameter
454     of the program.  Switch between standard and probabilistic Hough transform
455     by changing "#if 1" to "#if 0" and back */
456     #include <cv.h>
457     #include <highgui.h>
458     #include <math.h>
459
460     using namespace cv;
461
462     int main(int argc, char** argv)
463     {
464         Mat src, dst, color_dst;
465         if( argc != 2 || !(src=imread(argv[1], 0)).data)
466             return -1;
467
468         Canny( src, dst, 50, 200, 3 );
469         cvtColor( dst, color_dst, CV_GRAY2BGR );
470
471     #if 0
472         vector<Vec2f> lines;
473         HoughLines( dst, lines, 1, CV_PI/180, 100 );
474
475         for( size_t i = 0; i < lines.size(); i++ )
476         {
477             float rho = lines[i][0];
478             float theta = lines[i][1];
479             double a = cos(theta), b = sin(theta);
480             double x0 = a*rho, y0 = b*rho;
481             Point pt1(cvRound(x0 + 1000*(-b)),
482                       cvRound(y0 + 1000*(a)));
483             Point pt2(cvRound(x0 - 1000*(-b)),
484                       cvRound(y0 - 1000*(a)));
485             line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 );
486         }
487     #else
488         vector<Vec4i> lines;
489         HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
490         for( size_t i = 0; i < lines.size(); i++ )
491         {
492             line( color_dst, Point(lines[i][0], lines[i][1]),
493                 Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
494         }
495     #endif
496         namedWindow( "Source", 1 );
497         imshow( "Source", src );
498
499         namedWindow( "Detected Lines", 1 );
500         imshow( "Detected Lines", color_dst );
501
502         waitKey(0);
503         return 0;
504     }
505
506 This is a sample picture the function parameters have been tuned for:
507
508 .. image:: pics/building.jpg
509
510 And this is the output of the above program in case of the probabilistic Hough transform:
511
512 .. image:: pics/houghp.png
513
514
515
516 preCornerDetect
517 ---------------
518 Calculates a feature map for corner detection.
519
520 .. ocv:function:: void preCornerDetect( InputArray src, OutputArray dst, int ksize, int borderType=BORDER_DEFAULT )
521
522 .. ocv:pyfunction:: cv2.preCornerDetect(src, ksize[, dst[, borderType]]) -> dst
523
524 .. ocv:cfunction:: void cvPreCornerDetect( const CvArr* image, CvArr* corners, int aperture_size=3 )
525
526 .. ocv:pyoldfunction:: cv.PreCornerDetect(image, corners, apertureSize=3)-> None
527
528     :param src: Source single-channel 8-bit of floating-point image.
529
530     :param dst: Output image that has the type  ``CV_32F``  and the same size as  ``src`` .
531
532     :param ksize: Aperture size of the :ocv:func:`Sobel` .
533
534     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` .
535
536 The function calculates the complex spatial derivative-based function of the source image
537
538 .. math::
539
540     \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}
541
542 where
543 :math:`D_x`,:math:`D_y` are the first image derivatives,
544 :math:`D_{xx}`,:math:`D_{yy}` are the second image derivatives, and
545 :math:`D_{xy}` is the mixed derivative.
546
547 The corners can be found as local maximums of the functions, as shown below: ::
548
549     Mat corners, dilated_corners;
550     preCornerDetect(image, corners, 3);
551     // dilation with 3x3 rectangular structuring element
552     dilate(corners, dilated_corners, Mat(), 1);
553     Mat corner_mask = corners == dilated_corners;
554
555 .. [Canny86] J. Canny. *A Computational Approach to Edge Detection*, IEEE Trans. on Pattern Analysis and Machine Intelligence, 8(6), pp. 679-698 (1986).
556
557 .. [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)
558
559 .. [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.
560
561 .. [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)