extractIngredients static method

Future<OcrIngredientsResult> extractIngredients(
  1. User user,
  2. String barcode,
  3. OpenFoodFactsLanguage language, {
  4. OcrField ocrField = OcrField.GOOGLE_CLOUD_VISION,
  5. QueryType? queryType,
})

Extract the ingredients from image with the given parameters. The ingredients language should be given (ingredients_fr, ingredients_de, ingredients_en) Returns the ingredients using OCR. By default the query will use the Google Cloud Vision.

Implementation

static Future<OcrIngredientsResult> extractIngredients(
  User user,
  String barcode,
  OpenFoodFactsLanguage language, {
  OcrField ocrField = OcrField.GOOGLE_CLOUD_VISION,
  QueryType? queryType,
}) async {
  final Uri uri = UriHelper.getPostUri(
    path: '/cgi/ingredients.pl',
    queryType: queryType,
  );
  final Map<String, String> queryParameters = <String, String>{
    'code': barcode,
    'process_image': '1',
    'id': 'ingredients_${language.offTag}',
    'ocr_engine': ocrField.offTag
  };
  final Response response = await HttpHelper().doPostRequest(
    uri,
    queryParameters,
    user,
    queryType: queryType,
    addCredentialsToBody: false,
  );
  return OcrIngredientsResult.fromJson(
    json.decode(utf8.decode(response.bodyBytes)) as Map<String, dynamic>,
  );
}