2012-02-01 39 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