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