Label Definitions
Smart Label Capture provides a Label Definition API, enabling you to configure and extract structured data from predefined and custom labels. This feature provides a flexible way to recognize and decode fields within a specific label layout such as price tags, VIN labels, or packaging stickers without needing to write custom code for each label type.
A Label Definition is a configuration that defines the label, and its relevant fields, that Smart Label Capture should recognize and extract during scans.
There are two approaches to using label definitions:
Pre-built Labels
Smart Label Capture provides pre-built label definitions out of the box for the following common label types:
- Price Label: This factory method is designed for price checking scenarios where both barcode and price text need to be captured from product labels. Returns
UPC
andpriceText
fields. - VIN Label: A predefined label definition for scanning Vehicle Identification Numbers (VIN). Returns
text
and/orbarcode
fields.
Example: Price label
Use the LabelCaptureSettings
builder to configure a pre-built label definition for price labels, such as those found in retail environments:
let settings = LabelCaptureSettings.builder()
.addLabel(LabelDefinition.createPriceCaptureDefinition(name: "price-label"))
.build()
Custom Labels
If your use case is unique and not covered by Smart Label Capture's pre-built labels, you can define your own custom labels. These custom labels can use any combination of fully custom fields and pre-built fields, detailed below.
Custom Fields
There are two types of custom fields you can define:
The following methods are available to configure custom fields:
Method | Optional | Description |
---|---|---|
patterns | No | The regex patterns that identify the target string in the scanned content. |
dataTypePatterns | Yes | Used to specify keywords or phrases that help identify the context of the field. This is particularly useful when the label contains multiple fields that could match the same pattern (e.g., when both packaging and expiry dates are present). |
symbologies | No | The barcode symbologies to match for barcode fields. This is important for ensuring that the field only captures data from specific barcode types, enhancing accuracy and relevance. |
isOptional | Yes | Whether the field is optional or mandatory. This is helpful when certain fields may not be present on every scan. |
Example: Fish Shipping Box
This example shows how to create a custom label definition for a fish shipping box, which includes fields for barcode and batch number.
let settings = LabelCaptureSettings.builder()
.addLabel()
.addCustomBarcode()
.setSymbologies([.code128])
.buildFluent(name: "barcode-field")
.addCustomText()
.setDataTypePatterns(["Batch"])
.setPatterns(["FZ\\d{5,10}"])
.isOptional(true)
.buildFluent(name: "batch-number-field")
.buildFluent(name: "shipping-label")
.build()
Pre-built Fields
You can also configure your label by using pre-built fields. These are some common fields provided for faster integration, with all patterns
, dataTypePattern
, and symbologies
already predefined.
Customization of pre-built fields is done via the patterns
, dataTypePatterns
, and isOptional
methods, which allow you to specify the expected format of the field data.
All pre-built fields come with default patterns
and dataTypePatterns
that are suitable for most use cases. Using either method is optional and will override the defaults.
The resetDataTypePatterns
method can be used to remove the default dataTypePattern
, allowing you to rely solely on the patterns
for detection.
Barcode Fields
SerialNumberBarcode
: A barcode field for capturing serial numbers, typically used in electronics and appliances.PartNumberBarcode
: A barcode field for capturing part numbers, commonly used in manufacturing and inventory management.ImeiOneBarcode
: A barcode field for capturing the first International Mobile Equipment Identity (IMEI) number, used in mobile devices.ImeiTwoBarcode
: A barcode field for capturing the second International Mobile Equipment Identity (IMEI) number, used in mobile devices.
Price and Weight Fields
UnitPriceText
: A text field for capturing the unit price of an item, often used in retail and grocery labels.TotalPriceText
: A text field for capturing the total price of an item, typically used in retail and grocery labels.WeightText
: A text field for capturing the weight of an item, commonly used in shipping and logistics.
Date and Custom Text Fields
PackingDateText
: A text field for capturing the packing date of an item, often used in food and beverage labels.ExpiryDateText
: A text field for capturing the expiry date of an item, commonly used in pharmaceuticals and food products.
Example: Hard disk drive label
This example demonstrates how to configure a label definition for a hard disk drive (HDD) label, which typically includes common fields like serial number and part number.
let settings = LabelCaptureSettings.builder()
.addLabel()
.addSerialNumberBarcode()
.buildFluent(name: "serial-number")
.addPartNumberBarcode()
.buildFluent(name: "part-number")
.buildFluent(name: "hdd-label")
.build()