How to use houghlines to detect the barcode lines

1 次查看(过去 30 天)
How can I detect the lines using houghline or other hough function in Matlab??

采纳的回答

Chandra Kurniawan
Chandra Kurniawan 2012-1-13
Hi,
First, sorry for changing your tif image into jpg format.
Here, I have the code to perform line detection.
I = imread('15d27ap.jpg');
Igray = rgb2gray(I);
Ibw = ~im2bw(Igray,graythresh(Igray));
Iskel = bwmorph(Ibw,'thin',inf);
%%%%radon tranform
[R xp] = radon(Iskel,0:1:360);
[II JJ] = find(R >= (max(max(R)) * 0.75));
imshow(Ibw); hold on;
for k = 1 : size(II,1)
R_i = (JJ(k) - 1) * 1;
xp_i = xp(II(k));
x_origin = size(Iskel,2) / 2 + (xp_i) * cos(R_i * pi / 180);
y_origin = size(Iskel,1) / 2 - (xp_i) * sin(R_i * pi / 180);
y1 = (y_origin - (1 - x_origin) * tan(((R_i) - 90) * pi / 180));
ye = (y_origin - (size(Iskel,2) - x_origin) * tan(((R_i) - 90) * pi / 180));
line([1 size(Iskel,2)], [y1 ye],'color','g');
end
The result :
I think my code just detect the lines.
In other word, we only know the starting and end point of each lines.
I hope this helps you.

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by