ocr / ocr_utils.py
Shabdobhedi's picture
Update ocr_utils.py
e533ffc verified
raw
history blame contribute delete
840 Bytes
# ocr_utils.py
import easyocr
import numpy as np
# Initialize the EasyOCR reader for Hindi and English
reader = easyocr.Reader(['hi', 'en'])
def extract_text(image_np):
"""
Extract text from a NumPy array image using EasyOCR.
Parameters:
- image_np: NumPy array representation of the image.
Returns:
- full_text: Extracted text as a single string.
"""
extracted_text = reader.readtext(image_np, detail=0)
full_text = " ".join(extracted_text)
return full_text
def highlight_content(full_text, keyword):
if keyword:
# Highlight the keyword in the text
highlighted_text = full_text.replace(
keyword, f"<span class='highlight'>{keyword}</span>"
)
return highlighted_text
else:
return "No keyword entered for highlighting."