F_VN_DetectBarcodesWalsh
Detect barcodes using the Walsh transform.
Can use available TwinCAT Job Tasks for executing parallel code regions.
Syntax
Definition:
FUNCTION F_VN_DetectBarcodesWalsh : HRESULT
VAR_INPUT
ipSrcImage : ITcVnImage;
ipBarcodes : Reference To ITcVnContainer;
eOptions : UDINT;
END_VAR
VAR_IN_OUT
stParams : TcVnParamsWalshBarcodeDetection;
END_VAR
VAR_INPUT
hrPrev : HRESULT;
END_VARInputs
Name | Type | Description |
|---|---|---|
ipSrcImage | Source image (USINT or SINT) | |
ipBarcodes | Reference To ITcVnContainer | Returns the code positions as rotated rectangles (ContainerType_Vector_TcVnRotatedRectangle; Non-zero interface pointers are reused.) |
eOptions | UDINT | General flags controlling the detection process. (see ETcVnDetectBarcodesWalshOptions; default: TCVN_DBWO_HORIZONTAL) |
hrPrev | HRESULT indicating the result of previous operations (If SUCCEEDED(hrPrev) equals false, no operation is executed.) |
In/Outputs
Name | Type | Description |
|---|---|---|
stParams | Parameters for configuring the individual detection steps. |
Further information
The function F_VN_DetectBarcodesWalsh locates barcodes (1D codes) in an image using the Walsh transform and returns their position and orientation. Unlike code-reading functions, this function does not decode the code's content; rather, it serves to pre-locate the code regions.
These code regions can be decoded in the next step using the corresponding Code reading functions. Due to the specified region, the execution time is reduced as the localization of the code is restricted to a small image area. This also enables the direct use of code reading functions that require a predefined ROI.
Compared to neural network-based code recognition using F_VN_DetectCodesNeuralNetwork, Walsh-based detection offers shorter execution times in many scenarios, but can recognize only barcodes (1D codes). Whether the function is actually faster depends on the choice of parameters and the image content.
Parameter
ipSrcImage
The input image ipSrcImage must be of the type USINT or SINT.
ipBarcodes
The parameter ipBarcodes returns the localized barcode positions as a container of type ContainerType_Vector_TcVnRotatedRectangle.
eOptions
The parameter eOptions, of type ETcVnDetectBarcodesWalshOptions, specifies the orientations in which to search for barcodes. Multiple values can be combined using an OR operator. Default value: TCVN_DBWO_HORIZONTAL.
TCVN_DBWO_HORIZONTAL: Search for horizontally aligned barcodesTCVN_DBWO_VERTICAL: Search for vertically aligned barcodesTCVN_DBWO_DIAGONAL_45: Search for barcodes rotated by 45°TCVN_DBWO_DIAGONAL_135: Search for barcodes rotated by 135°TCVN_DBWO_ALL_DIRECTIONS: Search for barcodes rotated by any angle
If the orientation of the barcodes in the application is known, it is recommended to select only the relevant option, since each additional search direction increases computing time. TCVN_DBWO_ALL_DIRECTIONS offers the highest robustness when the orientation is unknown, but is correspondingly more computationally intensive.
stParams
The parameter stParams, of type TcVnParamsWalshBarcodeDetection, configures the individual steps of barcode detection. The code parameters can be estimated automatically from a reference image using F_VN_AnalyzeBarcodeWalsh.
Code parameters:
The following parameters describe the characteristic properties of the barcodes to be recognized and are typically estimated by F_VN_AnalyzeBarcodeWalsh:
nMaxBarDistance(Default: 8): Maximum distance in pixels between two consecutive dark or light bars. This should correspond to the maximum space width in the barcode.fMinAspectRatio(Default: 1.0) /fMaxAspectRatio(Default: 5.0): Minimum and maximum aspect ratios (width/height) for valid code regions.nIntensityDifference(Default: 100): Average intensity difference between dark and light code pixels.nMinArea(Default: -1): Expected minimum code area in pixels. The value -1 enables automatic estimation based on nMaxBarDistance.nChannelIndex(Default: -1): Color channel for internal processing. The value -1 enables automatic grayscale conversion: 3-channel images are interpreted as RGB, and 4-channel images as RGBA; if the number of channels is different, the first channel (index 0) is used.
For color images in which the barcode and background have particularly high contrast within a single channel, explicitly selecting that channel can improve detection robustness compared to automatic conversion.
Example: For a red barcode on a blue background, channel 0 (red) provides the highest contrast, since the red barcode appears light there and the blue background appears dark, whereas automatic grayscale conversion reduces this contrast by blending all channels.
Filter parameters:
The following parameters control the performance and robustness of the detection
nWalshFilterNum(Default: 5): Number of Walsh filters used. Higher values can improve recognition quality, but they also increase computing time. In practice, values between 2 and 7 yield good results. Computing time does not scale linearly with the number of filters: at the boundaries2n (i.e., at 2, 4, 8, ...), the internal kernel order increases abruptly. A reduction to just below such a threshold (e.g., from 4 to 3) can therefore result in a disproportionately large increase in speed.fOutlierReductionFactor(Default: 1.0): Suppresses distracting image elements such as text, logos, or matrix codes that appear in the image along with barcodes. Higher values increase the suppression; however, values that are too high can also weaken the barcode pixels.fBarConnectionFactor(Default: 1.0): Fills in gaps between barcode segments caused, for example, by lighting artifacts or reflections. Higher values bridge wider gaps but may create connections between unwanted image areas.fRegionFilterFactor(Default: 1.0): Removes small, distracting areas of the image. Higher values remove larger noise regions, but they increase computing time and may affect the shape of the barcode regions. Normally, the default value is sufficient.fPostProcessingResizeFactor(Default: 0.5): Scaling factor before post-processing. Lower values reduce computing time but may impair detection quality.eInterpolationType(Default:TCVN_IT_BILINEAR): Interpolation method for internal image scaling.TCVN_IT_BILINEARis recommended for most applications.
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 |