F_VN_GradeBarcode

F_VN_GradeBarcode 1:

Grades a 1D barcode according to ISO / IEC 15416:2016. Requires uniform illumination, good focus and the image sensor plane parallel to the code plane to achieve meaningful results.

Syntax

Definition:

FUNCTION F_VN_GradeBarcode : HRESULT
VAR_INPUT
    ipSrcImage    : ITcVnImage;
    ipDecodedData : Reference To ITcVnContainer;
END_VAR
VAR_IN_OUT
    stCodeGrades  : TcVnCodeGrades1D;
END_VAR
VAR_INPUT
    eBarcodeType  : ETcVnBarcodeType;
    hrPrev        : HRESULT;
END_VAR
VAR_OUTPUT
    fAngleDeg     : REAL;
END_VAR

F_VN_GradeBarcode 2: Inputs

Name

Type

Description

ipSrcImage

ITcVnImage

Source image, only containing the horizontally aligned barcode region (USINT, 1 channel, including quiet zones on left and right, excluding Text or empty space on more than 10% total height on top or bottom)

ipDecodedData

Reference To ITcVnContainer

Returns the decoded data (ContainerType_String_SINT)

eBarcodeType

ETcVnBarcodeType

Type of the barcode (supported: CODE39, CODE128, EAN8, EAN13, ITF, UPCA, UPCE)

hrPrev

HRESULT

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

F_VN_GradeBarcode 3: In/Outputs

Name

Type

Description

stCodeGrades

TcVnCodeGrades1D

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

F_VN_GradeBarcode 4: Outputs

Name

Type

Description

fAngleDeg

REAL

Returns the approximate clockwise rotation angle in degree

F_VN_GradeBarcode 5: Return value

HRESULT

Further information

The F_VN_GradeBarcode function determines the print quality of barcodes in accordance with the ISO/IEC 15416:2016 standard.

Algorithm

The function first searches for horizontally aligned codes and then for vertically aligned codes in the image.

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. The barcode must be aligned horizontally or vertically and must not have any text or blank space more than 10% of the total height above or below it. The quiet zones are located to the left and right of the code when aligned horizontally.

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 to match the line width. For barcodes, the minimum bar width should be covered by at least 3 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_GradeBarcode 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 TcVnCodeGrades1D contains the determined individual results and an overall total result fOverall. The quality grades ranges from 0 (very poor) to 4 (very good). The results are averaged over several scan lines.

Parameter

Description

fDecode

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

fSymbolContrast

Evaluates the global symbol contrast, i.e. the difference between the brightest and darkest value on the entire scan line.

fMinReflectance

Evaluates the ratio of the darkest to the brightest value of the scan lines.

fMinEdgeContrast

Evaluates the minimum local contrast of neighboring elements of the scan lines.

fModulation

Evaluates the ratio between the minimum local contrast and the global symbol contrast.

fDefects

Evaluates irregularities within elements and quiet zones.

fDecodability

Evaluates how reliably the code can be decoded with the reference algorithm.

fOverall

The overall score of the code is the lowest score achieved in the individual tests, averaged over all scan lines. If different scan lines lead to different decoded data, the overall score is 0.

Barcode type

The parameter eBarcodeType defines the barcode type whose print quality is to be assessed. The following barcode types from the enum ETcVnBarcodeType are supported:

  • TCVN_BT_CODE39
  • TCVN_BT_CODE128
  • TCVN_BT_EAN8
  • TCVN_BT_EAN13
  • TCVN_BT_ITF
  • TCVN_BT_UPCA
  • TCVN_BT_UPCE

Rotation angle (return value)

fAngleDeg returns the clockwise rotation angle in 90° steps.

Expert parameters

The expert variant F_VN_GradeBarcodeExp contains additional parameters.

Application

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

hr := F_VN_GradeBarcode(
    ipSrcImage       := ipSrcImage,
    ipDecodedData    := ipDecodedData,
    stCodeGrades     := stCodeGrades,
    eBarcodeType     := eBarcodeType,
    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