Food Quantity Confirmation

Confirm how much was eaten (grams or Small/Medium/Big portion) and auto‑recalculate ingredients & nutrition.

What You’ll Build

You’ll implement a quantity confirmation flow: once a dish is detected and confirmed, your app lets users specify how much they ate—either in grams, via SMALL / MEDIUM / BIG buttons or with a slider. The selected quantity updates the standardized ingredients and the nutritional breakdown for the intake.

Optionally, reduce guesswork by anchoring on the dish’s standard serving size (MEDIUM) and applying a simple ±50% adjustment for SMALL/BIG, or a precise grams input, so developers can provide quick, accessible controls and users get accurate totals. Using a slider is also a good alternative for the user to report the food quantity.


Prerequisites

  • Plan: Analyse and above (see more info about LogMeal Plans)
  • User type: 🔴 APIUser (see more info about User Types)
  • Client library for HTTP (e.g., Python requests, Node axios, Java OkHttp).
  • 1–2 sample food images for testing (JPEG/PNG). For best results, confirm dishes before confirming quantity.

Sequence Diagrams

Main Flow

sequenceDiagram
  participant User
  participant App
  participant LogMeal API

  User->>App: Capture/choose meal photo
  App->>LogMeal API: POST /v2/image/segmentation/complete <br> (Authorization: APIUser token, image)
  LogMeal API-->>App: 200 OK (imageId, segmentation results)
  App-->>User: Show top dish candidates per detected item
  User->>App: Confirm/adjust dish per item
  App->>LogMeal API: POST /v2/image/confirm/dish (imageId, confirmed items)
  LogMeal API-->>App: 200 OK (confirmed items)
  App->>User: Ask quantity (grams or SMALL / MEDIUM / BIG or slider)
  App->>LogMeal API: POST /v2/nutrition/confirm/quantity (imageId, quantity/portion)
  LogMeal API-->>App: 200 OK (quantity confirmed)
  App->>LogMeal API: POST /v2/nutrition/recipe/ingredients (imageId)
  LogMeal API-->>App: 200 OK (ingredients recalculated to quantity)
  App->>LogMeal API: POST /v2/nutrition/recipe/nutritionalInfo (imageId)
  LogMeal API-->>App: 200 OK (nutrition recalculated to quantity)
  App-->>User: Display updated ingredients & nutrients
ℹ️

Portion guidance: MEDIUM equals the dish’s standard serving size already used by ingredients and nutrition. Optionally use SMALL = −50% and BIG = +50% relative to MEDIUM. This keeps the UI simple while delivering accurate totals. See also guidance from Know Diabetes (knowdiabetes.org.uk).


Implementation Guide

Implementation Examples (Recipes)

See dedicated Recipes for runnable code and JSON response examples:

  1. Set profile data once to improve label language and regional dishes:
  1. Send the image for segmentation to obtain regions and top dish candidates per region. Display the top 5 candidate dishes per region.
  1. Ask the user to confirm or correct the dishes appearing on the image:
  1. Confirm the consumed quantity (grams or SMALL/MEDIUM/BIG or using a slider):
  1. Retrieve the standardized ingredients adjusted to the confirmed quantity:
  1. Retrieve the nutritional information (macros & micros) adjusted to the confirmed quantity:

User Interaction Recommendations

  • Provide SMALL / MEDIUM / BIG quick actions; MEDIUM is default.
  • Offer a grams text field or slider for precision entry.
  • After changes, preview the recalculated energy and macros before saving.
  • For multi-dish images, confirm quantity per item and show per-item and total rows.
  • Keep units consistent (g, mg, kcal) and localize labels/units by user profile.

Related Endpoints


Common Pitfalls & Tips

  • Confirm dishes first to maximize downstream accuracy of quantity, ingredients, and nutrients.
  • Treat MEDIUM as the system’s standard serving; optionally apply ±50% for SMALL/BIG if you don’t collect grams.
  • When users edit ingredients or quantities afterward, recompute nutrition to keep totals in sync.
  • Persist the original serving size and the user‑confirmed quantity for auditability and easy recalculation.

Optional Enhancements


Next Steps

  • Chain with nutrition analysis and history dashboards.
  • Offer ingredients editing after quantity confirmation.
  • Review Plans & Limits before going to production.