java websocket传json,使用WebSocket将图像作为字节发送JSON

本文档探讨了如何通过Java WebSocket发送和接收来自cv2.VideoCapture的图像,将其编码为JSON。问题在于从WebSocket接收到的图像无法解码以用于cv2.imshow()。解决方案包括正确地将图像编码为字节并将其作为JSON字符串发送。
摘要由CSDN通过智能技术生成

I want to send and receive image from cv2.Videocapture using WebSocket.

It could get json, but it couldn't decoded.

We need result that can be opened using cv2.imshow().

Somebody help me...

This is Client

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)

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值