Changes

Jump to navigation Jump to search
897 bytes added ,  13:36, 8 December 2022
no edit summary
Line 1: Line 1:  
[[Category:Developer]] [[Category:API]]
 
[[Category:Developer]] [[Category:API]]
 
<Back to [[API/Write]](Required reading)
 
<Back to [[API/Write]](Required reading)
 
+
<big>
 +
The new version of the documentation is available here:
 +
* [https://openfoodfacts.github.io/api-documentation/ API V2 - Comprehensive but not OpenAPI compliant] - It contains uses cases for displaying a product, and letting your users add the data required to get the Nutri-Score, the NOVA classification, additives, and the Eco-Score.
 +
* [https://openfoodfacts.github.io/openfoodfacts-server/reference/api/ API V2 - new OpenAPI documentation] - Work in Progress
 +
* [https://openfoodfacts.github.io/openfoodfacts-server/reference/api-v3/ API V3 - new OpenAPI documentation] - Work in Progress
 +
</big>
 
=== Manipulating photos for a product ===
 
=== Manipulating photos for a product ===
 
==== Understanding products and photos ====
 
==== Understanding products and photos ====
 
* Photos are the primary source of Open Food Facts.
 
* Photos are the primary source of Open Food Facts.
 
* We need good photos of the '''product''', of its '''ingredients''' and '''nutrition table'''. (and for each language present on the packaging)
 
* We need good photos of the '''product''', of its '''ingredients''' and '''nutrition table'''. (and for each language present on the packaging)
 +
* <span style="color:#d33">Good photos means a minimal allowed size: 640 x 160.</span>
 
* Please encourage your users to add as many photos as possible, even if the product is already complete (in that case, don't set them as default photos for  front, ingredients, and nutrition)
 
* Please encourage your users to add as many photos as possible, even if the product is already complete (in that case, don't set them as default photos for  front, ingredients, and nutrition)
   Line 22: Line 28:     
===== Parameters =====
 
===== Parameters =====
* code: the barcode
+
* code: the barcode of the product
* imagefield: (front | ingredients | nutrition)
+
* imagefield: (can be either: front | ingredients | nutrition)
* imgupload_front : your image file if imagefield:front
+
* imgupload_front : your image file if imagefield=front
* imgupload_ingredients: your image file if imagefield:ingredients
+
* imgupload_ingredients: your image file if imagefield=ngredients
* imgupload_nutrition: your image file if imagefield:nutrition
+
* imgupload_nutrition: your image file if imagefield=nutrition
 
      
===== Example =====
 
===== Example =====
Line 279: Line 284:  
Values:
 
Values:
 
==== Selecting a photo ====
 
==== Selecting a photo ====
<pre>imgid=</pre>
+
<pre>product_image_crop.pl?code=3266110700910&id=nutrition_fr&imgid=1</pre>
Values:
+
<pre>
 +
id: the field you want to attribute the image to
 +
code: the barcode of the product
 +
imgid: the image id you want to select into the field
 +
</pre>
 +
<pre>
 +
id can be:
 +
front_fr
 +
nutrition_fr
 +
ingredients_fr
 +
 
 +
front_nl
 +
nutrition_nl
 +
ingredients_nl
 +
 
 +
 +
</pre>
 +
<pre>
 +
You retrieve the photo id when you upload it
 +
</pre>
 +
 
 
==== Rotating a photo ====
 
==== Rotating a photo ====
 
<pre>Test server: https://world.openfoodfacts.net/cgi/product_image_rotate.pl</pre>
 
<pre>Test server: https://world.openfoodfacts.net/cgi/product_image_rotate.pl</pre>
<pre>Live server: https://world.openfoodfacts.org/cgi/product_image_rotate.pl</pre>
+
<pre>
===== Values and output =====
+
Parameters:
 +
</pre>
 +
===== Getting the preview =====
 
Parameters:
 
Parameters:
 
<pre>
 
<pre>
Line 302: Line 329:  
}
 
}
 
</pre>
 
</pre>
 +
===== Actually rotating the photo =====
 +
https://world.openfoodfacts.org/cgi/product_image_crop.pl?code=3266110700910&id=nutrition_fr&imgid=1&angle=90
   −
==== Removing background on a photo ("White magic") ====
+
==== Removing background on a photo ====
 
This will work best on photos with a white background. Best use case is to let user try it and give up if the result is not satisfying.
 
This will work best on photos with a white background. Best use case is to let user try it and give up if the result is not satisfying.
 
<pre>white_magic=</pre>
 
<pre>white_magic=</pre>
 
Values:
 
Values:
   −
==== Color correction on a photo ("Normalize")====
+
==== Perform color correction on a photo ====
 
<pre>normalize=</pre>
 
<pre>normalize=</pre>
 
Values:
 
Values:
Line 315: Line 344:  
This implies applying operations to a source image (not only cropping, but all the others if applicable). We start from a source image (defined by a barcode and incremental id), apply cropping parameters (x1, y1, x2, y2), additional operations (white_magic, normalize)
 
This implies applying operations to a source image (not only cropping, but all the others if applicable). We start from a source image (defined by a barcode and incremental id), apply cropping parameters (x1, y1, x2, y2), additional operations (white_magic, normalize)
 
<br>
 
<br>
   
<pre>Test server: https://world.openfoodfacts.net/cgi/product_image_crop.pl</pre>
 
<pre>Test server: https://world.openfoodfacts.net/cgi/product_image_crop.pl</pre>
<pre>Live server: https://world.openfoodfacts.org/cgi/product_image_crop.pl</pre>
+
<pre>https://world.openfoodfacts.org/cgi/product_image_crop.pl?code=1&imgid=2&id=front_en&x1=0&y1=0&x2=145&y2=145</pre>
 
=====Values=====
 
=====Values=====
 
<pre>
 
<pre>
Line 324: Line 352:  
angle= Angle of the rotation
 
angle= Angle of the rotation
 
normalize = whether the source image should be normalized
 
normalize = whether the source image should be normalized
white_magic = whether the source image should be white magiced ( background removal)
+
white_magic = whether the source image should be white magiced (background removal)
 
type = add
 
type = add
 
action = display
 
action = display
imgid =
+
imgid = the id of the source image
x1= the X origin of the crop
+
x1 = the X origin of the crop
y1=the Y origin of the crop
+
y1 = the Y origin of the crop
x2=the X end of the crop
+
x2 = the X end of the crop
y2=the Y end of the crop
+
y2 = the Y end of the crop
 
</pre>
 
</pre>
   Line 355: Line 383:     
==== Performing OCR on a photo ====
 
==== Performing OCR on a photo ====
We start from a source image (defined by barcode and id) as selected for ingredients. We ask Product Opener to process it (process_image=1). Product Opener returns a JSON. Processing is done using Tesseract (3 on preprod). The result is often cripped with errors. Take steps to avoid direct copy pasting into the ingredients field by your users.
+
We start from a source image (defined by barcode and id) as selected for ingredients. We ask Product Opener to process it (process_image=1). Product Opener returns a JSON. Processing is done using Tesseract or Google Cloud Vision. The result is often cripped with errors with Tesseract, less with Google Cloud Vision. Take steps to ensure your users correct the output. Do send the corrected output using the ingredients WRITE API. If possible, please use your own OCR, this costs us money, and we're a non-profit with no budget.
    
<pre>Test server: https://world.openfoodfacts.net/cgi/ingredients.pl</pre>
 
<pre>Test server: https://world.openfoodfacts.net/cgi/ingredients.pl</pre>
<pre>Live server: https://world.openfoodfacts.net/cgi/ingredients.pl</pre>
   
===== Values and output =====
 
===== Values and output =====
 
<pre>
 
<pre>
Line 366: Line 393:  
</pre>
 
</pre>
   −
This will return JSON
+
Example:
 
  −
===== Ignore me =====
   
<pre>
 
<pre>
$.post('/cgi/ingredients.pl',
+
ingredients.pl?code=13333560&id=ingredients_en&process_image=1&ocr_engine=tesseract
{ }, function(data) {
  −
  −
if (data.status == 0) {
  −
$('div[id="ocrbuttondiv_' + imagefield +'"]').html(Lang.extracted_ingredients_ok);
  −
var ingredients_text_id = imagefield.replace("ingredients","ingredients_text");
  −
$("#" + ingredients_text_id).val(data.ingredients_text_from_image);
  −
}
  −
else {
  −
$('div[id="ocrbuttondiv_' + imagefield +'"]').html(Lang.extracted_ingredients_nok);
  −
}
  −
$(document).foundation('equalizer', 'reflow');
  −
}, 'json');
   
</pre>
 
</pre>
 +
This will return JSON

Navigation menu