EAN-13 Barcode Reading

In diesem Beispiel werden

Erläuterung

Variablen

hr                        :   HRESULT;

ipImageIn                 :   ITcVnImage;
ipImageInDsply            :   ITcVnDisplayableImage;

ipImageRes                :   ITcVnImage;
ipImageResDsply           :   ITcVnDisplayableImage;

// Barcode
ipCodeDecodedList         :   ITcVnContainer;
ipCodeContourList         :   ITcVnContainer;
sCodeAsString             :   STRING(255);
eBarcodeSearchDirection   :   ETcVnBarcodeSearchDirection := TCVN_BSD_ANY;
eBarcodeType              :   ETcVnBarcodeType := TCVN_BT_EAN13;

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

// Output
sText                     :   STRING;

// Color
aColorRed                 :   TcVnVector4_LREAL := [255, 0, 0];

Code

// Execute the Barcode Reading Function with EAN13 selected monitored by the Watchdog-Function 
// ---------------------------------------------------------------
hrWD := F_VN_StartRelWatchdog(tStop, S_OK);
    hr := F_VN_ReadBarcodeExp(
               ipSrcImage         :=   ipImageIn,
               ipDecodedData      :=   ipCodeDecodedList,
               ipContours         :=   ipCodeContourList,
               eBarcodeType       :=   eBarcodeType,
               nCodeNumber        :=   1,
               eSearchDirection   :=   eBarcodeSearchDirection,
               hrPrev             :=   hr);
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_ExportSubContainer_String(ipCodeDecodedList, 0, sCodeAsString, 255, hr);

    // Write Code into Result Image
    hr := F_VN_PutTextExp(sCodeAsString, ipImageRes, 50, 100, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 5, aColorRed,3, TCVN_LT_4_CONNECTED, FALSE, hr);

    // Draw Code Contour into Result Image
    hr := F_VN_DrawContours(ipCodeContourList, 0, ipImageRes, aColorRed, 3, hr);
ELSE
    // Write HRESULT into Result Image
    sText := CONCAT('Returncode ', DINT_TO_STRING(hr));
    hr := F_VN_PutTextExp(sText, ipImageRes, 50, 100, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 5, aColorRed,3, TCVN_LT_4_CONNECTED, FALSE, hr);
END_IF

// Write Code Reading proceeded time into Result Image
sText := CONCAT(CONCAT('Time: ', DINT_TO_STRING(tStop - tRest)), 'us');
hr := F_VN_PutTextExp(sText, ipImageRes, 50, 200, ETcVnFontType.TCVN_FT_HERSHEY_PLAIN, 5, aColorRed,3, TCVN_LT_4_CONNECTED, FALSE, hr);

Ergebnisse

Wenn als Suchrichtung TCVN_BSD_ANY ausgewählt ist, werden sowohl horizontale als auch vertikale EAN13-Codes erkannt. Beim Vergleich der Watchdog-Zeit wird aber ersichtlich, dass horizontale EAN13-Codes (erstes Bild) deutlich schneller erkannt werden als vertikale EAN13-Codes (zweites Bild), da zunächst in horizontaler Richtung nach Codes gesucht wird.

EAN-13 Barcode Reading 1:
EAN-13 Barcode Reading 2:

Wird hingegen die Suchrichtung auf TCVN_BSD_VERTICAL gesetzt, ist der vertikale EAN13 Code deutlich schneller erkannt (drittes Bild). Es erfolgt dann aber keine Suche nach den horizontalen Codes.

EAN-13 Barcode Reading 3:

Ähnliche Beispiele