小编SUB*_*KHA的帖子

如何在fastAPI中返回图像

在使用 Opencv 比较两个图像后,我试图在 fastAPI 中返回一个图像。

这是我到目前为止所做的:

from fastapi import FastAPI , File, UploadFile
import numpy as np
from cv2 import *
import os
import base64


app = FastAPI(debug = True)


@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File(...),file1: UploadFile = File(...)):
    content = await file.read()
    nparr = np.fromstring(content, np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)

    content1 = await file1.read()
    nparr1 = np.fromstring(content1, np.uint8)
    img1 = cv2.imdecode(nparr1, cv2.IMREAD_COLOR)

    akaze = cv2.AKAZE_create()
    kpts1, desc1 = akaze.detectAndCompute(img, None)
    kpts2, desc2 = akaze.detectAndCompute(img1, None)
    matcher = cv2.DescriptorMatcher_create(cv2.DescriptorMatcher_BRUTEFORCE_HAMMING) …
Run Code Online (Sandbox Code Playgroud)

python api opencv opencv3.1 fastapi

2
推荐指数
1
解决办法
4833
查看次数

标签 统计

api ×1

fastapi ×1

opencv ×1

opencv3.1 ×1

python ×1