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

Look for one barcode in an image.

::find_1d_bar_code looks for a bar code in an image. As input it needs the description of the barcode as generated by ::gen_1d_bar_code_descr or ::gen_1d_bar_code_descr_gen. With this description the kind of barcode to be extracted is specified.

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

To control the internal image processing the parameters GenericName and GenericValue are used. This is done by passing the names of the control parameters to be changed in GenericName as a list of strings. In GenericValue 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 barcodes 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 barcode 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 choosen lower to find all parts of the barcode. 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_dir 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 barcode. 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 barcode 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 barcode. 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 inital search for elements of the barcode. 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 barcode. 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: 0.5 (corresponds 50 percent) Used for: Search for bar code region
'dilation_factor'
After the initial step of finding elements these are conbined into a barcode region (CodeRegion). 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 barcode elements have large gaps the value has to be larger than one. If the barcode 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 barcode region (value of Orientation). 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 barcode. The parameter specifies the minimum area of the barcode. This area used here consists only of the boundary pixels of the elements and is thus smaller than the area of CodeRegion. 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 barcode 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 barcode region are projected in the direction of the elements. The data calculated this way is smoothed to reduce noise. For barcodes 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: 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 the center part of the barcode region. The parameter specifies the half width of this area. If the orientation of the region is not estimated correctly this value has to be small. If there are distortions (e.g. scratches) this value can be increased. For very small barcodes the value can be decreased. Default value: 25 Used for: Extraction of element widths
'add_length_project'
Because the length of the barcode 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 barcode 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

Please note that these parameters should normally not be changed.


Parameters

Image (input_object)
image -> Hobject: HImage
Image with bar code inside.

CodeRegion (output_object)
region -> Hobject * : HRegion
Region of bar code.

BarCodeDescr (input_control)
string-array -> HTuple.char * / long / double
Description of a bar code class.

GenericName (input_control)
string(-array) -> HTuple.char *
Names of optional control parameters.
Default value: '[]'
List of values: 'amplitude_sobel', 'min_size_element', 'max_size_element', 'angle_range', 'correct_angle', 'dilation_factor', 'sum_angles', 'sigma_project', 'amplitude_project', 'width_project', 'add_length_project', 'interpolation_project'

GenericValue (input_control)
number(-array) -> HTuple.double / long
Values of optional control parameters.
Default value: '[]'

BarcodeFound (output_control)
integer -> HTuple.long *
Information whether the barcode was found.
List of values: 0, 1

BarCodeElements (output_control)
number-array -> HTuple.double *
Widths of elements.

Orientation (output_control)
angle.rad -> HTuple.double *
Orientation of bar code.


Example
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_code returns the value H_MSG_TRUE if the parameters are correct.


Possible Predecessors

::gen_1d_bar_code_descr, ::gen_1d_bar_code_descr_gen


Possible Successors

::decode_1d_bar_code, ::discrete_1d_bar_code


Alternatives

::find_1d_bar_code_region


See also

::sobel_dir, ::gray_projections, ::gen_measure_rectangle2


Module

Barcode reader



Copyright © 1996-2002 MVTec Software GmbH