From 99e7ae9708c500f0078d4d71cc088668b88a2fd4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 16 May 2024 07:59:35 +0000 Subject: [PATCH] make images stored separatedly --- tutorial_workspace/fogros2_tutorial/sam_client.py | 10 ++++++++-- tutorial_workspace/fogros2_tutorial/sam_server.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tutorial_workspace/fogros2_tutorial/sam_client.py b/tutorial_workspace/fogros2_tutorial/sam_client.py index 67160ca..0e44ffe 100644 --- a/tutorial_workspace/fogros2_tutorial/sam_client.py +++ b/tutorial_workspace/fogros2_tutorial/sam_client.py @@ -59,8 +59,9 @@ def handle_response(self, future, camera_type): # Save a copy of the image sent published image_stream = BytesIO(msg.data) image = Image.open(image_stream) - os.makedirs('saved_images', exist_ok=True) - image.save(f'saved_images/original_image_{self.counter}.png', format='PNG') + os.makedirs('base_images', exist_ok=True) + image.save(f'base_images/original_image.png', format='PNG') + image.save(f'base_images/original_image_{self.counter}.png', format='PNG') self.counter += 1 elif camera_type == 'top': @@ -68,6 +69,11 @@ def handle_response(self, future, camera_type): msg.format = 'png' msg.data = np.array(cv2.imencode('.png', cv_image)[1]).tobytes() self.publisher_top.publish(msg) + image_stream = BytesIO(msg.data) + image = Image.open(image_stream) + os.makedirs('top_images', exist_ok=True) + image.save(f'top_images/original_image.png', format='PNG') + image.save(f'top_images/original_image_{self.counter}.png', format='PNG') self.get_logger().info('Top camera image published.') else: self.get_logger().info(f'Failed to receive image from {camera_type} camera: ' + response.message) diff --git a/tutorial_workspace/fogros2_tutorial/sam_server.py b/tutorial_workspace/fogros2_tutorial/sam_server.py index d1eeddc..392fc25 100644 --- a/tutorial_workspace/fogros2_tutorial/sam_server.py +++ b/tutorial_workspace/fogros2_tutorial/sam_server.py @@ -38,7 +38,7 @@ def __init__(self): self.subscription = self.create_subscription( CompressedImage, - '/image/base', + '/image/top', self.listener_callback, 2)