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):
|
2024-09-28 08:33:55 +00:00
|
|
|
sum_text = ""
|
|
|
|
|
2024-09-28 07:06:04 +00:00
|
|
|
# Use EasyOCR to detect text in the photo
|
2024-09-28 08:33:55 +00:00
|
|
|
results = reader.readtext(file_path)
|
2024-09-29 05:27:06 +00:00
|
|
|
result = result[-1]
|
|
|
|
[_coords, ocr_text, ocr_accuracy] = result
|
|
|
|
logger.debug("OCR Result: %s", ocr_text)
|
|
|
|
if ocr_accuracy.item() > 0.5:
|
|
|
|
sum_text += " " + ocr_text
|
2024-09-29 05:12:05 +00:00
|
|
|
|
2024-09-28 08:17:20 +00:00
|
|
|
|
2024-09-28 08:33:55 +00:00
|
|
|
logger.debug(f'Recognized Text: {sum_text}')
|
|
|
|
return sum_text
|