refactor: refactored video_sender to send image as width, height and raw image bytes]

ref: N25B-393
This commit is contained in:
Storm
2026-01-29 11:57:48 +01:00
parent e157eafc91
commit f1cc55efec

View File

@@ -23,7 +23,7 @@ class VideoSender(SocketBase):
"""
def __init__(self, zmq_context, port=settings.agent_settings.video_sender_port):
super(VideoSender, self).__init__("video")
self.create_socket(zmq_context, zmq.PUB, port, [(zmq.CONFLATE,1)])
self.create_socket(zmq_context, zmq.PUB, port, [(zmq.SNDHWM,3)])
def start_video_rcv(self):
"""
@@ -69,24 +69,20 @@ class VideoSender(SocketBase):
break
height, width, channels = frame.shape
print(width)
print(height)
pixel_data = frame.tobytes()
width_bytes = struct.pack('<I', width)
height_bytes = struct.pack('<I', height)
#print("Sending frames")
#print(width_bytes)
#print(height_bytes)
#print(pixel_data)
self.socket.send_multipart([b"",width_bytes, height_bytes, pixel_data])
self.socket.send_multipart([width_bytes, height_bytes, pixel_data])
cap.release()
def video_rcv_loop(self, vid_service, vid_stream_name):
"""
The main loop of retrieving video images from the robot.
Sends the image data over the ZMQ socket in 3 parts: image width, image height and raw image bytes.
:param vid_service: The video service object that the active Qi session is connected to.
:type vid_service: Object (Qi service object)
@@ -99,16 +95,14 @@ class VideoSender(SocketBase):
try:
img = vid_service.getImageRemote(vid_stream_name)
if img is not None:
raw_data = img[6]
image_bytes = img[6]
width = img[0]
height = img[1]
frame = np.frombuffer(raw_data, dtype=np.uint8).reshape((height, width, 3))
ret, jpeg_data = cv2.imencode('.jpg', frame)
if ret:
jpeg_bytes = jpeg_data.tobytes()
width_bytes = struct.pack('<I', width)
height_bytes = struct.pack('<I', height)
self.socket.send(jpeg_bytes)
self.socket.send_multipart([width_bytes, height_bytes, image_bytes])
except:
logging.warn("Failed to retrieve video image from robot.")
except KeyboardInterrupt: