如何旋转图像使条形码水平? - MATLAB

时间:2012-02-01 06:17:54

标签: image matlab rotation hough-transform

如何使用条形码旋转图像以确定角度的位置,并根据使其水平旋转。我使用Hough Transform,但我只能稍微向右旋转。

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 个答案:

答案 0 :(得分:1)

首先需要检测线条。对于线路检测,您可以使用Hough transform