<< HoughLines Object detection cornerHarris >>

scicv >> Object detection > HoughLinesP

HoughLinesP

Finds lines in a binary image using the probabilistic Hough transform

Syntax

lines = HoughLinesP(img, distance_res, angle_res, threshold[, minLineLength[, maxLineGap]])

Parameters

img

Image (Mat, 8-bit single channel).

distance_res

Distance resolution, in pixels (double).

angle_res

Angle resolution, in radians (double).

threshold

Threshold parameter (double).

minLineLength

Minimum line length, shorter lines are rejected (double).

maxLineGap

Maximum allowed gap between points on the same line to link them (double).

lines

Output matrix of lines. Each column represents a line, coded in cartesian coordinates system ((x1, y1), (x2, y2)). (double 4xn).

Description

HoughLinesP find the line segments in an image using the probabilistic Hough transform. To apply, first an edge detection pre-processing is necessary. It keeps track of the intersection between curves of every point in the image. If the number of intersections is above the value of threshold, then the line is output in cartesian coordinates ((x1, y1), (x2, y2)).

Examples

scicv_Init();

img = new_Mat(200, 200, CV_8UC1, 0);
rectangle(img, [50,50], [100,100], 255 , -1);

scf();
matplot(img);

img_canny = Canny(img, 50, 150);

lines = HoughLinesP(img_canny, 1, %pi/180, 30, 10);

img_lines = new_Mat(200, 200, CV_8UC3, 0);
nb_lines = size(lines, 'c');
for i=1:nb_lines
    line(img_lines, lines(1:2,i), lines(3:4,i), [0,0,255]);
end

scf();
matplot(img_lines);

delete_Mat(img);
delete_Mat(img_canny);
delete_Mat(img_lines);

See also


Report an issue
<< HoughLines Object detection cornerHarris >>