A list,

1 What is QR code

QR code belongs to one of the matrix two-dimensional code, developed by DENSO(Japan) company, and standardized by JIS and ISO. What QR codes look like can already be seen in many situations.



(1) location detection graph, location detection graph separator: used for the positioning of the TWO-DIMENSIONAL code, for each QR code, the location is fixed, but the size of the specification will be different; These rectangular blocks with black and white intervals are easy to detect in image processing.

(2) Correction graphics: According to the different size, the number of correction graphics is also different. Correction graphics are mainly used for QR code shape correction, especially when the QR code is printed on uneven surfaces, or distortion occurs when taking photos.

(3) Positioning graphics: These small black and white squares are like coordinate axes, which define the grid on the TWO-DIMENSIONAL code.

(4) Format information: represents the error correction level of the TWO-DIMENSIONAL code, which is divided into L, M, Q and H;

(5) Data area: use black and white binary grid to encode content. Eight cells encode one byte.

(6) version information: that is, the specifications of the TWO-DIMENSIONAL code, THE QR code symbol has a total of 40 specifications of the matrix (generally black and white), from 21×21 (version 1), to 177×177 (version 40), each version of the symbol than the previous version of each side increased by 4 modules.

(7) Error correction code word: used to correct the error caused by two-dimensional code damage.

2 QR code identification principle

2.1 Positioning When a mobile phone takes a QR code image, it may also capture other images around the barcode. These interference images will increase the complexity of image processing, so these unnecessary interference images can be removed by cutting. After correction, the area outside the square A ‘B’ C ‘D’ is cut directly to remove the rest of the background. The QR code symbol has three position detection graphics, respectively located in the symbol image of the three corners of the four corners, each four position detection image is composed of a fixed depth of color module. The color sequence of modules is dark – light – dark – light – dark, and the width ratio of each element is 1∶ 1∶ 3∶ 1∶ 1 (as shown in the figure below).

Even if the image has rotation, the module color sequence and width ratio of the position detection image remain unchanged. The binarization image was scanned point by point in line and column respectively, and the adjacent pixels of the same gray level were recorded as line segments. If there are five line segments whose length ratio is 1:1:3:1:1, and the color sequence is dark – light – dark – light – deep, record the line segment. After scanning, the adjacent line segments were divided into 1 group, and the line segments that were not adjacent to all the line segments were removed (possibly random interference line segments). In the same way, the line segment group and the intersecting groups in the line segment group are classified, and the center point of the intersecting line segment group is obtained, which is the center of the position detection graph. 2.2.2 Basic principle of pre-processing: QR code as the two-dimensional code of mobile phone, its application mode is shown in the figure below. Smart devices such as mobile phones collect images with bar code symbols through the camera, and preprocess the images with gray scale, binarization and rotation correction to carry out bar code detection. If non-QR codes are detected, re-collect them. If it is a QR code, the image information is sampled. The reed-Solomon code decoding algorithm was used to correct and decode the obtained data, and the number of errors was counted. If the number of errors exceeds the error correction capacity, the error correction decoding fails and the image is collected again. If error correction and decoding can be carried out correctly, the information after error correction can be decoded in various data modes to recover the encoded information, and then according to the application mode for information output, sending SMS or url jump and other subsequent processing.

3 CHARACTERISTICS of QR code

Speaking of the features of QR codes:

First, it is high-speed reading (QR is taken from the first letter of “Quick Response”). The experience of reading speed comes from a software on my mobile phone. Like the code map posted above, it only takes about three seconds to shoot, decode and display content through the camera, and there is no requirement for the Angle of the camera.

2) High capacity and high density; Theoretically, the content can be compressed to store 7089 digits, 4296 alphanumeric characters, 2953 8-bit data, 1817 Chinese characters;

Three) support error correction; Error correction processing is relatively complex, I have not yet in-depth understanding, according to the STANDARD documentation of QR code, QR code error correction is divided into four levels, respectively: Level L: the maximum 7% of errors can be corrected; Level M: Up to 15% of errors can be corrected; Level Q: Up to 25% of errors can be corrected; Level H: up to 30% of errors can be corrected;

4) Structure; What looks like an irregular pattern has a strict definition of the region. Here is a QR graph structure of mode 2 and version 1 (the “mode” and “version” of the QR code will be introduced later) : In the 21*21 matrix above, the black and white areas are designated as fixed positions in the QR code specification, which are called finder pattern and Timing pattern. Image seeking graphics and location graphics are used to help the decoder determine the coordinates of specific symbols in the graphics. The yellow area is used to store the encoded data content and error correction message codes. The blue area is used to identify the Level of error correction (i.e., Level L to Level H) and the so-called “Mask pattern “, this area is called “format information”.

Five) is to expand the ability. QR code Structure Append characteristics, so that a QR code can be decomposed into multiple QR codes, on the contrary, can also be multiple QR code data combination to a QR code:

