Talk about qrcode’s detect position.

  java

Order

This article mainly introduces the detection position of qrcode, that is, the positioning pattern, which is used to position the two-dimensional code in a picture.

Qrcode classification

QRCode is divided into three categories: Model 1, Model 2 and Micro QR:

  • Model 1: is the prototype of Model 2 and Micro QR, with 14 sizes from Version 1 to Version 14.
  • Model 2: is an improved version of Model 1, with alignment marks added. There are 40 sizes from Version 1 to Version 40.
  • Micro QR: there is only one locating mark and the minimum size is 11*11 modules.

The default here is model 2.

version

Qrcode has a concept of Version, and different versions correspond to different sizes. The formula is as follows:

Version对应的矩阵边长 = (V-1)*4 + 21

Version 1 is a matrix of 21 x 21, Version 2 is a matrix of 25 x 25, and Version 3 is a size of 29. Each addition of Version increases the size of 4.
The highest Version 40, (40-1)*4+21 = 177, so the highest is 177 x 177 matrix.

Qrcode original byteMatrix instance

The content is hello world, version is 2, qrcode matrix is 25 x 25.

 1 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 0 1 1 1 1 1 1 1
 1 0 0 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 1
 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 0 1
 1 0 1 1 1 0 1 0 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1
 1 0 1 1 1 0 1 0 0 1 0 1 1 1 0 0 1 0 1 0 1 1 1 0 1
 1 0 0 0 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1
 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1
 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0
 0 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 1 0 0 1 1 1
 0 1 0 0 1 1 0 1 0 0 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1
 0 1 1 0 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 0
 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 0 1 0 1 0 0 0 0 0
 0 0 0 0 0 1 1 0 1 1 1 1 0 0 1 1 0 0 1 1 1 0 0 1 1
 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0
 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0
 1 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 0 1 0 1
 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 0 0 1
 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 0 0 0 1
 1 1 1 1 1 1 1 0 0 0 0 1 1 0 1 1 1 0 1 0 1 1 1 1 1
 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 0 0
 1 0 1 1 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0
 1 0 1 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1 1
 1 0 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 1
 1 0 0 0 0 0 1 0 0 0 1 1 0 0 1 1 0 1 1 0 1 0 1 1 0
 1 1 1 1 1 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 1 1

position detection

 1 1 1 1 1 1 1
 1 0 0 0 0 0 1
 1 0 1 1 1 0 1
 1 0 1 1 1 0 1
 1 0 1 1 1 0 1
 1 0 0 0 0 0 1
 1 1 1 1 1 1 1

Qrcode positioning pattern, standard 3, upper left corner, upper right corner, lower left corner, side length 7

Alignment

1 1 1 1 1 
1 0 0 0 1 
1 0 1 0 1 
1 0 0 0 1 
1 1 1 1 1 

Edge length is 5, only qrcode above Version2 (including Version 2) is required to assist positioning. At least 0, at most 6, depending on version

Examples of version8 are as follows:

Judge whether a point is within the detect position

It mainly judges whether the x and y coordinates are within several boundary values.

if( (x < 7 && y < 7) //左上角
    || (x < 7 && (y >= height - 7)) //左下角
    || ((x >= width - 7) && y < 7)){ //右上角
    //在detect position之内
} 
    

doc