extractIngredients static method
Future<OcrIngredientsResult>
extractIngredients(
- User user,
- String barcode,
- OpenFoodFactsLanguage language, {
- OcrField ocrField = OcrField.GOOGLE_CLOUD_VISION,
- UriProductHelper uriHelper = uriHelperFoodProd,
Extract the ingredients from image with the given parameters. The ingredients' language should be given (ingredients_fr, ingredients_de, ingredients_en)
Uses an already uploaded ingredients image.
Please only use if you have before uploaded a new ingredients image or if there is already an ingredients image but no extracted ingredients.
User user = User(userId: '', password: '');
OcrIngredientsResult result = await OpenFoodAPIClient.extractIngredients(
user,
'3274080005003',
OpenFoodFactsLanguage.FRENCH,
);
print(result.ingredientsTextFromImage); // EAU DE SOURCE DE LA DOYE BOUTEILIF Moll
ยดยดยด
Implementation
static Future<OcrIngredientsResult> extractIngredients(
User user,
String barcode,
OpenFoodFactsLanguage language, {
OcrField ocrField = OcrField.GOOGLE_CLOUD_VISION,
final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
final Uri uri = uriHelper.getPostUri(
path: '/cgi/ingredients.pl',
);
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,
uriHelper: uriHelper,
addCredentialsToBody: false,
);
return OcrIngredientsResult.fromJson(
HttpHelper().jsonDecode(utf8.decode(response.bodyBytes))
as Map<String, dynamic>,
);
}