-
Notifications
You must be signed in to change notification settings - Fork 2
tesseract_integration #656
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
Open
Dariiiii
wants to merge
26
commits into
master
Choose a base branch
from
tesseract-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d6b163c
v1
88f199c
v1.1
5ecde02
v2: edit cases
52d1afe
prototype: images readability check
Dariiiii e783ed9
fix image_quality_check
Dariiiii 5cc96ec
v1 image_quality_check
Dariiiii c15f5ab
tesseract prototype
Dariiiii f645a68
TODO: Implement Tesseract-based text check
Dariiiii 40cfc2d
tesseract check v1
Dariiiii b7acfcd
add TASK_SOFT_TIME_LIMIT
Dariiiii 456e238
Merge branch 'master' into image_check
HadronCollider 89ee03b
first fix
Dariiiii c59c475
trial version
Dariiiii 3f25405
correction of tesseract
Dariiiii 7906f70
Merge branch 'master' into tesseract-integration
Dariiiii 7c195c8
fix update_tesseract_criteria_result
Dariiiii 40f51be
update 469_extend_data_storage_model
Dariiiii 5fa3014
Merge branch 'image_check' into tesseract-integration
HadronCollider 24eb092
update docker base tag
HadronCollider fc8e0c1
Merge remote-tracking branch 'origin/master' into tesseract-integration
HadronCollider d05230a
Merge branch 'master' into tesseract-integration
HadronCollider 57bee01
correction of comments
Dariiiii 3b18e36
remove the typo
Dariiiii 050163a
fix bug
Dariiiii 3f3ef52
Merge branch 'master' into tesseract-integration
HadronCollider 5796e5f
update tesseract_worker volume
HadronCollider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import os | ||
| from celery import Celery | ||
| from celery.signals import worker_ready | ||
| import pytesseract | ||
| import cv2 | ||
| import numpy as np | ||
| from db import db_methods | ||
| from root_logger import get_root_logger | ||
|
|
||
| TASK_RETRY_COUNTDOWN = 60 | ||
| logger = get_root_logger('tesseract_tasks') | ||
|
|
||
| celery = Celery(__name__) | ||
| celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://redis:6379") | ||
| celery.conf.result_backend = os.environ.get("CELERY_RESULT_BACKEND", "redis://redis:6379") | ||
|
|
||
| celery.conf.timezone = 'Europe/Moscow' | ||
|
|
||
| TESSERACT_CONFIG = { | ||
| 'lang': 'rus', | ||
| 'config': '--psm 6', | ||
| } | ||
|
|
||
| @worker_ready.connect | ||
| def at_start(sender, **k): | ||
| logger.info("Tesseract worker is ready!") | ||
|
|
||
|
|
||
| @celery.task(name="tesseract_recognize", queue='tesseract-queue', bind=True) | ||
| def tesseract_recognize(self, image_id, image_data): | ||
| try: | ||
| image_array = np.frombuffer(image_data, dtype=np.uint8) | ||
| img_cv = cv2.imdecode(image_array, cv2.IMREAD_COLOR) | ||
| if img_cv is None: | ||
| raise ValueError("Не удалось декодировать изображение из двоичных данных") | ||
| text = pytesseract.image_to_string(img_cv, **TESSERACT_CONFIG) | ||
| success = db_methods.update_image_text(image_id, text) | ||
| if not success: | ||
| logger.error(f"Не удалось записать текст для image_id: {image_id}") | ||
| raise Exception("Ошибка при обновлении текста изображения в базе данных") | ||
| logger.info(f"Текст успешно распознан и записан для image_id: {image_id}") | ||
| return text | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Ошибка при распознавании текста: {e}", exc_info=True) | ||
| if self.request.retries == self.max_retries: | ||
| logger.error(f"Достигнуто максимальное количество попыток для image_id: {image_id}") | ||
| return f"Ошибка: {e}" | ||
| self.retry(countdown=TASK_RETRY_COUNTDOWN) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Полезный момент на будущее - добавить checksum на случай дубликатов (чтобы одна одинаковая фотка в 100 отправок / отчетах нам не занимала лишнее место и ресурсы на обработку)