DotCode Reading

This sample illustrates the following

Explanation

The F_VN_ReadDotCodeRoiExp function searches for a single DotCode within a defined image area and decodes it. It also returns the contour and the rotation angle of the code found.

A 1-channel 8-bit grayscale image must be transferred to the function. It is also necessary that the DotCode to be read is in the center of the transferred image area. If the code is not in the center of the image, the position must be determined in advance using other functions and adjusted accordingly by setting a Region of interest (ROI).

The fModuleWidth parameter defines the expected point diameter in pixels. This value should correspond as closely as possible to the actual diameter in the image. An absolute minimum size of 3 pixels is required. For optimum results, a range of 5 to 8 pixels is recommended. Significant deviations from the actual module width can reduce the recognition rate and significantly increase the execution time of the function.

In addition, the search strategy can be adapted to the circumstances using the eOptions parameter (ETcVnDotCodeOptions). E.g. TCVN_DCO_BINARY_INPUT can be used for pre-binarized images or TCVN_DCO_REGULAR_COLOR / TCVN_DCO_INVERTED_COLOR can be used to specifically search for dark or light codes.

To prevent cycle timeouts, the function in the sample is monitored using a watchdog.

Variables

// DotCode reading
fModuleWidth              :   REAL := 4.0;
eOptions                  :   ULINT := TCVN_DCO_DEFAULT;
ipCodeDecoded             :   ITcVnContainer;
ipCodeContour             :   ITcVnContainer;
sCodeAsString             :   STRING(255);
fCodeAngleDeg             :   REAL;


// Watchdog
hrWD                      :   HRESULT;
tStop                     :   DINT := 20000;
tRest                     :   DINT;

// Output
sText                     :   STRING;

Code

// Execute the DotCode reading function monitored by the Watchdog function
hrWD := F_VN_StartRelWatchdog(tStop, S_OK);
    hr := F_VN_ReadDotCodeRoiExp(
                ipSrcImage      := ipImageIn,
                ipDecodedData   := ipCodeDecoded,
                fModuleWidth    := fModuleWidth,
                ipContour       := ipCodeContour,
                eOptions        := eOptions,
                hrPrev          := hr,
                fAngleDeg       => fCodeAngleDeg);

hrWD := F_VN_StopWatchdog(hrWD, tRest => tRest);

// Check if the function was executed successfully
IF hr = S_OK THEN
    // Export code into string
    hr := F_VN_ExportContainer_String(ipCodeDecoded, sCodeAsString, 255, hr);

    // Draw code contour into result image
    hr := F_VN_DrawContours(ipCodeContour, 0, ipImageRes, aColorRed, 2, hr);

    // Write code into result image
    hr := F_VN_PutLabelExp(sCodeAsString, ipImageRes, 0, 11, 1, 1, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, aColorGreen, aColorWhite, ETcVnLineType.TCVN_LT_8_CONNECTED, S_OK);
ELSE
    // Write HRESULT into result image
    sText := CONCAT('Returncode ', DINT_TO_STRING(hr));
    hr := F_VN_PutLabelExp(sText, ipImageRes, 0, 11, 1, 1, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, aColorRed, aColorWhite, ETcVnLineType.TCVN_LT_8_CONNECTED, S_OK);
END_IF

// Write Code Reading proceeded time into Result Image
sText := CONCAT(CONCAT('Time: ', DINT_TO_STRING(tStop - tRest)), ' us');
hr := F_VN_PutLabelExp(sText, ipImageRes, 0, 26, 1, 1, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, aColorGreen, aColorWhite, ETcVnLineType.TCVN_LT_8_CONNECTED, S_OK);

Result

DotCode Reading 1: