ocr api
This commit is contained in:
@@ -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 = APIRouter()
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/")
|
||||||
def init():
|
async def process_ocr(file: UploadFile = File(...)) -> str:
|
||||||
return
|
#받아온 파일 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()
|
||||||
@@ -3,4 +3,4 @@ from app.api import ocr
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.include_router(ocr.init, prefix='/ocr', tags='OCR')
|
app.include_router(ocr.router, prefix='/ocr', tags='OCR')
|
||||||
BIN
kakaobank20250701105811.png
Normal file
BIN
kakaobank20250701105811.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
Reference in New Issue
Block a user