Create an ImageRecognitionsFragment to handle image capture, gallery selection, and food item recognition.
Step 1: Select or Capture Image
For selecting or capturing an image, use PhotoPicker and PhotoCapture functions in ImageRecognitionsFragment. Refer to Android's official documentation for detailed instructions:
The fetchResult() method sends the selected image to the Passio SDK for recognition.
privatefunfetchResult() {if (bitmap ==null) { Toast.makeText(requireContext(), "Please select an image", Toast.LENGTH_SHORT).show()return } binding.loader.isVisible =true PassioSDK.instance.recognizeImageRemote(bitmap!!) { result -> binding.loader.isVisible =falseval adapter =ImageRecognitionsAdapter(result) { info ->onShowDetails(info) } binding.list.adapter = adapter }}
PassioSDK.instance.recognizeImageRemote
The recognizeImageRemote function takes an image in Bitmap format, analyzes it remotely using Passio's servers, and returns a list of food items recognized within the image. This function is asynchronous and utilizes a callback to return the result once the analysis is complete.
Output
The function returns a list of PassioAdvisorFoodInfo objects through a callback
The structure of PassioAdvisorFoodInfo is as follows:
recognisedName (String): The name of the recognized food item.
portionSize (String): Suggested portion size for the recognized food.
weightGrams (Double): Estimated weight of the food item in grams.
foodDataInfo (PassioFoodDataInfo?): An optional field containing more detailed nutritional information if available.
packagedFoodItem (PassioFoodItem?): An optional field containing packaged food item data if the recognized item is a packaged product.
resultType (PassioFoodResultType): The type of result, indicating if the food is freshly prepared, packaged, or a general item.
The fetchFoodItemForDataInfo function retrieves detailed food information from Passio's database based on provided data fields. This function is also asynchronous and accepts a callback that returns a PassioFoodItem object with the full nutritional profile of the requested food item.
Input Parameters
foodDataInfo (PassioFoodDataInfo): A data object containing metadata about the food item, including its ID and a preview of its nutrition details.
servingQuantity (Double): The quantity or portion size of the food.
servingUnit (String): The unit of measurement for the serving size, such as grams, ounces, or pieces.
Output
The function returns a PassioFoodItem through the callback. This object contains the full nutritional breakdown of the food item, which can include: