Please explain this QR code program to me.

조회 수: 5 (최근 30일)
S. M
S. M 2022년 1월 3일
편집: Walter Roberson 2022년 1월 4일
I wanna someone explain to me what every functions do ,special functions QRkey and im2freqs ?total code will extract Qr code from image
function [ hit ] = QRkey( img,L,RP ) hit=[]; [row ~] = size(img); for i = 1:row freq = im2freqs(img(i,:)); [num ~] = size(freq); for j = 3:num-3 Error = 0.5; if abs((freq(j,2)/3)-freq(j-2,2)) > ceil((freq(j,2)/3)*Error)+1 ... abs((freq(j,2)/3)-freq(j-1,2)) > ceil((freq(j,2)/3)*Error)+1 ... abs((freq(j,2)/3)-freq(j+1,2)) > ceil((freq(j,2)/3)*Error)+1 ... abs((freq(j,2)/3)-freq(j+2,2)) > ceil((freq(j,2)/3)*Error)+1 ... freq(j,3)==0 L(i,freq(j,1))==0 L(i,freq(j+2,1))==0 L(i,freq(j-2,1))==0 continue; end %x = freq(j,1) , y = i Box = RP( L(i,freq(j,1)) ).BoundingBox; Cdif = uint32(sum(abs(RP(L(i,freq(j+2,1))).Centroid - RP(L(i,freq(j,1))).Centroid))); Ar = RP( L(i,freq(j,1)) ).Area;
if Cdif <= 5 && ...
L(i,freq(j-2,1))==L(i,freq(j+2,1)) && L(i,freq(j-2,1))~=L(i,freq(j,1))
hit = [hit; L(i,freq(j,1))];
j = j+2;
end
end
end
end
function [ freq ] = im2freqs( img)
col = numel(img);
freq = [];
co = [1 1 img(1)]; % [center counter color]
for j = 2:col
if co(3) ~= img(j)
co(1) = uint32(co(1))+ uint32(co(2))/2;
freq = [freq ; co];
co = [j 1 img(j)];
else
co(2) = co(2) + 1;
end
end
co(1) = uint32(co(1))+ uint32(co(2))/2;
freq = [freq;co];
end
function QR = CropQR (img, points) %u = [points(2,:)-points(4,:) 0]; %v = [1 0 0]; %c = cross(u,v); %angle = sign(c(3))*180/pi*atan2(norm(c),dot(u,v)); %angle = -(mod(angle +360,360)-135); angle = atand((points(2,2)-points(4,2))/(points(2,1)-points(4,1))); angle = angle - 45; if points(4,1) < points(2,1) angle = angle + 180; end
[h ,w ,~] = size(img);
QR = imrotate(img, angle);
[rh ,rw ,~] = size(QR);
T=[w/2 h/2];
RT=[rw/2 rh/2];
R=[cosd(angle) -sind(angle); sind(angle) cosd(angle)];
T = [T;T;T;T];
RT = [RT;RT;RT;RT];
rotpoints=(points-T)*R+RT ;
rotpoints=uint32(rotpoints);
xymax = max(rotpoints);
xymin = min(rotpoints);
QR = QR(xymin(2):xymax(2), xymin(1):xymax(1), :);
end
function [ ] = QRextraction( Rimg ) Rimg = imread('6.1.bmp'); img = rgb2gray(Rimg);
%sharppining the image
%enhancment image % and convert to binary image (black and white)
img = imsharpen(img,'Radius',10,'Amount',1);
img = ~im2bw(img,0.5);
[L num] = bwlabel(img)
%now we need properties for each 8 component
RP = regionprops(L,'all');
hit = QRkey(img,L,RP);
hit = [unique(hit) histc(hit,unique(hit))]
figure,imshow(L );
flag = zeros((numel(hit)/2));
for i = 1:(numel(hit)/2)-1
if flag(i)==1
continue;
end
ci = RP(hit(i,1)).Centroid;
j = i+1;
if flag(j)==1
continue;
end
cj = RP(hit(j,1)).Centroid;
for k = 1:(numel(hit)/2)
if i == k || j == k || flag(k)==1
continue;
end
ck = RP(hit(k,1)).Centroid;
%start
a = pdist([ci ; cj],'euclidean');
b = pdist([ci ; ck],'euclidean');
c = pdist([cj ; ck],'euclidean');
diff = cj - ci;
if c<a || c<b
continue;
end
d = ck+diff;
zz = abs((a*a + b*b)-(c*c))/(c*c)
center = ((cj+ci+ck+d)/4);
if zz < 0.1
x = [cj(1);ci(1);ck(1);d(1)];
y = [cj(2);ci(2);ck(2);d(2)];
x = x+(x-center(1))*0.5;
y = y+(y-center(2))*0.5;
flag(i)=1;flag(j)=1;flag(k)=1;
final_image=CropQR( Rimg , [x y]);
figure,imshow(final_image);
break;
end
end
end
  댓글 수: 7
Walter Roberson
Walter Roberson 2022년 1월 3일
The author of the code appears to be Osama Fawzy at Faculty of Computer and Information Science Ain Shams University
S. M
S. M 2022년 1월 3일
Okay sir

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

답변 (1개)

yanqi liu
yanqi liu 2022년 1월 4일
편집: Walter Roberson 2022년 1월 4일
yes,sir,i think the key is to judge the square corner,such as
now,we can find the rule
a = pdist([ci; cj],'euclidean');
b = pdist([ci; ck],'euclidean');
c = pdist([cj; ck],'euclidean');
zz = abs((a*a + b*b)-(c*c))/(c*c);
when zz < 0.1 ,the area is QR area,such as

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by