I try to rotated my QR code depends on three boxs i used this code but didn't work

I = imread('2.1.bmp');
Igray = rgb2gray(I);;
BW = edge(Igray,'canny');
% We can see that the image is noisy. We will clean it up with a few
% morphological operations
Ibw = im2bw(Igray,graythresh(Igray));
se = strel('line',1,100);
cleanI = imdilate(~Ibw,se);
figure, imshow(cleanI);
%Perform a Hough Transform on the image
% The Hough Transform identifies lines in an image
[H,theta,rho] = hough(cleanI);
peaks = houghpeaks(H,3);
lines = houghlines(Ibw,theta,rho,peaks);
% Highlight (by changing color) the lines found by MATLAB
hold on
for k = 1:numel(lines)
x1 = lines(k).point1(1);
y1 = lines(k).point1(2);
x2 = lines(k).point2(1);
y2 = lines(k).point2(2);
plot([x1 x2],[y1 y2],'Color','g','LineWidth', 2)
end
hold off
% Identify the angles of the lines.
% The following command shows the angle of the 2nd line found by the Hough
% Transform
lines(1).theta
ans = -45
lines(2).theta
ans = 45
lines(3).theta
ans = 45
%J = imrotate(cleanI,lines(1).theta,'bilinear','crop');
figure, imshow(J);
Unrecognized function or variable 'J'.
angle_1=lines(1).theta;
if lines(1).theta ~=45
J = imrotate(cleanI,45,'bilinear','crop');
figure, imshow(J);
end
if lines(2).theta ~=-45
J = imrotate(cleanI,-45,'bilinear','crop');
figure, imshow(J);
end

4 Commenti

I have edited your post and applied the run button to your code. As you can see, it doesn't run to completion so we cannot know what result you want us to see.
i wanna rotate image depend on three corners in QR code
Your code shows
Unrecognized function or variable 'J'.
because J has not been defined
Comment posted as flag by @S. M:
okay ,but still image didn't rotate successfully

Accedi per commentare.

Risposte (1)

clc; clear all; close all;
I = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/848380/2.1.bmp');
Igray = rgb2gray(I);
BW = edge(Igray,'canny');
% We can see that the image is noisy. We will clean it up with a few
% morphological operations
Ibw = im2bw(Igray,graythresh(Igray));
se = strel('line',1,100);
cleanI = imdilate(~Ibw,se);
figure, imshow(cleanI);
%Perform a Hough Transform on the image
% The Hough Transform identifies lines in an image
cleanI2=bwperim(imclose(cleanI,strel('square',100)));
[H,theta,rho] = hough(cleanI2);
peaks = houghpeaks(H,3);
lines = houghlines(Ibw,theta,rho,peaks);
% Highlight (by changing color) the lines found by MATLAB
hold on
for k = 1:numel(lines)
x1 = lines(k).point1(1);
y1 = lines(k).point1(2);
x2 = lines(k).point2(1);
y2 = lines(k).point2(2);
plot([x1 x2],[y1 y2],'Color','g','LineWidth', 2)
end
hold off
% Identify the angles of the lines.
% The following command shows the angle of the 2nd line found by the Hough
% Transform
lines(1).theta
ans = -63
lines(2).theta
ans = -63
lines(3).theta
ans = 27
J = imrotate(cleanI,lines(1).theta,'bilinear','crop');
J2 = imrotate(Igray,lines(1).theta,'bilinear','crop');
J3 = imdilate(J, strel('square', 9));
[r,c] = find(J3);
rect = [min(c) min(r) max(c)-min(c) max(r)-min(r)];
figure; imshow(J);
hold on; rectangle('position', rect, 'EdgeColor', 'g', 'LineWidth', 2)
qr_img = imcrop(J2, rect);
figure; imshow(qr_img);
then we can use zxing to decode,and use base64 to decode
%res = qr_code_extract(qr_img)
res = 'D8YAr0oOO6HusQQ61fNDKw=='
res = 'D8YAr0oOO6HusQQ61fNDKw=='
res2 = native2unicode(matlab.net.base64decode(res))
res2 = '� �J;��:��C+'

2 Commenti

thank you , but how to put three corners in the top like this (normal QR)
yes,sir,thie image can directly process,such as
clc; clear all; close all;
im = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/849060/pic_1.png');
res = QrDen(im)
res2 = native2unicode(matlab.net.base64decode(res))
function res = QrDen(qr_im)
if nargin < 1
load mtx.mat;
qr_im = mtx;
end
zxingpath = fullfile(fileparts(mfilename('fullpath')), 'zxing_encrypt.jar');
javaaddpath(zxingpath);
zxingpath = fullfile(pwd, 'zxing_decrypt.jar');
javaaddpath(zxingpath);
qr_im = im2java(qr_im);
width = qr_im.getWidth();
height = qr_im.getHeight();
source = com.google.zxing.client.j2se.BufferedImageLuminanceSource(qr_im.getBufferedImage());
binarizer = com.google.zxing.common.HybridBinarizer(source);
bitmap = com.google.zxing.BinaryBitmap(binarizer);
reader = com.google.zxing.MultiFormatReader();
res = char(reader.decode(bitmap));
end
result is
res =
'D8YAr0oOO6HusQQ61fNDKw=='
>> res2 = native2unicode(matlab.net.base64decode(res))
res2 =

Accedi per commentare.

Prodotti

Release

R2017a

Richiesto:

il 30 Dic 2021

Commentato:

il 1 Gen 2022

Community Treasure Hunt

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

Start Hunting!

Translated by