ClassesClassesClassesClasses | | | | Operators

find_1d_bar_codeT_find_1d_bar_codeFind1dBarCodefind_1d_bar_codeFind1dBarCodeFind1dBarCode (Operator)

Name

find_1d_bar_codeT_find_1d_bar_codeFind1dBarCodefind_1d_bar_codeFind1dBarCodeFind1dBarCode — Look for one bar code in an image.

Warning

find_1d_bar_codefind_1d_bar_codeFind1dBarCodefind_1d_bar_codeFind1dBarCodeFind1dBarCode is obsolete and is only provided for reasons of backward compatibility. New applications for reading bar codes should use the functionalities in the chapter Identification / Bar Code instead (see find_bar_codefind_bar_codeFindBarCodefind_bar_codeFindBarCodeFindBarCode).

Signature

find_1d_bar_code(Image : CodeRegion : BarCodeDescr, GenericName, GenericValue : BarcodeFound, BarCodeElements, Orientation)

Herror T_find_1d_bar_code(const Hobject Image, Hobject* CodeRegion, const Htuple BarCodeDescr, const Htuple GenericName, const Htuple GenericValue, Htuple* BarcodeFound, Htuple* BarCodeElements, Htuple* Orientation)

Herror find_1d_bar_code(Hobject Image, Hobject* CodeRegion, const HTuple& BarCodeDescr, const HTuple& GenericName, const HTuple& GenericValue, HTuple* BarcodeFound, HTuple* BarCodeElements, HTuple* Orientation)

HRegion HImage::Find1dBarCode(const HTuple& BarCodeDescr, const HTuple& GenericName, const HTuple& GenericValue, HTuple* BarcodeFound, HTuple* BarCodeElements, HTuple* Orientation) const

HRegion HBarCode1D::Find1dBarCode(const HImage& Image, const HTuple& GenericName, const HTuple& GenericValue, HTuple* BarcodeFound, HTuple* BarCodeElements, HTuple* Orientation) const

void Find1dBarCode(const HObject& Image, HObject* CodeRegion, const HTuple& BarCodeDescr, const HTuple& GenericName, const HTuple& GenericValue, HTuple* BarcodeFound, HTuple* BarCodeElements, HTuple* Orientation)

HRegion HImage::Find1dBarCode(const HTuple& BarCodeDescr, const HTuple& GenericName, const HTuple& GenericValue, Hlong* BarcodeFound, HTuple* BarCodeElements, double* Orientation) const

HRegion HImage::Find1dBarCode(const HTuple& BarCodeDescr, const HString& GenericName, double GenericValue, Hlong* BarcodeFound, HTuple* BarCodeElements, double* Orientation) const

HRegion HImage::Find1dBarCode(const HTuple& BarCodeDescr, const char* GenericName, double GenericValue, Hlong* BarcodeFound, HTuple* BarCodeElements, double* Orientation) const

void HOperatorSetX.Find1dBarCode(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*CodeRegion, [in] VARIANT BarCodeDescr, [in] VARIANT GenericName, [in] VARIANT GenericValue, [out] VARIANT* BarcodeFound, [out] VARIANT* BarCodeElements, [out] VARIANT* Orientation)

IHRegionX* HBarCode1DX.Find1dBarCode(
[in] IHImageX* Image, [in] VARIANT BarCodeDescr, [in] VARIANT GenericName, [in] VARIANT GenericValue, [out] Hlong* BarcodeFound, [out] VARIANT* BarCodeElements, [out] double* Orientation)

IHRegionX* HImageX.Find1dBarCode(
[in] VARIANT BarCodeDescr, [in] VARIANT GenericName, [in] VARIANT GenericValue, [out] Hlong* BarcodeFound, [out] VARIANT* BarCodeElements, [out] double* Orientation)

static void HOperatorSet.Find1dBarCode(HObject image, out HObject codeRegion, HTuple barCodeDescr, HTuple genericName, HTuple genericValue, out HTuple barcodeFound, out HTuple barCodeElements, out HTuple orientation)

HRegion HImage.Find1dBarCode(HTuple barCodeDescr, HTuple genericName, HTuple genericValue, out int barcodeFound, out HTuple barCodeElements, out double orientation)

HRegion HImage.Find1dBarCode(HTuple barCodeDescr, string genericName, double genericValue, out int barcodeFound, out HTuple barCodeElements, out double orientation)

