您好,欢迎来到六九路网。
搜索
您的当前位置:首页基于MATLAB的QR二维码解码技术的程序

基于MATLAB的QR二维码解码技术的程序

来源:六九路网


function varargout = QRMain(varargin)

% QRMAIN MATLAB code for QRMain.fig

% QRMAIN, by itself, creates a new QRMAIN or raises the existing

% singleton*.

%

% H = QRMAIN returns the handle to a new QRMAIN or the handle to

% the existing singleton*.

%

% QRMAIN('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in QRMAIN.M with the given input arguments.

%

% QRMAIN('Property','Value',...) creates a new QRMAIN or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before QRMain_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to QRMain_OpeningFcn via varargin.

%

% *See GUI Options on GUIDE's Tools menu. Choose \"GUI allows only one

% instance to run (singleton)\".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help QRMain

% Last Modified by GUIDE v2.5 11-Apr-2017 20:19:20

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @QRMain_OpeningFcn, ...

'gui_OutputFcn', @QRMain_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before QRMain is made visible.

function QRMain_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to QRMain (see VARARGIN)

% Choose default command line output for QRMain

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes QRMain wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = QRMain_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

% --- Executes on button press in OpenQRPic.

function OpenQRPic_Callback(hObject, eventdata,

handles) %%%%%%%%打开图像

global im;

[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'选择图像');

if isequal(filename,0)||isequal(pathname,0)

errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框

return;

else

image=[pathname,filename];%合成路径+文件名

im=imread(image);%读取图像

figure

imshow(im);%在坐标axes1显示原图像

title('原始QR图像');

end

% hObject handle to OpenQRPic (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in DecodeQR.

function DecodeQR_Callback(hObject, eventdata,

handles)%%%%%%%%%%%%%%%%%%% QR解码

global I_otsu; %global 定义全局变量

global im;

global KL;

global Ijibian;

I_jiema=Ijibian;

I_jiema=I_otsu; %二值

I_jiema=KL;

I_jiema=im;

%

str=zxing_decode(I_jiema) %解码

%set(handles.edit1,'string',[get(handles.edit1,'string') str]);

%set(handles.text,'string',[get(handles.text,'string') str]);

set(handles.edit1,'String',str); %显示字符

% --- Executes on button press in GrayGen.

function GrayGen_Callback(hObject, handles) %%%%%%%%%%%%%%%%%%% 灰度化处理

global im;

global II;

I=im;

[w,h,l]=size(I); %图像大小

II=[];

for i=1:h

for j=1:w

eventdata,

II(j,i)=0.3*I(j,i,1)+0.59*I(j,i,2)+0.11*I(j,i,3); %灰度化处理公式

end

end

figure,imshow(II,[]) %显示图像

title('QR二维码灰度化处理');

% --- Executes on button press in SmoothGen.

function SmoothGen_Callback(hObject, eventdata,

handles)%%%%%%%%%%%%%%%%%%% 平滑处理

global II;

global I3;

III=uint8(II); %图像转换0-255

Ix=imnoise(III,'salt & pepper',0.02); %对灰度化图像人为加噪声

I3=medfilt2(Ix,[3,3]); %平滑处理

figure

imshow(Ix)

title('QR二维码加噪处理');

figure

imshow(I3)

title('QR二维码平滑处理');

% --- Executes on button press in Binaryzation.

function Binaryzation_Callback(hObject, handles)%%%%%%%%%%%%%%%%%%% 二值化处理

global I3;

global I_otsu;

I_otsu=otsut(I3); %二值化处理figure

eventdata,

imshow(I_otsu,[])

title('QR二维码二值化处理');

% function edit1_Callback(hObject, eventdata, handles)

% % hObject handle to edit1 (see GCBO)

% % eventdata reserved - to be defined in a future version of MATLAB

% % handles structure with handles and user data (see GUIDATA)

%

% % Hints: get(hObject,'String') returns contents of edit1 as text

% % str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in ImageRotate.

function ImageRotate_Callback(hObject, eventdata,

handles) %%%% 旋转校正 4.bmp

global im;

%倾斜校正 :二值化,取边缘,Hough变换得到角度,旋转

I=im;

bw=rgb2gray(I); %rgb转换为灰度图

bw=im2bw(I,graythresh(bw)); %二值化过程

bw=double(bw);

BW=edge(bw,'canny'); %canny边缘处理

BW1=BW;

figure

imshow(BW1);title('边缘处理图像'); %显示图像

[H,T,R]=hough(BW);

figure,imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');

xlabel('\heta'),ylabel('\\rho');

axis on, axis normal,hold on;

P=houghpeaks(H,4,'threshold',ceil(0.3*max(H(:)))); %hough变化峰值检测

x=T(P(:,2)); y = R(P(:,1));

plot(x,y,'s','color','white');

lines=houghlines(BW,T,R,P,'FillGap',50,'MinLength',7); figure,imshow(BW),title('直线标识图像');

max_len = 0;

hold on;

for k=1:length(lines) 来

xy=[lines(k).point1;lines(k).point2];

% 标出线段

plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

% 标出线段的起始和终端点

%hough检测线段

%主要把线条和点显示出

plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');

plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

len=norm(lines(k).point1-lines(k).point2);

Len(k)=len;

if (len>max_len)

max_len=len;

xy_long=xy;

end

end

% 强调最长的部分

plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','blue');

[L1 Index1]=max(Len(:));

% 最长线段的起始和终止点

x1=[lines(Index1).point1(1) lines(Index1).point2(1)];

y1=[lines(Index1).point1(2) lines(Index1).point2(2)];

% 求得线段的斜率

K1=-(lines(Index1).point1(2)-lines(Index1).point2(2))/...

(lines(Index1).point1(1)-lines(Index1).point2(1))

angle=atan(K1)*180/pi %显示角度

A = imrotate(I,-angle,'bilinear');% imrate 是逆时针的所以取一个负号

figure,imshow(A);

%imwrite(A,'4qingxie_jiaozheng')

% --- Executes on button press in AberrationAdj.

function AberrationAdj_Callback(hObject, eventdata,

handles) %%%% 畸变校正 11.bmp

global im;

global Ijibian;

syms a1 a2 a3 a4 b1 b2 b3 b4 real;

I=im;

x=[1:256];y=[1:256];

control_outpoint=[14 64 26 221

206 38

246 196];

control_inputpoint=[1 1 1 255

%原图像顶点

%几何畸变图像顶点

255 1

255 255];

x1=control_inputpoint(:,1); %原图像第一列

y1=control_inputpoint(:,2); %原图像第二列

A=[control_outpoint(1,1)

control_outpoint(1,1)*control_outpoint(1,2) 1

control_outpoint(1,2)

control_outpoint(2,1)

control_outpoint(2,1)*control_outpoint(2,2) 1

control_outpoint(2,2)

control_outpoint(3,1)

control_outpoint(3,1)*control_outpoint(3,2) 1

control_outpoint(3,2)

control_outpoint(4,1)

control_outpoint(4,1)*control_outpoint(4,2) 1];

control_outpoint(4,2)

a=linsolve(A,x1); %等价于a=sym(A)/sym(x1)

b=linsolve(A,y1); %等价于a=sym(A)/sym(y1)

f1=@(x,y) a(1)*x+a(2)*y+a(3)*x*y+a(4); %定义变换函数

f2=@(x,y) b(1)*x+b(2)*y+b(3)*x*y+b(4);

for i=1:256

for j=1:256

x1(i,j)=f1(i,j);

y1(i,j)=f2(i,j);

I1(i,j)=interp2(x,y,I,x1(i,j),y1(i,j),'bilinear'); %双线性插值

%I1(i,j)=interp2(x1(i,j),y1(i,j),I,x,y,'bilinear');

end

end

Ijibian=I1;

figure

imshow(I1);

function edit3_Callback(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text

% str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.

function edit3_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in QRGen.

function QRGen_Callback(hObject, eventdata,

handles) %%%% 自制QR (用英文)

global KL;

str3=get(handles.edit3,'string') %得到 string数据

KL=qrgen(str3,300,300); %生成相应QR二维码

figure

imshow(KL,[])

imwrite(KL,'KL.png')

% --- Executes on button press in QRgenDecode.

function QRgenDecode_Callback(hObject, eventdata,

handles) %%%%%%%%自制QR解码显示

global KL;

I_jiema=imread('KL.bmp');

str2=zxing_decode(I_jiema) %解码过程

set(handles.edit1,'String',str2);

% --- Executes on key press with focus on QRgenDecode and none of its controls.

function QRgenDecode_KeyPressFcn(hObject, eventdata, handles)

% hObject handle to QRgenDecode (see GCBO)

% eventdata structure with the following fields (see UICONTROL)

% Key: name of the key that was pressed, in lower case

% Character: character interpretation of the key(s) that was pressed

% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed

% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton11.

function pushbutton11_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton11 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

AllFigureHandle=get(0,'Children'); % Contain Figure and GUI

flag=rem(AllFigureHandle,1);%

OnlyPictureHandle=AllFigureHandle(find(flag==0)); % Exclude GUI,because GUI'handle is decimal

close(OnlyPictureHandle);

% --- If Enable == 'on', executes on mouse press in 5 pixel border.

% --- Otherwise, executes on mouse press in 5 pixel border or over DecodeQR.

function DecodeQR_ButtonDownFcn(hObject, eventdata, handles)

% hObject handle to DecodeQR (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 69lv.com 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务