基于MATLAB的QR二维码解码技术的程序_第1页
基于MATLAB的QR二维码解码技术的程序_第2页
基于MATLAB的QR二维码解码技术的程序_第3页
基于MATLAB的QR二维码解码技术的程序_第4页
基于MATLAB的QR二维码解码技术的程序_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 GUIDEs 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 EDITgui_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(varargin1) gui_State.gui_Callback = str2func(varargin1);end if nargout varargout1: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 QRMainhandles.output = hObject; % Update handles structureguidata(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 structurevarargout1 = 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, eventdata, handles) % 灰度化处理global im;global II; I=im;w,h,l=size(I); %图像大小 II=;for i=1:h for j=1:w II(j,i)=0.3*I(j,i,1)+0.59*I(j,i,2)+0.11*I(j,i,3); %灰度化处理公式endend 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-255Ix=imnoise(III,salt & pepper,0.02); %对灰度化图像人为加噪声I3=medfilt2(Ix,3,3); %平滑处理figureimshow(Ix)title(QR二维码加噪处理);figureimshow(I3)title(QR二维码平滑处理); % - Executes on button press in Binaryzation.function Binaryzation_Callback(hObject, eventdata, handles)% 二值化处理global I3;global I_otsu;I_otsu=otsut(I3); %二值化处理figureimshow(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.bmpglobal im; %倾斜校正 :二值化,取边缘,Hough变换得到角度,旋转I=im;bw=rgb2gray(I); %rgb转换为灰度图bw=im2bw(I,graythresh(bw); %二值化过程 bw=double(bw);BW=edge(bw,canny); %canny边缘处理BW1=BW;figureimshow(BW1);title(边缘处理图像); %显示图像H,T,R=hough(BW);figure,imshow(H,XData,T,YData,R,InitialMagnification,fit);xlabel(theta),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); %hough检测线段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); % 标出线段的起始和终端点 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 (lenmax_len) max_len=len; xy_long=xy; endend% 强调最长的部分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.bmpglobal 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,2) control_outpoint(1,1)*control_outpoint(1,2) 1 control_outpoint(2,1) control_outpoint(2,2) control_outpoint(2,1)*control_outpoint(2,2) 1 control_outpoint(3,1) control_outpoint(3,2) control_outpoint(3,1)*control_outpoint(3,2) 1 control_outpoint(4,1) control_outpoint(4,2) control_outpoint(4,1)*control_outpoint(4,2) 1;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); endendIjibian=I1;figureimshow(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二维码figureimshow(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 lowe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论