Deleted pytesseract logic

This commit is contained in:
kyy
2025-08-12 10:27:39 +09:00
parent 82d40f625a
commit 165c14acda
3 changed files with 5 additions and 54 deletions

View File

@@ -48,7 +48,8 @@
Docker Compose를 사용하여 프로젝트의 모든 서비스를 실행합니다.
```bash
docker-compose up -d --build
docker compose build ocr_perf_api
docker compose up -d --build
```
- API 서버는 `http://localhost:8892`에서 실행됩니다.
@@ -61,6 +62,7 @@ API 문서는 서버 실행 후 `http://localhost:8892/docs`에서 확인할 수
### OCR 작업 요청
- **POST /ocr/paddle**
- **설명**: Paddle OCR을 사용하여 OCR 작업을 요청합니다.
- **요청 본문**: `multipart/form-data` 형식의 파일 목록
- **응답**: 접수된 각 파일에 대한 작업 정보 (request_id, task_id 등)

View File

@@ -17,4 +17,5 @@ celery
flower
minio
opencv-python-headlesspython-dotenv
opencv-python-headless
python-dotenv

View File

@@ -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를 사용하여 이미지에서 텍스트 추출 및 좌표 정보 반환