diff --git a/app/api/ocr.py b/app/api/ocr.py index f26bf25..4cffe4e 100644 --- a/app/api/ocr.py +++ b/app/api/ocr.py @@ -1,7 +1,18 @@ -from fastapi import APIRouter +from fastapi import APIRouter, UploadFile, File +from PIL import Image +import io +import pytesseract router = APIRouter() @router.post("/") -def init(): - return \ No newline at end of file +async def process_ocr(file: UploadFile = File(...)) -> str: + #받아온 파일 byte stream으로 읽기 + image_byte = await file.read() + #byte stream을 image파일로 변환 + image = Image.open(io.BytesIO(image_byte)) + #image > txt(ocr) + text = pytesseract.image_to_string(image=image, + lang='kor+eng', + config='--psm 6 -c preserve_interword_spaces=1') + return text.strip() \ No newline at end of file diff --git a/app/main.py b/app/main.py index 4ae1094..fb5ba1d 100644 --- a/app/main.py +++ b/app/main.py @@ -3,4 +3,4 @@ from app.api import ocr app = FastAPI() -app.include_router(ocr.init, prefix='/ocr', tags='OCR') \ No newline at end of file +app.include_router(ocr.router, prefix='/ocr', tags='OCR') \ No newline at end of file diff --git a/kakaobank20250701105811.png b/kakaobank20250701105811.png new file mode 100644 index 0000000..a4f2782 Binary files /dev/null and b/kakaobank20250701105811.png differ