2012-02-01 59 views
1

如何使用條形碼旋轉圖像以確定角度位置,然後根據水平方向旋轉角度。我用Hough Transform,但我只能稍微向右旋轉。如何旋轉圖像使條形碼水平? - MATLAB

Original Image Rotated Image

rgb = imread('barcode10.jpg'); 
% Resize Image 
rgb = imresize(rgb,0.33); 
figure(),imshow(rgb); 
% Convert from RGB to Gray 
Igray = double(rgb2gray(rgb)); 
BW2 = edge(Igray,'canny'); 
figure(),imshow(BW2); 
% Perform the Hough transform 
[H, theta, rho] = hough(BW2); 
% Find the peak pt in the Hough transform 
peak = houghpeaks(H); 
% Find the angle of the bars 
barAngle = theta(peak(2)); 
J = imrotate(rgb,barAngle,'bilinear','crop'); 
figure(),imshow(J); 

回答

1

您需要先檢測線。對於線路檢測,您可以使用Hough transform

+0

如何編寫該代碼?我花了幾個星期閱讀有關它,並嘗試代碼,但它不會工作! – Kim 2012-02-01 06:26:19

+1

你需要更具體。你有什麼嘗試?它如何不起作用? – Harriv 2012-02-01 07:42:37

+0

@Kim你不會得到任何有用的答案是這樣的。你至少應該嘗試一些東西或告訴我們,你確實有問題。此外,我想,在互聯網上已經有很多解決方案。所以請至少使用谷歌或搜索matlab文件交換:) – tim 2012-02-01 07:53:25