Start food detection
Once the SDK is ready, you can start food detection.
Camera
Android Platform: You need the user's permission to access the camera.
<uses-permission android:name="android.permission.CAMERA">
IOS Platform: Enter a value for NSCameraUsageDescription
in your Info.plist so the camera may be utilized.
Import the SDK
import {
PassioSDK,
DetectionCameraView,
} from '@passiolife/react-native-passio-sdk';
To show the live camera preview, add the DetectionCameraView
to your view
<DetectionCameraView style={{flex: 1, width: '100%'}} />
The SDK can detect 3 different categories: VISUAL, BARCODE and OCR.
const config: FoodDetectionConfig = {
detectBarcodes: true,
detectOCR: true,
detectNutritionFacts: true,
};
useEffect(() => {
if (!isReady) {
return;
}
const subscription = PassioSDK.startFoodDetection(
config,
async (detection: FoodDetectionEvent) => {
console.log('Got food detection event: ', detection);
const { candidates, nutritionFacts } = detection
if (candidates?.barcodeCandidates?.length) {
// show barcode candidates to the user
} else if (candidates?.ocrCandidates?.length) {
// show OCR candidates to the user
} else if (candidates?.detectedCandidates?.length) {
// show visually recognized candidates to the user
} else if (nutritionFacts) {
// Show scanned nutrition facts to the user
}
},
);
// stop food detection when component unmounts
return () => subscription.remove();
}, [isReady]);
Try to run the above code in component and Point the phone to the image below and see if you are getting the correct food in console log Got food detection event

If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Last updated