小编Moh*_*bli的帖子

将opencv图像以及其他数据发送到Flask Server

我目前可以使用以下代码将OpenCV图像帧发送到我的Flask服务器

def sendtoserver(frame):
    imencoded = cv2.imencode(".jpg", frame)[1]
    headers = {"Content-type": "text/plain"}
    try:
        conn.request("POST", "/", imencoded.tostring(), headers)
        response = conn.getresponse()
    except conn.timeout as e:
        print("timeout")


    return response
Run Code Online (Sandbox Code Playgroud)

但是我想发送一个unique_id以及我尝试使用JSON组合框架和ID的框架,但是遇到以下错误TypeError: Object of type 'bytes' is not JSON serializable,任何人都不知道我如何将一些其他数据与框架一起发送到服务器。

更新:

json格式代码

def sendtoserver(frame):
    imencoded = cv2.imencode(".jpg", frame)[1]
    data = {"uid" : "23", "frame" : imencoded.tostring()}
    headers = {"Content-type": "application/json"}
    try:
        conn.request("POST", "/", json.dumps(data), headers)
        response = conn.getresponse()
    except conn.timeout as e:
        print("timeout")


    return response
Run Code Online (Sandbox Code Playgroud)

python opencv flask

0
推荐指数
1
解决办法
1303
查看次数

标签 统计

flask ×1

opencv ×1

python ×1