Start food detection
Camera
<uses-permission android:name="android.permission.CAMERA">Import the SDK
import {
PassioSDK,
DetectionCameraView,
} from '@passiolife/nutritionai-react-native-sdk-v2';<DetectionCameraView style={{flex: 1, width: '100%'}} />The SDK can detect 4 different categories: VISUAL, BARCODE, PACKAGED FOOD and NUTRITION LABEL
const config: FoodDetectionConfig = {
/**
* Detect barcodes on packaged food products. Results will be returned
* as `BarcodeCandidates` in the `FoodCandidates` property of `FoodDetectionEvent`
*/
detectBarcodes: true,
/**
* Results will be returned as DetectedCandidate in the `FoodCandidates`and
* property of `FoodDetectionEvent`
*/
detectPackagedFood: true,
/**
* Detect barcodes on packaged food products. Results will be returned
* under the `nutritionFacts` property on `FoodDetectionEvent`.
*/
detectNutritionFacts: true,
};
useEffect(() => {
if (!isReady) {
return;
}
const subscription = PassioSDK.startFoodDetection(
config,
async (detection: FoodDetectionEvent) => {
const { candidates, nutritionFacts } = detection
if (candidates?.barcodeCandidates?.length) {
// show barcode candidates to the user
} else if (candidates?.packagedFoodCode?.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]);
Last updated