Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Every call to the SDK is made through the singleton object obtained with PassioSDK.instance call. The SDK is designed to be called from the main thread, and it will deliver results to the main thread. Its internal tasks will be run by Passio threads, so you don't need to manage the threading execution.
Two things are required for the SDK to work: a proper license key and the neural network files that the SDK uses to run the recognition process.
The license key can be requsted at support@passiolife.com
The files are shipped inside the PassioSDKSandbox project on the releases page of the Android-Passio-SDK-Distribution repository. Unzip the PassioSDKSandbox project and locate the files in the assets folder: /PassioSDKSandbox/app/src/main/assets. Files that the SDK needs have an extension .passiosecure and are encrypted
There are several ways to initialize the SDK depending on the location of the needed files:
Files are in the assets folder of your Android project
Let the SDK manage file download and update
Host the files on your own server, download the files, store them on the device's memory and point the SDK to the URIs of the needed files
For a first time integration the first approach is recommended
If the assets folder is not already present in your Android project, create one in the module where the SDK dependencies are located under the main directory (e.g. app/src/main/assets)
Transfer the .passiosecure files to the assets folder
Create a PassioConfiguration object with the application context and the license key
Call the configure method of the PassioSDK without changing the default PassioConfiguration object
By setting the sdkDownloadsModels field to true the SDK will do the initial download of the files. If the current files that are present on the device are older than the version of the SDK library, the SDK will download the newer version in the background, but still run the session with the older version of the files. Once the download is finished, the new files will be applied on the next session.
To track the download process you can implement a PassioStatusListener (recommended to define after the PassioStatus mode returns IS_DOWNLOADING_MODELS)
This approach is recommended if you are responsible for the download of the files. In this case the SDK does not care where the files are hosted and how they are downloaded, just where they are stored after the download has completed. Use the PassioConfiguration object to modify the initialization process with local files and pass the URIs of the files to the localFiles field.
After the configuration process is successful, delete the files from local device storage. The SDK will copy them over to its internal folder.
When you call the configure method of the Passio SDK with the PassioConfiguration object, you will need to define a callback to handle the result of the configuration process. This result is comprised in the PassioStatus object.
The mode of PassioStatus defines what the current status of the configuration process is. There are 5 different modes, and they all should be handled by the implementing side.
NOT_READY -> The configuration process hasn't started yet.
FAILED_TO_CONFIGURE -> The configuration process resulted in an error. Be sure to check the debugMessage of the PassioStatus object to get more insight into the nature of the error.
IS_BEING_CONFIGURED -> The SDK is still in the configuration process. Normally, you shouldn't receive this mode as a callback to the configure method.
IS_DOWNLOADING_MODELS -> The files required for the SDK to work are not present and are currently being downloaded.
IS_READY_FOR_DETECTION -> The configuration process is over and all the SDKs functionalities are available.
The missingFiles variable contains a list of all the files missing for the SDK to work optimally. When this list is not null, this doesn't mean that the SDK is not operational. The SDK may be initialized with older files, but it will advocate the download of the newest files through this list.
The debugMessage usually gives more verbose and human-readable information about the configuration process. It will always give an error message if the mode is FAILED_TO_CONFIGURE.
The activeModels will give the version of the files installed and ran by the SDK if the configuration process ran successfully i.e. if the mode is IS_READY_FOR_DETECTION.
The PassioStatus mode is NOT_READY -> check debugMessage for the error, usually the wrong license key has been supplied or the files are missing.
The PassioStatus mode is IS_DOWNLOADING_MODELS -> register a PassioStatusListener through the PassioSDK.instance.setPassioStatusListener() method as it will enable tracking of the download progress.
The PassioStatus mode is IS_READY_FOR_DETECTION -> still check the missingFiles because the SDK might be running with an older version of the files and newer need to be downloaded.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Passio Nutrition AI Android SDK Documentation
The SDK can detect 3 different categories: VISUAL, BARCODE and PACKAGED. The VISUAL recognition is powered by Passio's neural network and is used to recognize over 3000 food classes. BARCODE, as the name suggests, can be used to scan a barcode located on a branded food. Finally, PACKAGED can detect the name of a branded food. To choose one or more types of detection, a FoodDetectionConfiguration object is defined and the corresponding fields are set. The VISUAL recognition works automatically.
To start the Food Recognition process a FoodRecognitionListener also has to be defined. The listener serves as a callback for all the different food detection processes defined by the FoodDetectionConfiguration.
Only the corresponding candidate lists will be populated (e.g. if you define detection types VISUAL and BARCODE, you will never receive a packagedFoodCandidates list in this callback).
Using the listener and the detection options start the food detection by calling the startFoodDetection method of the SDK.
Stop the food recognition in the onStop() lifecycle callback.
Try to run the code containing the foodListener defined above. Point the phone at the image below and see if you are getting the correct food printed on the screen (it should be red apples, but if it isn't don't worry, we'll cover the data structure later).
When starting the food detection with the FoodRecognitionListener as the callback, on every frame analyzed you will receive a FoodCandidates object. This is the structure of that data class:
You can see the structure of all the detection classes in the file called PassioAPI.kt
Depending on how you structured the FoodDetectionConfiguration object, some fields of the FoodCandidates object might be null. If the field is null it means that that type of detection has not been run. On the other hand, if the detection process ran to completion and the list is empty, then that type of detection could not recognize anything from the given frame.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
To start using the camera in your Activity/Fragment, implement the PassioCameraViewProvider interface. By implementing this interface the SDK will use that component as the lifecycle owner of the camera (when that component calls onPause() the camera will stop) and also will provide the Context in order for the camera to start. The component implementing the interface must have a in its view hierarchy.
Start by adding the PreviewView to your view hierarchy. Go to your layout.xml and add the following.
The SDK requires the device's Camera to work. To ensure that the Camera is working and sending frames to analyze, you need the user's permission to access the camera. As of now, only the back camera is supported by the SDK. There are two ways to implement Camera usage along with the permission request. Review both of these strategies and choose what best suits your code.
PassioCameraFragment is an abstract class that handles Camera permission at runtime as well as starting the Camera process of the SDK. To use the PassioCameraFragment simply extend it in your own fragment and supply the PreviewView that has been added to the view hierarchy in the previous step.
This approach is more manual but gives you more flexibility. You need to implement the PassioCameraViewProvider interface and supply the needed LifecycleOwner and the PreviewView added in the initial step.
Finally, after the user has granted permission to use the camera, start the SDK camera
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Once the food detection process has returned a PassioID, it is time to query the database and see what information Passio has on the detected food.
All the calls to the database are synchronous and are executed on the caller thread. For better performance execute these calls on a background thread.
The most detailed information can be found in the PassioIDAttributes object. To retrieve this object from a given PassioID, simply call
This call may return null if the given PassioID can't be found in the database. Be sure to check the nullability of the return object before proceeding.
Here we will cover the fields that are not self-explanatory:
The image for a food can also be retrieved using the PassioID and the method
parents, children, siblings - All the foods in Passio's Nutritional Database are organized in a tree-like structure with each PassioID being a node in that tree. Let's say we scanned a "mandarin". A child of a "mandarin" is a "tangerine", and its parent is a "whole citrus fruit". We can offer these alternatives to the user in case the user is pointing to a similar food to a mandarin.
passioFoodItemDataForDefault, passioFoodRecipe - The SDK differentiates single food items and food recipes. A single item represents just one particular food like an apple or peas. A food recipe consists of more than one single food item. For example a recipe is a Caprese salad which consists of mozzarella, tomatoes, basil, salt, black pepper and olive oil.
PassioFoodItemData holds the nutritional information for a food item like calories, carbs, protein, fat etc. It also has a reference weight on which these values are calculated and contains serving sizes and serving units. Serving sizes offer you quick options to select the size of the food with a given quantity and unit.
Recipes should be viewed as a collection of PassioFoodItemData objects.
If you have a PassioID returned from the detection process and you are just interested in the name of the corresponding food, use
To query the names of the foods from the database by a filter use
The returned list contains a PassioID paired with the name of the food.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
The Passio Android SDK is shipped in the form of an file.
Visit the of the Android-Passio-SDK-Distribution GitHub repository. Download the passiolib-release.aar file from the latest release.
If you don't have access to the repository please contact our support team at support@passiolife.com
To include the .aar file into your project go to the module that will contain the food recognition feature. Place the .aar file in the libs folder of the module. If the libs folder is missing, create one. Reference the .aar file in the build.gradle file of the implementing module.
Sync Project with Gradle Files and be sure that you can reference the PassioSDK class within your code.
Passio Android SDK is powered by and with the camera being managed by . Add the dependencies to these three projects by adding these lines to the module's build.gradle file.
In order for the SDK to work add the following lines to the android section of the module's build.gradle file.
Running Sync Project with Gradle Files will enable access to the SDK.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Note: Some of these detections might not be accessible to you if your license does not include that module
A DetectedCandidate represents the result from running Passio's neural network, specialized for detecting foods like apples, salads, burgers etc.
The PassioID is a unique identifier for food that is used to query our Nutritional Database. See section for more details.
Try to opt in for BARCODE by enabling the flag detectBarcodes and point your device at the image of the barcodes below. The SDK's barcode detector will recognize the barcode and it will return the barcode number inside the BarcodeCandidate object.
Use the barcode field to query Passio's backend and if the scanned food can be found in Passio's database, a PassioIDAttributes object will be returned.
The Visual Detection process can detect up to 5 objects per frame. Depending on your UI/UX you can display all the results to the end user, or just choose one of them. The criteria to choose the best candidate from a list is up to you, but the two most common strategies are the biggest bounding box or the highest confidence. This biggest bounding box represents the biggest object on the frame and the highest confidence points to the object that the neural network is most sure about.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Acquire the user's permission to use the Camera with these
imageName - An identifier for the image of the food. To retrieve the for the given image name use
Passio uses to recognize names of branded foods. Opt in with FoodDetectionConfiguration.detectPackagedFood and if the SDK has recognized a branded food that is present in Passio's Nutritional Database it will return the PackagedFoodCandidate of that food item. To retrieve full information about the item call: