<< Object detection Object detection HoughLinesP >>

scicv >> Object detection > HoughLines

HoughLines

Finds lines in a binary image using the standard Hough transform

Syntax

lines = HoughLines(img, distance_res, angle_res, threshold)

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).

lines

Output matrix of lines. Each column represents a line, coded in polar coordinates system (rho, theta). (double 2xn).

Description

HoughLines find the lines in an image using the standard 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 polar coordinates (rho, theta).

Examples

scicv_Init();

img_gray = imread(getSampleImage("shapes.png"), CV_LOAD_IMAGE_GRAYSCALE);

thresh = 100;
img_canny = Canny(img_gray, thresh, thresh*2, 3);

lines = HoughLines(img_canny, 1, %pi/180, 50);

rho = lines(1,:);
theta = lines(2,:);
a = cos(theta);
b = sin(theta);
xy0 = [rho; rho] .* [a; b];
xy1 = xy0 - 1000 * [-b; a];
xy2 = xy0 + 1000 * [-b; a];

img_out = new_Mat(size(img_gray, 'r'), size(img_gray, 'c'), CV_8UC3);
nb_lines = size(lines, 'c');
for i=1:nb_lines
    line(img_out, xy1(:,i), xy2(:,i), [0,0,255]);
end

matplot(img_out);

delete_Mat(img_gray);
delete_Mat(img_canny);
delete_Mat(img_out);

See also


Report an issue
<< Object detection Object detection HoughLinesP >>