Я хочу отправить и получить изображение из cv2.Videocapture с помощью WebSocket.
Он может получить JSON, но не может быть декодирован.
Нам нужен результат, который можно открыть с помощью cv2.imshow ().
Кто-нибудь, помогите мне ...
Это клиент
ret, image_np = cap.read()
IMAGE_SHAPE = image_np.shape
encoded_image = base64.b64encode(image_np)
print(type(encoded_image))
payload = {
'from': 'rasp',
'image': str(encoded_image),
'shape': IMAGE_SHAPE,
}
data = json.dumps(payload)
try:
# Send encoded image data.
await websocket.send(data)
# receive server message
received_data = await websocket.recv()
print('< {}'.format(received_data))
# image = base64.b64decode(received_data)
# np_image = np.fromstring(image, dtype=np.uint8)
# source = np_image.reshape(IMAGE_SHAPE)
return websocket
except Exception:
print('WebSocket send or receive error.')
exit(1)
Это сервер
async def server_on(websocket, path):
payload = {
'from': 'image-server',
# 'result': {
# # Default is null.
# 'isPerson': <bool>,
# 'centerPoint': <(x, y)>,
# },
}
data = json.dumps(payload)
try:
payload = await websocket.recv()
receive_data = json.loads(payload)
# At this line doesnt work...
decoded_image = base64.b64decode(receive_data['image'])
image_np = np.fromstring(decoded_image, dtype=np.uint8)
source = image_np.reshape(receive_data['shape'])
await websocket.send(data)
except Exception:
websocket.close()
return