Description

find_1d_bar_codefind_1d_bar_codeFind1dBarCodefind_1d_bar_codeFind1dBarCodeFind1dBarCode looks for a bar code in an image. As input it needs the description of the bar code as generated by gen_1d_bar_code_descrgen_1d_bar_code_descrGen1dBarCodeDescrgen_1d_bar_code_descrGen1dBarCodeDescrGen1dBarCodeDescr or gen_1d_bar_code_descr_gengen_1d_bar_code_descr_genGen1dBarCodeDescrGengen_1d_bar_code_descr_genGen1dBarCodeDescrGenGen1dBarCodeDescrGen. With this description the kind of bar code to be extracted is specified.

The result of the operator are the widths of the elements and the bar code region with its orientation. If a bar code was found BarcodeFoundBarcodeFoundBarcodeFoundBarcodeFoundBarcodeFoundbarcodeFound returns the value 1. Otherwise it returns 0.

To control the internal image processing the parameters GenericNameGenericNameGenericNameGenericNameGenericNamegenericName and GenericValueGenericValueGenericValueGenericValueGenericValuegenericValue are used. This is done by passing the names of the control parameters to be changed in GenericNameGenericNameGenericNameGenericNameGenericNamegenericName as a list of strings. In GenericValueGenericValueGenericValueGenericValueGenericValuegenericValue the values are passed at the corresponding index positions.

Normally none of the values have to be changed because the operator can adapt automatically to changing situations. Only in the case of difficult capturing conditions or with special bar codes a change should be applied. Here is the list of all parameters which can be changed:

'amplitude_sobel'

Minimum amplitude for edge extraction: The first step of the search for the bar code is based on the sobel filter. In contrast to thresholding this has the advantage of being independent of different illumination conditions. In the case of a low contrast (difference between bright and dark elements) this value can be chosen lower to find all parts of the bar code. If the contrast is very good the value can be set to a higher value. This results in a better runtime because less pixels have to be evaluated. The effect of this parameter can be checked with the operator sobel_dirsobel_dirSobelDirsobel_dirSobelDirSobelDir with edge type 'sum_abs'.

Default value: 70

Used for: Search for bar code region

'min_size_element'

During the analysis of elements (or parts of them) this parameter is used to eliminate very small objects which do not belong to the bar code. You have to be aware that with a low image quality elements can be divided into smaller pieces. The parameter has to be larger than the smallest piece. With good image quality the value can be larger to reduce runtime. In any case the value may not be larger than the length of one element (in pixels). The area calculated includes only the border of the elements and is thus smaller. If the value is too large parts of the bar code may be missing.

Default value: 30

Used for: Search for bar code region

'max_size_element'

Similar to the minimal size this parameter is used to suppress large objects. You have to know that with a low resolution multiple elements can be extracted as one intermediate region. The value has thus to be larger than the size of this region. This can be the size of many elements. The area internally calculated includes only the border of the elements. Furthermore the value should be smaller than the total size of the bar code.

Default value: 15000

Used for: Search for bar code region

'angle_range'

This parameter has the same function as the parameter 'sum_angles' but here it is used during the initial search for elements of the bar code. It has influence on the estimation of the orientation of the elements. For low quality images this value has to be large. A small value results in a reduced runtime. The value is given in degrees. There is no need to change the parameter.

Default value: 24

Used for: Search for bar code region

'correct_angle'

This parameter is used to decide if a region can be part of a bar code. For this the orientation of all boundary points are calculated. If enough points have the same orientation the region is accepted for further processing. Increasing this value reduces the amount of accepted regions and improves speed. For low image quality this value has to be low.

Default value: 50 (percent)

Used for: Search for bar code region

'dilation_factor'

After the initial step of finding elements these are combined into a bar code region (CodeRegionCodeRegionCodeRegionCodeRegionCodeRegioncodeRegion). This is implemented using the closing operator. The mask size is automatically estimated. If this estimation is wrong it can be corrected using this parameter. If the bar code elements have large gaps the value has to be larger than one. If the bar code is very close to other objects and is wrongly connected to this object the value can be smaller than 1. The parameter is independent of the image quality and runtime.

Default value: 1

Used for: Search for bar code region

'sum_angles'

