Deleted pytesseract logic
This commit is contained in:
@@ -7,7 +7,6 @@ import cv2
|
||||
import docx # PyMuPDF, python-docx
|
||||
import fitz
|
||||
import numpy as np
|
||||
import pytesseract
|
||||
from paddleocr import PaddleOCR
|
||||
from pdf2image import convert_from_path
|
||||
from PIL import Image
|
||||
@@ -49,10 +48,6 @@ async def extract_text_from_file(file_path):
|
||||
)
|
||||
raise ValueError("지원하지 않는 파일 형식입니다.")
|
||||
|
||||
# full_response, coord_response = await asyncio.to_thread(
|
||||
# extract_text_ocr, images
|
||||
# )
|
||||
# return full_response, coord_response, "pytesseract"
|
||||
full_response, coord_response = await asyncio.to_thread(
|
||||
extract_text_paddle_ocr, images
|
||||
)
|
||||
@@ -107,56 +102,9 @@ def preprocess_image_for_ocr(pil_img, page_idx=None):
|
||||
img, None, fx=2, fy=2, interpolation=cv2.INTER_LINEAR
|
||||
) # 해상도 확대
|
||||
|
||||
# # ✅ 전처리 이미지 저장
|
||||
# save_path = os.path.join("preprocess_image.png")
|
||||
# logger.info(f"[UTILS-OCR] 전처리 이미지 저장: {save_path}")
|
||||
# cv2.imwrite(save_path, img)
|
||||
|
||||
return Image.fromarray(img)
|
||||
|
||||
|
||||
# ✅ OCR 수행 (좌표 포함)
|
||||
def extract_text_ocr(images):
|
||||
"""
|
||||
tesseract를 사용하여 이미지에서 텍스트 추출 및 좌표 정보 반환
|
||||
"""
|
||||
all_texts = []
|
||||
coord_response = []
|
||||
|
||||
for page_idx, img in enumerate(images):
|
||||
logger.info(f"[UTILS-OCR] 페이지 {page_idx + 1} OCR로 텍스트 추출 중...")
|
||||
pre_img = preprocess_image_for_ocr(img)
|
||||
text = pytesseract.image_to_string(
|
||||
pre_img, lang="kor+eng", config="--oem 3 --psm 6"
|
||||
)
|
||||
all_texts.append(text)
|
||||
|
||||
ocr_data = pytesseract.image_to_data(
|
||||
pre_img,
|
||||
output_type=pytesseract.Output.DICT,
|
||||
lang="kor+eng",
|
||||
config="--oem 3 --psm 6",
|
||||
)
|
||||
for i in range(len(ocr_data["text"])):
|
||||
word = ocr_data["text"][i].strip()
|
||||
if word == "":
|
||||
continue
|
||||
x, y, w, h = (
|
||||
ocr_data["left"][i],
|
||||
ocr_data["top"][i],
|
||||
ocr_data["width"][i],
|
||||
ocr_data["height"][i],
|
||||
)
|
||||
coord_response.append(
|
||||
{"text": word, "coords": [x, y, x + w, y + h], "page": page_idx + 1}
|
||||
)
|
||||
|
||||
logger.info(f"[UTILS-OCR] 페이지 {page_idx + 1} 텍스트 및 좌표 추출 완료")
|
||||
|
||||
full_response = "\n".join(all_texts)
|
||||
return full_response, coord_response
|
||||
|
||||
|
||||
def extract_text_paddle_ocr(images):
|
||||
"""
|
||||
PaddleOCR를 사용하여 이미지에서 텍스트 추출 및 좌표 정보 반환
|
||||
|
||||
Reference in New Issue
Block a user