refactor: refactored video_sender to send image as width, height and raw image bytes]
ref: N25B-393
This commit is contained in:
@@ -23,7 +23,7 @@ class VideoSender(SocketBase):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, zmq_context, port=settings.agent_settings.video_sender_port):
|
def __init__(self, zmq_context, port=settings.agent_settings.video_sender_port):
|
||||||
super(VideoSender, self).__init__("video")
|
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):
|
def start_video_rcv(self):
|
||||||
"""
|
"""
|
||||||
@@ -69,24 +69,20 @@ class VideoSender(SocketBase):
|
|||||||
break
|
break
|
||||||
|
|
||||||
height, width, channels = frame.shape
|
height, width, channels = frame.shape
|
||||||
print(width)
|
|
||||||
print(height)
|
|
||||||
pixel_data = frame.tobytes()
|
pixel_data = frame.tobytes()
|
||||||
|
|
||||||
width_bytes = struct.pack('<I', width)
|
width_bytes = struct.pack('<I', width)
|
||||||
height_bytes = struct.pack('<I', height)
|
height_bytes = struct.pack('<I', height)
|
||||||
|
|
||||||
#print("Sending frames")
|
self.socket.send_multipart([width_bytes, height_bytes, pixel_data])
|
||||||
#print(width_bytes)
|
|
||||||
#print(height_bytes)
|
|
||||||
#print(pixel_data)
|
|
||||||
self.socket.send_multipart([b"",width_bytes, height_bytes, pixel_data])
|
|
||||||
|
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
||||||
def video_rcv_loop(self, vid_service, vid_stream_name):
|
def video_rcv_loop(self, vid_service, vid_stream_name):
|
||||||
"""
|
"""
|
||||||
The main loop of retrieving video images from the robot.
|
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.
|
:param vid_service: The video service object that the active Qi session is connected to.
|
||||||
:type vid_service: Object (Qi service object)
|
:type vid_service: Object (Qi service object)
|
||||||
@@ -99,16 +95,14 @@ class VideoSender(SocketBase):
|
|||||||
try:
|
try:
|
||||||
img = vid_service.getImageRemote(vid_stream_name)
|
img = vid_service.getImageRemote(vid_stream_name)
|
||||||
if img is not None:
|
if img is not None:
|
||||||
raw_data = img[6]
|
image_bytes = img[6]
|
||||||
width = img[0]
|
width = img[0]
|
||||||
height = img[1]
|
height = img[1]
|
||||||
|
|
||||||
frame = np.frombuffer(raw_data, dtype=np.uint8).reshape((height, width, 3))
|
width_bytes = struct.pack('<I', width)
|
||||||
ret, jpeg_data = cv2.imencode('.jpg', frame)
|
height_bytes = struct.pack('<I', height)
|
||||||
if ret:
|
|
||||||
jpeg_bytes = jpeg_data.tobytes()
|
self.socket.send_multipart([width_bytes, height_bytes, image_bytes])
|
||||||
|
|
||||||
self.socket.send(jpeg_bytes)
|
|
||||||
except:
|
except:
|
||||||
logging.warn("Failed to retrieve video image from robot.")
|
logging.warn("Failed to retrieve video image from robot.")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
Reference in New Issue
Block a user