Barcode scanning

The SDK can detect barcodes located on the packaging of packaged foods. To implement barcode scanning, the camera setup for continuous image recognition is needed.

Specifically for barcode scanning, these steps are required:

  1. When defining a FoodDetectionConfiguration object, enable the detectBarcode flag.

  2. In the recognitionResults callback, check the property candidate.barcodeCandidates. If this list is empty, no barcodes have been recognised.

  3. If there is a single or multiple barcode candidates, use their value property and invoke this function to fetch the full nutrition data.

public func fetchFoodItemFor(productCode: String, completion: @escaping ((PassioNutritionAISDK.PassioFoodItem?) -> Void))

On smaller packages, barcodes can be very small. When trying to scan these barcodes, the user usually brings to package to close to the camera creating focus issues. To avoid this, but the camera zoom level to 2.

UI Example

  1. Set up the camera preview and detection session to recognise barcodes

  2. Create a result view with two states: search and result

  3. If the candidate.barcodeCandidates is empty, show the search state. Else, fetch the PassioFoodItem, and use it's name and icon to show the result

Example of an image that produces multiple BarcodeCandidates:

Last updated