I try to rotated my QR code depends on three boxs i used this code but didn't work
Mostra commenti meno recenti
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
lines(2).theta
lines(3).theta
%J = imrotate(cleanI,lines(1).theta,'bilinear','crop');
figure, imshow(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
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
lines(2).theta
lines(3).theta
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=='
res2 = native2unicode(matlab.net.base64decode(res))
2 Commenti
S. M
il 31 Dic 2021
yanqi liu
il 1 Gen 2022
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 =
Categorie
Scopri di più su ROI-Based Processing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



