Barcode Scanner API Overview¶
The Barcode Scanner API lets you detect and read barcodes, its type, and retrieve its instance information.
See Best Practices for Barcode Scanning for information on the recommendations on barcode detection, the difference between 1-dimensional and 2-dimensional barcodes and choosing suitable barcodes.
General Setup¶
Please see the Engine Lifecycle for a general introduction to the Vuforia Engine lifecycle. The Engine is required for creating and using Observers.
Create Barcode Observer¶
Barcode detection is activated by creating a Barcode Observer. A Barcode Observer's default configuration initializes with all supported barcode types. The Barcode Observer is activated by default upon creation.
Only one Barcode Observer can be active at a time.
Configuring Barcode types¶
Specifying the types of barcodes to detect is optional. In cases where the barcode type is known ahead of time, we recommend restricting the detection to those types being used. For example, if only detection of QR-codes is required, the Observer can be configured accordingly before creation.
See the API reference documentation for supported VuBarcodeType
. The default value is null which sets the types to all supported types
.
After setting the barcode type for the Barcode Observer, you can destroy the types
:
Configuring Barcode detection mode¶
You can set the detection mode to observe a single barcode at a time or multiple simultaneously with VuBarcodeDetectionMode
. A single barcode detection improves device performance. Multiple barcode detections in parallel has higher performance requirements and will produce an observation for each barcode. Use the following Enums to define the detection mode:
- VU_BARCODE_DETECTION_MODE_SINGLE
- VU_BARCODE_DETECTION_MODE_MULTIPLE
Observations¶
The Barcode Observer produces a Barcode Observation on the State for each detected barcode instance. See the Observer and Observations article for more details on how to work with Observations.
Creation of Observation List
Destroy ObservationList
Destroy the Observer
Instance info¶
A barcode's payload is stored in VuBarcodeObservationInstanceInfo
. Each instance info contains the following information about a detected barcode:
- The actual payload of the barcode, encoded as a UTF-8 string. Accessible with
buffer
. - The type of barcode (e.g., EAN-13, CODE 39, QR-CODE). Accessible with
type
. - The 2D coordinates of the four corners of the barcode. Note that these are normalized coordinates in the [0.0-1.0] range. Accessible with
vertices
.
Tracking Barcodes Across Frames¶
In some cases (e.g., when visualizing the detection results), it is useful to know which observation in a previous frame corresponds to the current observation. For this purpose, the Vuforia Engine assigns a unique id to each barcode which is kept consistent as long as the barcode is visible.
Target Information¶
Get the set of supported barcode types of an activated Barcode Observer:
Get the number of elements in a barcode type set: