В настоящее время я могу отправлять рамки изображений OpenCV на свой Flask Server, используя следующий код
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
Но я хочу отправить unique_id вместе с фреймом. Я пытался объединить фрейм и идентификатор с помощью JSON, но получаю следующее сообщение об ошибке 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