Kim
Kim

Reputation: 437

How to rotate the image so that the barcode horizontal?? - MATLAB

How can I rotate the image using the barcode to determine where the angle is and rotate it according to make it horizontal. I used Hough Transform but I can only rotate slightly to the right.

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

Upvotes: 1

Views: 1993

Answers (1)

Harriv
Harriv

Reputation: 6137

You need first to detect the lines. For line detection you can use Hough transform.

Upvotes: 1

Related Questions