Detecting and Decoding QR Codes
![Closed](../../../../Skins/Default/Stylesheets/Images/transparent.gif)
1. | Set a search field on an EROIBW8 image. |
2. | If needed, tune the parameters to restrict the number of operations to process. |
3. | The QR code reader scans the image and searches for 3 finder patterns that could match a QR code, with the following requirements: |
□ | Minimum quiet zone (blank zone around the QR code) width: 3 pixels. |
□ | Minimum module size: 3 x 3 pixels. |
□ | Minimum isotropy: 0.5. |
□ | Maximum corner deformation: 15° (corner angles can range from 75° to 105°). |
4. | The reader returns QR code candidates, or the result of a detection, as a vector of geometries. |
The QR code reader uses the gravity center of the QR code geometries to sort this vector in line then columns order starting from the top left corner of the image.
![Closed](../../../../Skins/Default/Stylesheets/Images/transparent.gif)
5. | The QR code reader decodes a QR candidate and returns the QR code: model, version, level, geometry and the decoded data as described below. |
6. | The reader can report the amount of unused error correction. |
□ | Close to 1, very few errors were corrected when decoding the data. The decoding is highly reliable, and the QR code is of good quality. |
□ | Close to 0, many errors were corrected when decoding the data. The decoding is reliable, but the QR code quality is poor. |
□ | -1, error correction failed. Decoding was not performed. |
![Closed](../../../../Skins/Default/Stylesheets/Images/transparent.gif)
Scan precision: You can change the scan precision to scan the search field with:
□ | A fine precision (recommended for small QR codes) |
□ | A coarse precision (recommended for medium to large QR codes) |
Minimum score: The QR code reader searches for this QR code finder pattern:
□ | A perfect match returns a pattern finder score of 1. |
□ | Less accurate matches return lower scores. |
□ | The minimum score allowed by default is 0.65 - you can tune this. |
Minimum isotropy: The isotropy of a QR code represents its rectangular deformation.
□ | Perfectly square QR codes have an isotropy of 1 (short side divided by long side, whether the rectangle is vertical or horizontal). |
□ | EasyQRCode can detect rectangle QR codes with an isotropy down to 0.5. |
□ | The default minimum isotropy is 0.8, it can be tuned from 0 to 1. |
Square and rectangular QR codes (isotropy = 1, 0.5, and 0.5 from left to right)
Model and version: The QR code reader searches for QR codes of all models, and all versions.
□ | You can shorten the process by specifying the QR code model(s) and a range of versions (from 1 to 40) to be searched for. |
![Closed](../../../../Skins/Default/Stylesheets/Images/transparent.gif)
Retrieving methods
To retrieve the decoded data, you can (in growing complexity order):
1. | Use the GetDecodedString method of an EQRCode object. |
□ | This method returns an UTF-8 formatted string that contains the concatenated data of the QR code. |
□ | It can take an EByteInterpretationMode as argument. |
2. | Use the GetDecodedString method of the EQRCodeDecodedStreamPart objects. |
□ | This method is called on a part and returns an UTF-8 formatted string that contains the data of this part. |
□ | It can take an EByteInterpretationMode as argument. |
□ | Concatenate the decoded string of each part. |
3. | Use the GetDecodedData method of the EQRCodeDecodedStreamPart objects. |
□ | This method is called on a part and returns a vector of bytes that contains the data of this part. |
□ | Interpret the data according to the coding mode of the QR code and the encoding of each part. |
□ | Concatenate the interpreted data of each part. |
Interpreting the encoded data
The QR code data can be encoded in either alphanumeric, numeric or byte modes. If a QR code contains bytes, the interpretation mode of these bytes can be embedded in the QR code through the ECI protocol or you must specify or know it.
Use the dedicated EByteInterpretationMode for this purpose:
● | EByteInterpretationMode_Hexadecimal |
□ | Converts all bytes to their hexadecimal values (2 characters per byte). |
□ | The escape character 0xEFBFBD surrounds the converted byte parts. |
□ | This mode overrides the ECI table indicator if it is present. |
● | EByteInterpretationMode_UTF8 |
□ | Converts all bytes to UTF-8 if possible. |
□ | The GetDecodedString method throws an EException if the data are not UTF-8 compatible. |
● | EByteInterpretationMode_Auto |
□ | Converts all bytes in the best possible way following the ECI protocol. |
The decoded string returns the concatenated data of the QR code in UTF-8 format:
□ | If bytes are present in the QR code data without ECI, specify the byte interpretation mode when you call the GetDecodedString method. |
□ | If bytes are present in the QR code data with ECI encoding, use the corresponding byte interpretation table (currently, only table ECI 26: UTF-8). |
□ | The hexadecimal byte interpretation mode does not throw an exception and returns all bytes parts present in the data in their hexadecimal form (2 characters per byte) surrounded by the 0xEFBFBD escape character. |
□ | See the code snippet Retrieving Information of a QR Code. |
The decoded stream class consists of:
□ | A coding mode (basic, ECI, FNC1/GS1 or FNC1/AIM). |
□ | An application indicator (if the coding mode is FNC1/AIM, otherwise 0). |
The decoded data:
□ | Is accessible from each part of the decoded stream. |
□ | Is interpreted according to its encoding (numeric, alphanumeric, byte or Kanji) and the ECI table indicator (if the coding mode is ECI, otherwise -1). |
□ | Can be the raw bit stream (the bit data after unmasking and error correction, but before decoding as a vector of bytes). |
□ | Can be the corresponding decoded string (specify a byte interpretation mode if the encoding is byte without ECI coding mode or if the ECI table is not supported). |
□ | See also the code snippet Retrieving the Decoded Data (Advanced). |