This parameter is used for the final estimation of the orientation of the bar code region (value of OrientationOrientationOrientationOrientationOrientationorientation). For this at first the orientation of the boundaries of all elements are calculated. The most frequent orientation is calculated. Using the neighboring orientations the mean orientation is calculated. The parameter determines the amount of neighboring angles used for summing up. The value is given in degrees.

Default value: 40

Used for: Search for bar code region

'min_area_bar_code'

This value is used for the final decision if the region is a bar code. The parameter specifies the minimum area of the bar code. This area used here consists only of the boundary pixels of the elements and is thus smaller than the area of CodeRegionCodeRegionCodeRegionCodeRegionCodeRegioncodeRegion. If areas were found which are too small the value has to be increased. The parameter can also be used if small areas with the same orientation as the bar code elements were found. The parameter is independent of the image quality and runtime.

Default value: 1000

Used for: Search for bar code region

'sigma_project'

For the extraction of the element widths the gray values of the bar code region are projected in the direction of the elements. The data calculated this way is smoothed to reduce noise. For bar codes with large gaps between the elements this value can be increased if extra elements were detected. The value should be larger than 0.5.

Default value: 0.7

Used for: Search for bar code region

'element_orientation'

For the extraction of the bar code elements the gray values of the bar code region are projected in the direction of the elements. With this parameter elements with a specific orientation can be selected. The orientation is given in degrees -360 to +360.

Default value: No selection.

Used for: Search for bar code region

'element_orientation_tolerance'

For the extraction of the bar code elements the gray values of the bar code region are projected in the direction of the elements. With this parameter parameter you can define the tolerance for the orientation of the elements. The Value is added and subtracted from 'element_orientation'.

Default Value: 10

Used for: Extraction of element widths

'amplitude_project'

For the calculation of the element widths from the gray projections this parameter controls the minimum amplitude (gray value difference) between dark and light elements. With a lot of noise (e.g. scratches) this value can be increased. For low contrast images the value has to be low.

Default value: 3

Used for: Extraction of element widths

'width_project'

The gray value projections are calculated only in a part of the bar code region along several scanlines (see below). This parameter specifies the half width of the area that is used to calculate the gray value projections. If the orientation of the region is not estimated correctly this value must be small. If there are distortions (e.g., scratches) this value can be increased. For very narrow bar codes the value can be set to a small value.

Default value: 5

Used for: Extraction of element widths

'add_length_project'

Because the length of the bar code is sometimes to short to get get elements at the beginning and at the end the region is extended based on this parameter. If the bar code lies near to another object resulting in a connection of both areas this value can be decreased.

Default value: 5

Used for: Extraction of element widths

'interpolation_project'

With this parameter the type of interpolation used for the gray projection is determined. With a value of 1 a bilinear interpolation is used. With 0 no interpolation is used. In this case the runtime is shorter but it might result in a wrong extraction of the elements.

Default value: 1

Used for: Extraction of element widths

'num_scanlines'

This value determines the maximum number of scanlines in which the bar code is searched. This value should be chosen relatively large if it is expected that bar codes with severe disturbances must be read. If 'num_scanlines'"num_scanlines""num_scanlines""num_scanlines""num_scanlines""num_scanlines" is set to a value greater than 1, the default value of 'width_project'"width_project""width_project""width_project""width_project""width_project" is 5, otherwise 25. This choice of default values for 'width_project'"width_project""width_project""width_project""width_project""width_project" enables a robust extraction of the bar code even if only a single scanline is used.

Default value: 9

Used for: Extraction of element widths

'max_extra_elements'

With this parameter, elements extracted in the vicinity of the bar code that are parallel to the bars of the bar code can be eliminated. Hence, this parameter enables the correct decoding of the bar code if there are extraneous bars close to the bar code. The value of 'max_extra_elements'"max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements" is used for both ends of the bar code separately, so that a total of 2*'max_extra_elements'"max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements" extraneous elements (bars and spaces) can be eliminated. Hence, on each side of the bar code up to 'max_extra_elements'"max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements"/2 extraneous bars can be eliminated.

Default value: 6

Used for: Extraction of element widths

Please note that these parameters should normally not be changed.

Parallelization

Parameters

ImageImageImageImageImageimage (input_object)  singlechannelimage objectHImageHImageHImageHImageXHobject (byte / uint2)

