Application Next.js qui détecte des aliments sur image/caméra (YOLOv8 segmentation ONNX) et estime calories + macros.
- Next.js 16 (App Router)
- React 19 + TypeScript
- Tailwind CSS v4
- onnxruntime-web (inférence dans un Web Worker)
npm install
# ou
pnpm installnpm run dev
npm run build
npm run start
npm run lint
npm run type-check- Scan via caméra
- Upload d'image
- Détection multi-aliments avec segmentation
- Estimation nutritionnelle par portion calibrée
- Historique local des scans
- Fallback mock si l'inférence échoue
src/hooks/useInference.tsinitialise le worker.src/workers/inference.worker.tschargepublic/models/best.onnxvia ONNX Runtime.- Prétraitement image dans
src/lib/inference/preprocessing.tsvers tensor1x3x640x640. - Parsing YOLO + NMS dans
src/workers/inference.worker.tsetsrc/lib/inference/nms.ts. - Génération masque + nutrition dans
src/lib/inference/postprocessing.ts.
La formule actuelle ne repose plus sur densité/épaisseur physiques.
totalPixels = 640 * 640
maskRatioRaw = pixelCount / totalPixels
maskRatioCalibrated = maskRatioRaw * MASK_RATIO_CALIBRATION
scaleFactor = maskRatioCalibrated / expectedMaskRatio
weightGrams = min(defaultPortionWeightG * scaleFactor, maxWeightG)Puis calories/macros sont calculées avec les valeurs per100g.
Les paramètres alimentaires sont dans src/lib/inference/foodDatabase.ts:
defaultPortionWeightGexpectedMaskRatiomaxWeightG
Le facteur global MASK_RATIO_CALIBRATION est défini dans src/lib/constants.ts.
src/
├── app/
├── components/
├── hooks/
│ ├── useCamera.ts
│ └── useInference.ts
├── lib/
│ ├── inference/
│ │ ├── foodDatabase.ts
│ │ ├── nms.ts
│ │ ├── postprocessing.ts
│ │ ├── preprocessing.ts
│ │ └── types.ts
│ ├── constants.ts
│ ├── mockNutrition.ts
│ └── workerClient.ts
└── workers/
└── inference.worker.ts
- Poids bloqués à
500g:- redémarrer
npm run dev - hard refresh navigateur (
Cmd+Shift+R) - vérifier les logs:
[Worker] Box stats[Postprocess] Mask stats[Nutrition] Weight calculation
- redémarrer
- Modèle introuvable:
- vérifier la présence de
public/models/best.onnx
- vérifier la présence de
- Warning ONNX
Unknown CPU vendor:- attendu sur certaines machines, non bloquant
L'application nécessite l'accès caméra pour le mode scan.