Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(proofs): more features to OCR extraction #566

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion open_prices/proofs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def run_ocr_on_image(image_path: Path | str, api_key: str) -> dict[str, Any] | N
:param image_path: the path to the image
:param api_key: the Google Cloud Vision API key
:return: the OCR data as a dict or None if an error occurred

This is similar to the run_ocr.py script in openfoodfacts-server:
https://github.com/openfoodfacts/openfoodfacts-server/blob/main/scripts/run_ocr.py
"""
with open(image_path, "rb") as f:
image_bytes = f.read()
Expand All @@ -152,7 +155,13 @@ def run_ocr_on_image(image_path: Path | str, api_key: str) -> dict[str, Any] | N
json={
"requests": [
{
"features": [{"type": "TEXT_DETECTION"}],
"features": [
{"type": "TEXT_DETECTION"},
{"type": "LOGO_DETECTION"},
{"type": "LABEL_DETECTION"},
{"type": "SAFE_SEARCH_DETECTION"},
{"type": "FACE_DETECTION"},
],
"image": {"content": base64_content},
}
]
Expand Down
Loading