File size: 524 Bytes
08606b0
 
 
1cdc160
 
 
 
08606b0
 
 
1cdc160
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI

app = FastAPI()
from rapidocr_onnxruntime import RapidOCR

# det_model_path同理
model = RapidOCR()

@app.get("/")
def read_root():
    return {"Hello": "World!"}
	
@app.post("/ocr")	
async def ocr(file: UploadFile = File(...)):
    # 读取上传的文件内容
    contents = await file.read()
    # 使用Pillow打开图像
    image = Image.open(io.BytesIO(contents))
    # 将图像转换为numpy数组
    np_array = np.array(image)
    result, elapse = model(np_array)
    return result