Files
welcomecenterbot/nlp/ocr.py

16 lines
530 B
Python
Raw Normal View History

2024-09-28 10:06:04 +03:00
import easyocr
import logging
logger = logging.getLogger("[ocr] ")
# 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)
# Extract the recognized text from the result
2024-09-28 11:12:42 +03:00
recognized_text = ' '.join([text[0] for text, _, _ in result if isinstance(text, list) and text])
2024-09-28 10:06:04 +03:00
logger.debug(f'recognized_text: {recognized_text}')
return recognized_text