Barcode scanning
Real-time barcode scanning
The SDK can detect barcodes located on the packaging of packaged foods. To implement real-time barcode scanning, the camera setup for continuous image recognition is needed.
Specifically for barcode scanning, these steps are required:
When defining a
FoodDetectionConfigurationobject, enable thedetectBarcodeflag.In the
recognitionResultscallback, check the propertycandidate.barcodeCandidates. If this list is empty, no barcodes have been recognised.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))fun fetchFoodItemForProductCode(
productCode: String,
onResult: (foodItem: PassioFoodItem?) -> Unit
)fetchFoodItemForProductCode(code: Barcode | PackagedFoodCode): Promise<PassioFoodItem | null>Future<PassioFoodItem?> fetchFoodItemForProductCode(String productCode)Barcode scanning from an image
To recognise a barcode in an image, refer to the recognizeImageRemote function. The result of the barcode scanning process will come in the packagedFoodItem attribute, and the resultType will be Barcode.
UI Example
Set up the camera preview and detection session to recognise barcodes
Create a result view with two states: search and result
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