F_VN_GradeQRCodeExp

F_VN_GradeQRCodeExp 1:

Grades a QR code according to ISO / IEC 15415:2011. Requires uniform illumination, good focus and the image sensor plane parallel to the code plane to achieve meaningful results. (expert function)

Syntax

Definition:

FUNCTION F_VN_GradeQRCodeExp : HRESULT
VAR_INPUT
    ipSrcImage            : ITcVnImage;
    ipDecodedData         : Reference To ITcVnContainer;
END_VAR
VAR_IN_OUT
    stCodeGrades          : TcVnCodeGradesQR;
END_VAR
VAR_INPUT
    fModuleWidth          : REAL;
    ipResultVisualization : Reference To ITcVnImage;
    ipMarginGrades        : Reference To ITcVnContainer;
    ipContour             : Reference To ITcVnContainer;
    hrPrev                : HRESULT;
END_VAR
VAR_OUTPUT
    fAngleDeg             : REAL;
END_VAR

F_VN_GradeQRCodeExp 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image, only containing the QR code region (USINT, 1 channel, including quiet zone)

ipDecodedData

Reference To ITcVnContainer

Returns the decoded data (ContainerType_String_SINT)

fModuleWidth

REAL

Minimum module width of the code in the image (in pixels). Must be at least 3, preferably 5 - 8.

ipResultVisualization

Reference To ITcVnImage

Returns a visualization of the scan grid (optional, set to 0 if not required). Module margin grades are color coded: >= 3 as green, >= 2 as light blue, >= 1 as orange, < 1 as red

ipMarginGrades

Reference To ITcVnContainer

Returns the individual margin grade for each module, e.g. to create a custom visualization (optional, set to 0 if not required; ContainerType_Vector_TcVnVector3_REAL, containing [x-position, y-position, grade])

ipContour

Reference To ITcVnContainer

Returns the 4 code corner points, excluding the quiet zone (optional, set to 0 if not required; ContainerType_Vector_TcVnPoint2_DINT)

hrPrev

HRESULT

HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.)

F_VN_GradeQRCodeExp 3: In/Outputs

Name

Type

Description

stCodeGrades

TcVnCodeGradesQR

Returns the code grades in the range from 0 (very bad) to 4 (very good)

F_VN_GradeQRCodeExp 4: Outputs

Name

Type

Description

fAngleDeg

REAL

Returns the clockwise rotation angle in degree

F_VN_GradeQRCodeExp 5: Return value

HRESULT

Further information

The function F_VN_GradeQRCodeExp is an expert variant of F_VN_GradeQRCode. It contains additional parameters.

Parameter

Input image

The input image ipSrcImage must be an 1-channel image with element type USINT (8 bits). The input image may only contain the code to be checked, including the corresponding quiet zones.

To achieve meaningful results, uniform illumination, not underexposed or overexposed, good focusing on the code plane and an image sensor plane aligned parallel to it are required. Furthermore, the image resolution must be high enough for the module size. For 2D codes, the smallest module should be covered with at least 5 pixels in order to achieve good results.

Read data

The data read from the code are returned as a string in the container ipDecodedData. The container is of the type ContainerType_String_SINT. Once the code has been successfully found and decoded, the content can be exported to a string using the function F_VN_ExportContainer_String.

hr := F_VN_ExportSubContainer_String(ipDecodedData, sText, nMaxLength, hr);
F_VN_GradeQRCodeExp 6:

Different decoding results

Decoding with the respective reference algorithm can lead to deviating results. It is therefore possible that the code content can be read by other devices or functions, but the reference algorithm fails.

Return of the quality assessment

The return value stCodeGrades of type TcVnCodeGradesQR contains the determined individual results and an overall total result nOverall. The quality grades ranges from 0 (very poor) to 4 (very good).

Parameter

Description

nDecode

Evaluates whether the code could be decoded with the reference algorithm.

nSymbolContrast

Evaluates the global symbol contrast, i.e. the difference between the brightest and darkest value in the test area.

nModulation

Evaluates the uniformity of the dark or bright modules.

nReflectanceMargin

Evaluates how well each module can be correctly distinguished as bright or dark compared to the global threshold.

nFixedPatternDamage

Evaluates the various fixed code components such as the finder or alignment pattern.

nAxialNonuniformity

Evaluates the uniform scaling of the code.

nGridNonuniformity

Evaluates deviations of the code grid.

nUnusedErrorCorrection

Evaluates the remaining capacity of the error correction.

nFormatInfo

Evaluates the format information encoded around the finder pattern.

nVersionInfo

Evaluates the version information contained in the code from version 7 onwards.

nOverall

The overall grade of the code is the lowest grade achieved in the individual examinations.

Minimum module width

The expected minimum module width of the code in pixels is specified with fModuleWidth. If the module size in the image differs significantly from this, this can lead to inaccurate or no results and increased computing time.

Presentation of results

ipResultVisualization returns an image with the visualization of the scan grid and the respective evaluation results. The modules are color-coded according to the individual grades: >= 3 as green, >= 2 as light blue, >= 1 as orange, < 1 as red. This parameter is optional and can be set to 0 if it is not required.

Margin information

ipMarginGrades returns additional information on the individual margin ratings of each module for a more detailed evaluation. The return vector of the type ContainerType_Vector_TcVnVector3_REAL contains the X and Y position of the center points and the grade for each module. This parameter is optional and can be set to 0 if it is not required.

Position of the code

The parameter ipContour returns the code corner points as four contour points of the type ContainerType_Vector_TcVnPoint2_DINT. The corner points are in the middle of the outer modules. The contour can be drawn directly with F_VN_DrawContours, for example, or further analyzed with the Contour Analysis functions. This parameter is optional and can be set to 0 if it is not required.

Rotation angle (return value)

fAngleDeg returns the clockwise rotation angle in degrees.

Application

The print quality of a QR code can be determined in this way, for example:

hr := F_VN_GradeQRCodeExp(
    ipSrcImage              := ipSrcImage,
    ipDecodedData           := ipDecodedData,
    stCodeGrades            := stCodeGrades,
    fModuleWidth            := fModuleWidth,
    ipResultVisualization   := ipResultVisualization,
    ipMarginGrades          := ipMarginGrades,
    ipContour               := ipContour,
    hrPrev                  := hr,
    fAngleDeg               => fAngleDeg);

Required License

TC3 Vision Code Quality

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision