Nutrition Facts scanning
There are cases when the barcode scanning item isn't present in the nutritional database. In the cases when the fetchFoodItemForProductCode doesn't yield a response, the user can scan the nutrition facts label on the packaging of the food and extract the data to create a new food item.
Real-time Nutrition Facts scanning
Similar to the real-time barcode scanning, the camera preview must be set up to enable continuous nutrition facts scanning. To start the Nutrition Facts scanning process a NutritionFactsRecognitionListener has to be defined. When the app is done with the nutrition fact scanning process, it should clear out the listener to avoid any unwanted UI updates.
The PassioNutritionFacts
contains all of the data that can be scanned from a nutrition facts label including:
Serving size (quantity and unit)
Weight
Calories
Carbs
Protein
Fat
Sugars
Other micronutrients like fiber, cholesterol...
Nutrition Facts scanning from an image
To recognise nutrition facts in an image, refer to the recognizeImageRemote function. The result of the nutrition facts scanning process will come in the packagedFoodItem
attribute, and the resultType will be Nutrition Facts. The nutrients will be stored in the PassioNutrients object of the first ingredient, and the serving size info will be stored in the PassioFoodAmount.
There is a separate API called recognizeNutritionFactsRemote
that is specifically taylored for this task. The recognizeImageRemote has the ability to recognise multiple different aspects of food scanning, but if there is a use case where the only action is to extract the data from the nutrition facts label, it's advised to use the recognizeNutritionFactsRemote.
UI Example
The barcode scanning process is always the most precise way to get nutritional information about a packaged food. If the barcode is not present in the nutritional database, give the user the option to scan the nutrition facts label.
If the user proceeds with the Nutrition Facts scan, register a listener to start receiving the results from the SDK. When a PassioNutritionFacts is returned from the callback, display the data so that the user can verify it's accuracy.
Enable to user to manually enter all of the other data that the Nutrition Facts scanner did not recognise.
Once a user saves this food item, be sure to include it in the search or barcode scanning results.
Last updated