필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Kim
Kim 2012년 2월 2일
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.
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);

채택된 답변

Razvan
Razvan 2012년 2월 2일
J = imrotate(rgb,90 + barAngle,'bilinear','crop'); seems to give the right result. I think it depends if the Hough transform detects a horizontal line or a vertical line. So one of these should rotate the image as you like:
J = imrotate(rgb,barAngle,'bilinear','crop');
or
J = imrotate(rgb,90 + barAngle,'bilinear','crop');
  댓글 수: 2
Kim
Kim 2012년 2월 2일
But how can I make the barcode become horizontal no matter what image I insert whether is it vertical or horizontal.
Anton Semechko
Anton Semechko 2012년 2월 2일
there is too much clutter in the background ... Did you check if the bin with the highest vote actually corresponds to the orientation of the barcode lines?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by