Speed up Smart Label Capture integration with Agent Skills
Install the Scandit plugin and use the /label-capture-web skill so that your AI coding agent can integrate, debug, and customize Smart Label Capture on Web following Scandit's recommended patterns. More info →
Run the following command in your project directory. It detects the supported coding agents you have installed and adds the Scandit plugin to each. Re-run it to update.
npx plugins add scandit/skillsPrefer to set it up yourself? Manual installation steps for each agent →
Scan shipping labels
Shipping Label Scanning reads a shipping label and returns its tracking ID, the receiver's name and address, and the carrier. Like receipt scanning, it uses the Adaptive Recognition Engine, which processes the label in the cloud.
To read your own set of fields on the device instead, define a custom label.
Shipping Label Scanning requires the Adaptive Recognition Engine, which is still in beta and may change in future versions of Scandit Data Capture SDK. To enable it on your subscription, contact support@scandit.com.
Before you start
- Use Scandit Data Capture SDK 8.6.0 or later. Shipping Label Scanning is available on iOS, Android, and Web. It isn't available on other frameworks yet.
- Ask support@scandit.com to enable the Adaptive Recognition Engine on your subscription.
- Make sure the device has a network connection. The Adaptive Recognition Engine processes the label in the cloud.
- Set up a
LabelCaptureinstance and aDataCaptureView. If you haven't done this yet, follow Get started.
Create the LabelCapture instance with LabelCaptureSettings that have no label definitions. The overlay adds its own definition for the tracking barcode. Label definitions that you add stay active alongside it, so a barcode that isn't the tracking barcode can end up as the trackingId.
import { LabelCapture, LabelCaptureSettings } from "@scandit/web-datacapture-label";
const labelCaptureSettings = await LabelCaptureSettings.fromLabelDefinitions([]);
const labelCapture = await LabelCapture.forContext(dataCaptureContext, labelCaptureSettings);
Steps
1. Create the settings
Create LabelCaptureAdaptiveRecognitionSettings with the result type AdaptiveRecognitionResultType.ShippingLabel. The result type sets the kind of document that the overlay looks for.
create() is asynchronous. If you call it without a result type, it creates settings for receipts.
To change the hint that the overlay shows while it processes a label, use setProcessingHintText(text).
import {
AdaptiveRecognitionResultType,
LabelCaptureAdaptiveRecognitionOverlay,
LabelCaptureAdaptiveRecognitionSettings,
ShippingLabelScanningResult,
type AdaptiveRecognitionResult,
} from "@scandit/web-datacapture-label";
const settings = await LabelCaptureAdaptiveRecognitionSettings.create(
AdaptiveRecognitionResultType.ShippingLabel
);
2. Create the overlay
Create the overlay with LabelCaptureAdaptiveRecognitionOverlay.withLabelCaptureForView(labelCapture, view). Then apply the settings with applySettings(settings).
When you pass your DataCaptureView, the overlay adds itself to the view. If you leave out the view, add the overlay yourself with DataCaptureView.addOverlay().
const overlay = await LabelCaptureAdaptiveRecognitionOverlay.withLabelCaptureForView(
labelCapture,
dataCaptureView
);
await overlay.applySettings(settings);
3. Listen for results
Set a LabelCaptureAdaptiveRecognitionListener as the overlay's listener. It receives two callbacks:
onRecognized(result)runs when the label is recognized. Check that the result is aShippingLabelScanningResult, then read its fields.onFailure()runs when recognition fails, for example because of a connection error.
overlay.listener = {
onRecognized: (result: AdaptiveRecognitionResult) => {
if (!(result instanceof ShippingLabelScanningResult)) {
return;
}
const trackingId = result.trackingId;
const receiverName = result.receiverFullName;
const receiverCompany = result.receiverCompany; // null if the label doesn't show one
const carrier = result.carrier;
},
onFailure: () => {
// Recognition failed, for example because of a connection error.
},
};
4. Switch the camera back on
When the overlay starts to process a label, it switches the camera to standby. It doesn't switch the camera back on after a result. To scan the next label, call the camera's switchToDesiredState(FrameSourceState.On) in onRecognized(result) after you handle the result.
If recognition fails, the overlay shows an error notification and switches the camera back on.
FrameSourceState is in @scandit/web-datacapture-core.
onRecognized: async (result: AdaptiveRecognitionResult) => {
// Handle the result, then get ready for the next label.
await camera.switchToDesiredState(FrameSourceState.On);
},
Shipping label fields
ShippingLabelScanningResult has the following fields:
| Field | Type | Description |
|---|---|---|
trackingId | string | The tracking identifier, read from the tracking barcode on the label. |
receiverFullName | string | The receiver's full name. |
receiverCompany | string | null | The receiver's company. null if the label doesn't show one. |
receiverStreet | string | The street of the receiver's address. |
receiverCity | string | The city of the receiver's address. |
receiverState | string | null | The state of the receiver's address. null if the label doesn't show one. |
receiverPostalCode | string | The postal code of the receiver's address. |
receiverCountry | string | null | The country of the receiver's address. null if the label doesn't show one. |
carrier | Carrier | The postal provider of the label. See Carriers. |
resultType is always AdaptiveRecognitionResultType.ShippingLabel for this result.
Handle missing values
receiverCompany,receiverState, andreceiverCountryarenullwhen the label doesn't show them. Check fornullbefore you use them.carrierisCarrier.NotAvailablewhen no carrier is identified on the label, or when the identified carrier isn't in the list below. It'sCarrier.Otheronly when the engine classifies the carrier as other.
Carriers
Carrier has the following values. The SDK maps the carrier that the engine identifies on the label to one of these values. The list can grow in future SDK versions.
| Carrier | Value |
|---|---|
| FedEx | Carrier.Fedex |
| United Parcel Service (UPS) | Carrier.Ups |
| United States Postal Service (USPS) | Carrier.Usps |
| DHL | Carrier.Dhl |
| DPD | Carrier.Dpd |
| GLS | Carrier.Gls |
| TNT | Carrier.Tnt |
| Amazon Logistics | Carrier.AmazonLogistics |
| OnTrac | Carrier.Ontrac |
| Royal Mail | Carrier.RoyalMail |
| Parcelforce | Carrier.Parcelforce |
| Evri | Carrier.Evri |
| Yodel | Carrier.Yodel |
| Chronopost | Carrier.Chronopost |
| Colissimo | Carrier.Colissimo |
| Mondial Relay | Carrier.MondialRelay |
| Poste Italiane | Carrier.PosteItaliane |
| BRT | Carrier.Brt |
| SDA | Carrier.Sda |
| Hermes | Carrier.Hermes |
| Austrian Post | Carrier.AustrianPost |
| Swiss Post | Carrier.SwissPost |
| PostNL | Carrier.Postnl |
| bpost | Carrier.Bpost |
| PostNord | Carrier.Postnord |
| Correos | Carrier.Correos |
| SEUR | Carrier.Seur |
| InPost | Carrier.Inpost |
| Classified by the engine as other | Carrier.Other |
| Not identified, or not in this list | Carrier.NotAvailable |
Verify it works
You're done when:
- The overlay shows its processing hint after you point the camera at a shipping label.
- Your
onRecognized(result)callback receives aShippingLabelScanningResult, and you can read itstrackingIdandcarrier. - Your
onRecognized(result)code switches the camera back on after each result, so you can scan the next label.
Processing starts only after the SDK decodes a tracking barcode on the label. The tracking barcode must be Code 128, Code 39, ITF, Data Matrix, or PDF417. Processing also requires a license key that includes Adaptive Recognition. If the overlay never shows its processing hint, check that the label has one of these barcodes and that your license key includes Adaptive Recognition.
If onFailure() runs instead, recognition failed, for example because of a network problem or a label the engine can't read. Check the network connection, then scan the label again.
Related
- Advanced configurations, including Receipt Scanning and Cloud Fallback
- Label definitions
- API reference:
ShippingLabelScanningResult,Carrier,LabelCaptureAdaptiveRecognitionSettings,LabelCaptureAdaptiveRecognitionOverlay,LabelCaptureAdaptiveRecognitionListener