2024-09-28 07:06:04 +00:00
|
|
|
import easyocr
|
|
|
|
import logging
|
|
|
|
|
2024-09-28 08:17:20 +00:00
|
|
|
logger = logging.getLogger(" ocr ")
|
2024-09-28 07:06:04 +00:00
|
|
|
|
|
|
|
# Initialize the EasyOCR reader
|
|
|
|
reader = easyocr.Reader(['ru']) # Specify the languages you want to support
|
|
|
|
|
|
|
|
def ocr_recognize(file_path):
|
|
|
|
# Use EasyOCR to detect text in the photo
|
|
|
|
result = reader.readtext(file_path)
|
2024-09-28 08:23:10 +00:00
|
|
|
logger.debug("OCR Result: %s", result)
|
2024-09-28 08:17:20 +00:00
|
|
|
|
2024-09-28 08:23:10 +00:00
|
|
|
# Extract recognized text
|
|
|
|
recognized_text = ' '.join([text[1] for text in result if isinstance(text, tuple) and len(text) > 1])
|
2024-09-28 08:17:20 +00:00
|
|
|
|
2024-09-28 08:23:10 +00:00
|
|
|
logger.debug(f'Recognized Text: {recognized_text}')
|
2024-09-28 07:06:04 +00:00
|
|
|
return recognized_text
|