4 QR code mode and version

The Model and Version of QR codes were mentioned earlier. QR code is divided into Model1 and Model2 two modes, Model1 is the initial definition of QR, Model2 is an extension of Model1, currently used more commonly is Model2, all the instructions in this article is only used for Model2.

The size of the QR graph is defined as Version, with Version numbers ranging from 1 to 40. Version 1 is a 2121 matrix, and each additional version number increases the size of the matrix by 4 modules, so version 40 is a 177177 matrix. (A higher version means more content stored and more error-correcting power).

5 Encoding content supported by QR codes

QR code supports encoding content including pure digits, digits and character mixed encoding, 8-bit bytecode and multi-byte characters including Chinese characters. Where: number: every three for a group compressed into 10 bits. Alphanumeric mix: Each two is a group, compressed to 11 bits. 8bit data: saves data directly without compression. Multi-byte characters: Each character is compressed to 13 bits.

6 QR code coding principle (coding) coding is the common numbers, characters and so on into QR code method. Before we get into the coding, let’s talk about the maximum size of a QR code.

6.1 Maximum Capacity

The maximum size of the QR code depends on the version selected, error correction level, and encoding Mode (Mode: digit, character, multi-byte character, etc.). In version 1, the error correction Level is Level Q QR code as an example, can store 27 pure digits, or 17 alphanumeric mixed characters or 11 8bit data. If you want to store the same amount of content and increase the level of error correction, you need a higher version. The data capacity and error correction code capacity of versions 1 to 9 are compared as follows:





Ii. Source code

function varargout = main(varargin)
% MAIN MATLAB code for main.fig
%      MAIN, by itself, creates a new MAIN or raises the existing
%      singleton*.
%
%      H = MAIN returns the handle to a new MAIN or the handle to
%      the existing singleton*.
%
%      MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAIN.M with the given input arguments.
%
%      MAIN('Property'.'Value',...). creates anew MAIN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before main_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to main_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 main

% Last Modified by GUIDE v2. 5 20-Apr- 2014. 14:55:44

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @main_OpeningFcn, ...
                   'gui_OutputFcn',  @main_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 main is made visible.
function main_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 main (see VARARGIN)

% Choose default command line output for main
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = main_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)%%%%%%%% Open the image Global IM;
[filename,pathname]=uigetfile({'*. *';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'Select Image');
if isequal(filename,0)||isequal(pathname,0)
  errordlg('You haven't selected the image yet!! '.'Warm reminder'); % If no input is entered, an error dialog box is createdreturn;
elseimage=[pathname,filename]; % composition path + file name im=imread(image); % Read imagefigure
    imshow(im); % display original image title at coordinates axes1'Raw QR image');
end


% hObject    handle to pushbutton1 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%%%%%%% QR decodes global I_otsu; %global Defines the global variable global im; global KL; global Ijibian; I_jiema=Ijibian; I_jiema=I_otsu; Binary I_jiema % = KL; I_jiema=im; % STR =zxing_decode(I_jiema) % decode %set(handles.edit1,'string',[get(handles.edit1,'string') str]);
%set(handles.text,'string',[get(handles.text,'string') str]);
set(handles.edit1,'String',str); % displays character % -- Executes on button press in PUSHButton4.function pushbutton4_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%%%%%%% Grayscale processing global IM; global II; I=im; [w,h,l]=size(I); % image size 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); End end figure,imshow(II,[]) %'QR code gray processing ');

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%%%%%%% Smooth global II; global I3; III=uint8(II); % image conversion0- 255.
Ix=imnoise(III,'salt & pepper'.0.02); I3= medFilt2 (Ix,[3.3]); % smoothingfigure
imshow(Ix)
title('QR code noise processing ');
figure
imshow(I3)
title('QR code smoothing ');


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)%%%%%%%%%%%%%%%%%%% binarization processes global I3; global I_otsu; I_otsu=otsut(I3); % binarization processingfigure
imshow(I_otsu,[])
title('QR code binary processing ');



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 pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)%%%% Rotation correction 4. BMP Global IM; % tilt correction: binarization, take edge, Hough transform to get Angle, rotate I=im; bw=rgb2gray(I); % RGB converted to grayscale bw= im2BW (I,graythresh(bw)); % binarization process bw=double(bw);
BW=edge(bw,'canny'); %canny edge treatment BW1=BW;figure
imshow(BW1); title('Canny boundary image'); [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 peak detection 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 test line segment figure,imshow(BW),title('Line identification image');
max_len = 0;
hold on;
for k=1Xy =[lines(k).point1;lines(k).point2]; xy=[lines(k).point2]; % plot(xy(:,1),xy(:,2),'LineWidth'.2.'Color'.'green'); % Mark the start and end points of the line segment 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
Copy the code

3. Operation results

Fourth, note

Version: 2014 a