Image with bar code inside.

CodeRegionCodeRegionCodeRegionCodeRegionCodeRegioncodeRegion (output_object)  region objectHRegionHRegionHRegionHRegionXHobject *

Region of bar code.

BarCodeDescrBarCodeDescrBarCodeDescrBarCodeDescrBarCodeDescrbarCodeDescr (input_control)  barcode_1d HTupleHTupleHBarCode1D, HTupleHBarCode1DX, VARIANTHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double) (BSTR / Hlong / double) (char* / Hlong / double)

Description of a bar code class.

GenericNameGenericNameGenericNameGenericNameGenericNamegenericName (input_control)  attribute.name(-array) HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Names of optional control parameters.

Default value: []

List of values: 'add_length_project'"add_length_project""add_length_project""add_length_project""add_length_project""add_length_project", 'amplitude_project'"amplitude_project""amplitude_project""amplitude_project""amplitude_project""amplitude_project", 'amplitude_sobel'"amplitude_sobel""amplitude_sobel""amplitude_sobel""amplitude_sobel""amplitude_sobel", 'angle_range'"angle_range""angle_range""angle_range""angle_range""angle_range", 'correct_angle'"correct_angle""correct_angle""correct_angle""correct_angle""correct_angle", 'dilation_factor'"dilation_factor""dilation_factor""dilation_factor""dilation_factor""dilation_factor", 'element_orientation'"element_orientation""element_orientation""element_orientation""element_orientation""element_orientation", 'element_orientation_tolerance'"element_orientation_tolerance""element_orientation_tolerance""element_orientation_tolerance""element_orientation_tolerance""element_orientation_tolerance", 'interpolation_project'"interpolation_project""interpolation_project""interpolation_project""interpolation_project""interpolation_project", 'max_extra_elements'"max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements""max_extra_elements", 'max_size_element'"max_size_element""max_size_element""max_size_element""max_size_element""max_size_element", 'min_size_element'"min_size_element""min_size_element""min_size_element""min_size_element""min_size_element", 'num_scanlines'"num_scanlines""num_scanlines""num_scanlines""num_scanlines""num_scanlines", 'sigma_project'"sigma_project""sigma_project""sigma_project""sigma_project""sigma_project", 'sum_angles'"sum_angles""sum_angles""sum_angles""sum_angles""sum_angles", 'width_project'"width_project""width_project""width_project""width_project""width_project"

GenericValueGenericValueGenericValueGenericValueGenericValuegenericValue (input_control)  attribute.value(-array) HTupleHTupleHTupleVARIANTHtuple (real / integer) (double / int / long) (double / Hlong) (double / Hlong) (double / Hlong) (double / Hlong)

Values of optional control parameters.

Default value: []

BarcodeFoundBarcodeFoundBarcodeFoundBarcodeFoundBarcodeFoundbarcodeFound (output_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Information whether the bar code was found.

List of values: 0, 1

BarCodeElementsBarCodeElementsBarCodeElementsBarCodeElementsBarCodeElementsbarCodeElements (output_control)  number-array HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Widths of elements.

OrientationOrientationOrientationOrientationOrientationorientation (output_control)  angle.rad HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Orientation of bar code.

Example (C++ (HALCON 5.0-10.0))

HTuple   empty;   // empty list of values
HTuple   BarCodeDescr;
HTuple   BarcodeFound,Elements,Orientation;
HTuple   Characters,Reference,IsCorrect;
Hobject  Image,CodeRegion;

gen_1d_bar_code_descr("EAN 13",13,13,&BarCodeDescr);
find_1d_bar_code(Image,&CodeRegion,BarCodeDescr,empty,empty,
                 &BarcodeFound,&Elements,&Orientation);
if (BarcodeFound[0].l)
{
  decode_1d_bar_code(Elements,BarCodeDescr,
                     &Characters,&Reference,&IsCorrect);
  if (IsCorrect[0].l)
    for (int i=0; i<Characters.Num(); i++)
    {
      char *value = Characters[i];
    }
}

Result

The operator find_1d_bar_codefind_1d_bar_codeFind1dBarCodefind_1d_bar_codeFind1dBarCodeFind1dBarCode returns the value 2 (H_MSG_TRUE) if the parameters are correct.

Module

Bar Code


ClassesClassesClassesClasses | | | | Operators