ReadBarcodeRoi

Detect and interpret a 1d barcode within the provided image. For best performance, the code should be horizontally aligned and in the image center.

Syntax

Definition:

HRESULT ReadBarcodeRoi(
    HRESULT                     hrPrev,
    ITcVnImage*                 ipSrcImage,
    ITcVnContainer*&            ipDecodedData,
    ETcVnBarcodeType            eBarcodeType,
    float&                      fAngleDeg,
    ETcVnBarcodeSearchDirection eSearchDirection = BSD_ANY,
    ITcVnContainer**            pipContour = nullptr,
    LONG                        nMaxScans = 30
)

Parameters

Name

Type

Default

Description

hrPrev

HRESULT

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

ipSrcImage

ITcVnImage*

Source image (USINT, 1 channel)

ipDecodedData

ITcVnContainer*&

Returns the decoded data (ContainerType_String_SINT)

eBarcodeType

ETcVnBarcodeType

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

fAngleDeg

float&

Returns the approximate clockwise rotation angle in degree

eSearchDirection

ETcVnBarcodeSearchDirection

BSD_ANY

Barcode search direction (BSD_ANY first tries horizontal, then vertical)

pipContour

ITcVnContainer**

nullptr

Returns 4 approximate code corner points, including the quiet zone. The width is accurate, but the actual height is not measured for performance reasons. Instead, it is statically set to 10% of the width, centered around the scan line that was decoded. (optional, set to 0 if not required; ContainerType_Vector_TcVnPoint2_DINT)

nMaxScans

LONG

30

Maximum number of scan lines that are evaluated to find the barcode. The scan always starts at the image center and then alternates up- and downwards with increasing distance, using steps of (ipSrcImage height / nMaxScans).

 Return value

HRESULT

Weiterführende Informationen

Die Funktion F_VN_ReadBarcodeRoi ist für die Erkennung eines einzelnen Barcodes innerhalb eines definierten Bildbereiches (ROI) optimiert.

Algorithmus

Dafür nutzt die Funktion einen angepassten Algorithmus, der eine zentrierte Positionierung des Codes im übergebenen Bild voraussetzt. Die Funktion sucht zunächst nach horizontal ausgerichteten Codes und anschließend nach vertikal ausgerichteten Codes im Bild.

Parameter

Eingangsbild

Das Eingangsbild ipSrcImage muss ein 1-kanaliges Bild mit Element-Typ USINT (8-Bit) sein. Der Code muss sich horizontal oder vertikal ausgerichtet in der Bildmitte befinden.

Gelesene Daten

Die aus dem Code gelesenen Daten werden als String in dem Container ipDecodedData zurückgegeben. Der Container ist dabei vom Typ ContainerType_String_SINT. Wurde der Code erfolgreich gefunden und decodiert kann der Inhalt über die Funktion F_VN_ExportContainer_String in einen String exportiert werden.

hr := F_VN_ExportContainer_String(ipDecodedData, sText, nMaxLength, hr);

Barcode-Typ

Der Parameter eBarcodeType definiert den Barcode-Typ, der gelesen werden soll. Es kann nur ein Barcode-Typ pro Funktionsaufruf übergeben werden. Die folgenden Barcode-Typen aus dem Enum ETcVnBarcodeType werden unterstützt:

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

Drehwinkel (Rückgabewert)

Der Rückgabewert fAngleDeg gibt den Drehwinkel im Uhrzeigersinn in 90°-Schritten zurück.

Expert-Parameter

Die Expert-Variante F_VN_ReadBarcodeRoiExp enthält zusätzliche Parameter.

Required License

TC3 Vision Code Reading

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.59 or later

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

Tc3_Vision