Flask收发JSON传输树莓派视频帧时进程冻结问题求助
我正尝试从树莓派获取实时视频,经压缩后封装为JSON发送至Flask服务器,目前先测试未压缩的JSON传输场景,但遇到了问题。
客户端发送代码
headers = {'ContentType':'application/json'} frame = np.random.randint(256, size=res, dtype='uint8') paylaod_tx = json.dumps({'shape':res, 'frame':json.dumps(frame,cls=NumpyArrayEncoder)}) #each pixel will have a rgb color and the color will be stored into a matrix, each matrix will store a row request.post('http://192.168.207:500',json=payload,headers=headers)
服务器端代码
while True: t = time.time() if request.method == 'POST': print(t) data1=request.get_json(force=True) print(data1) payload_rx = json.loads(data1) frame1 = np.asarray( json.loads(payload_rx['frame']), dtype='uint8' ).reshape(payload_rx['shape']) cv.imshow('test', frame1) if cv.waitKey(20) & 0xFF == ord('d'): # stop the video is the key 'd' is pressed (you can change as per your choice) break return 'ok'
当前现象与错误
目前服务器能正常打印JSON数据和时间:
1658586054.8141189 {"shape": [5, 5, 3], "frame": "[[[244, 15, 11], [132, 52, 234], [69, 13, 220], [88, 109, 62], [25, 97, 22]], [[143,
164, 89], [139, 42, 23], [180, 159, 69], [17, 174, 246], [211, 144,
92]], [[71, 140, 61], [40, 234, 236], [75, 46, 97], [10, 214, 62],
[19, 85, 112]], [[3, 111, 164], [51, 147, 173], [15, 227, 245], [7,
252, 230], [2, 60, 128]], [[112, 87, 95], [191, 176, 155], [26, 81,
7], [72, 241, 11], [207, 72, 192]]]"}
我也成功重建了5×5像素的测试图像(避免网络过载),但问题在于首次发送JSON后,客户端和服务器进程均冻结。客户端在首次与第二次发送之间出现错误:
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in
"/home/alex/projectgit/ConvergeCast/venv/lib/python3.10/site-packages/cv2/qt/plugins"
疑问
- 尝试降级OpenCV版本是否可行?
- 此前服务器报308错误,添加
return 'ok'后已建立连接,但现在接收第二次JSON并打印后进程冻结,不确定是否与POST请求有关,若相关该如何解决?
内容的提问来源于stack exchange,提问作者Al3x4ndru11

