English (English)

Sample 4. Step 5.6: Delivery Address field, grAddress, wgAddressAbove, and DeliveryAddress elements

We have decided to search for the Delivery Address field:

  • to the right of and below the field name
  • using the White Gap element to limit the search area from below
  • using a Paragraph element

To specify the properties common to all these elements, we will create a Group element.

To create a group grAddress element:

  1. In the InvoiceHeader element create an element of type Group and name it grAddress.
  2. Click the Relations tab and specify the following search constraints for the elements of the group:
    • Above the kwDeliveryAddress element, Offset = -400
    • Left of the right boundary of the kwDeliveryAddress element, Offset = -800, Reference boundary = Right.
    • Right of the left boundary of the kwDeliveryAddress element, Offset = -50, Reference boundary = Left.
    • Below the upper boundary of the kwDeliveryAddress element, Offset = -20, Reference boundary = Top.

Show me...

To limit the search area for the DeliveryAddress element from below, we will specify a horizontal White Gap.

To create a wgAddressAbove element:

  1. In the InvoiceHeader.grAddress element, create an element of type White Gap and name it wgAddressAbove.
  2. Click the White Gap tab.
  3. Under Orientation, select Horizontal. Set Min height to 55.
    Note.When selecting values for the heights/widths of white gaps, you may wish to consider the geometry (i.e. boundaries and sizes) of the adjacent image objects in pre-recognition results mode.
  4. We are going to look for a white gap inside a paragraph, therefore under Search among objects of type, select only Text.
  5. Under Rubbish, specify the following values:
    • Lower threshold limit – 20;
    • Upper threshold limit – 80;
    • Threshold coefficient (%) – 10.

      Show me...

Note.The values for the properties Lower threshold limit, Upper threshold limit, and Threshold coefficient (%) can only be selected by method of trial and error. We recommend starting with the default values. If the default values do not work, altering them until the white gap is detected on all the test images.

  1. Do not specify any additional search constraints and retain the default values for the other options.
  2. Click the Relations tab.
  3. Since the white gap can be located only beneath the keywords of the name kwDeliveryAddress, specify the following search constraints:
    • Below the kwDeliveryAddress element, Offset = 20
      Offset is required in order to prevent the program from finding white gaps in other areas on the image, e.g. between the field name and the text. Click the Advanced tab.
  4. Since the Delivery Address field is not present on all of the images, but when it does occur it is always accompanied with its name, specify the following additional condition in the Advanced pre-search relations field:Search for the image object only if the kwDeliveryAddress element is detected. In the FlexiLayout language, this condition can be written as follows:
    If InvoiceHeader.kwDeliveryAddress.IsNull Then DontFind;
  5. Match the FlexiLayout to see if the wgAddressAbove element is detected on all images.
  6. Since the program sometimes finds more than one white gap in the specified search area and cannot always select the right one, we need to impose additional search constraints. If you examine the images, you will notice that the white gap we are interested in is the topmost gap in the given search area. Therefore, in the Advanced pre-search relations field, specify the following additional condition:Search for an image object closest to the upper boundary of the first page. In the FlexiLayout language, this condition can be written as follows:
    NearestY: Page(1).RectGlobal.Top;
  7. Temporarily exclude the InvoiceFooter element and match the FlexiLayout.

To create a DeliveryAddress element:

  1. In the InvoiceHeader.grAddress element, create an element of type Paragraph and name it DeliveryAddress.
  2. Click the Relations tab.
  3. Since DeliveryAddress can be located only above the white gap wgAddressAbove, specify the following search constraint:
    • Above the wgAddressAbove element, Offset = 0.
  4. Since the search area for the DeliveryAddress element has already been specified at the level of the InvoiceHeader.grAddress group, we need not specify it once again here.
  5. Click the Advanced tab.
  6. Since the name of the DeliveryAddress field is also located inside the search area, we need to exclude it in order to obtain only the value of DeliveryAddress. Additionally, there are separators and noise in the search area which are also best excluded. For the above reasons, we cannot just exclude the region of the kwDeliveryAddress element. It would be more appropriate to take the region of the kwDeliveryAddress element, enlarge this region so that it encompasses all the noise, and then exclude the resulting rectangle. To do this, specify the following search constraints in the Advanced pre-search relations field:
    If InvoiceHeader.kwDeliveryAddress.IsNull Then DontFind;
    Else
    // Draws a rectangle around the field name (with some offset for the boundaries)
    { Let Left = InvoiceHeader.kwDeliveryAddress.Rect.Left - 100dt;
    Let Top = InvoiceHeader.kwDeliveryAddress.Rect.Top - 100dt;
    Let Right = InvoiceHeader.kwDeliveryAddress.Rect.Right + 20dt;
    Let Bottom = InvoiceHeader.kwDeliveryAddress.Rect.Bottom;
    // Exclude the resulting rectangle from the search area of the field
    ExcludeRect (Left, Top, Right, Bottom);
    }
  7. Temporarily exclude the InvoiceFooter element and match the FlexiLayout.
  8. Specify the location of the DeliveryAddress block as the rectangular region of the detected DeliveryAddress element, simplified for better visual perception and expanded by 5 dots vertically and horizontally. To do this, select the Expression option and type the following expression:
    Rect outputRect;
    OutputRegion = InvoiceHeader.grAddress.DeliveryAddress.SimplifiedRegion;
    IsNull = InvoiceHeader.grAddress.DeliveryAddress.IsNull;
    OutputRegion.Inflate (5dt, 5dt);

12.04.2024 18:16:02

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.