From a0728c8da4288f2bc3bfb3d1dd5141056bb3e2cb Mon Sep 17 00:00:00 2001 From: Ben Ronde Date: Sun, 30 Nov 2025 18:16:36 +0100 Subject: [PATCH] adjust subscribers --- package.xml | 1 + .../sam/__init__.py | 0 .../scene_graph_fusion_node.py | 45 ++++++++++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 scene_graph_room_classification/sam/__init__.py diff --git a/package.xml b/package.xml index ce57091..7cfb741 100644 --- a/package.xml +++ b/package.xml @@ -17,6 +17,7 @@ sensor_msgs cv_bridge python3-opencv + std_msgs scene_graph_interfaces diff --git a/scene_graph_room_classification/sam/__init__.py b/scene_graph_room_classification/sam/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scene_graph_room_classification/scene_graph_fusion/scene_graph_fusion_node.py b/scene_graph_room_classification/scene_graph_fusion/scene_graph_fusion_node.py index 1a62137..a52b228 100644 --- a/scene_graph_room_classification/scene_graph_fusion/scene_graph_fusion_node.py +++ b/scene_graph_room_classification/scene_graph_fusion/scene_graph_fusion_node.py @@ -20,6 +20,7 @@ import networkx as nx import numpy as np import math from scene_graph_interfaces.msg import Object3DBoundingBox, Object3DBoundingBoxList, ClassifiedRoom, RoomPolygonList +from scene_graph_interfaces.msg import ObjectPointCloud, ObjectPointCloudList, FunctionalObjectPointCloud, FunctionalObjectPointCloudList from visualization_msgs.msg import Marker, MarkerArray from geometry_msgs.msg import Point32, Point from scipy.spatial.transform import Rotation as R @@ -27,6 +28,7 @@ import pickle import time from shapely.geometry import Polygon import json +from sensor_msgs_py import point_cloud2 # ============================================================================ @@ -84,7 +86,7 @@ class ObjectNode: bounding_box (list): [min_corner, max_corner] as Point32 objects """ - def __init__(self, id, class_id, bounding_box) -> None: + def __init__(self, id, class_id, bounding_box) -> None: #TODO add point cloud self.id = id self.class_id = class_id self.bounding_box = bounding_box @@ -134,10 +136,17 @@ class GraphManagementNode(Node): # Initialize the parent Node class super().__init__('graph_management_node') - + # Create subscribers self.create_subscription(Object3DBoundingBoxList, '/scene_graph/bounding_boxes_3d', self.bounding_boxes_callback, 10) + + #TODO wo kommen die Infos her? + self.create_subscription(ObjectPointCloudList, '/scene_graph/objects', + self.objects_callback, 10) + + self.create_subscription(FunctionalObjectPointCloudList, '/scene_graph/functional_objects', + self.functional_objects_callback, 10) # FIXME: add later # self.create_subscription(RoomPolygonList, '/scene_graph/rooms', @@ -240,7 +249,15 @@ class GraphManagementNode(Node): self.get_logger().info('Graph Management Node initialized') - + def pointcloud2_to_xyz_array(cloud_msg): + # cloud_msg: sensor_msgs.msg.PointCloud2 TODO add intensity + points = [] + for p in point_cloud2.read_points(cloud_msg, field_names=('x', 'y', 'z'), skip_nans=True): + points.append([p[0], p[1], p[2]]) + if not points: + return np.empty((0, 3), dtype=np.float32) + return np.asarray(points, dtype=np.float32) + def main_loop_callback(self): """ Timer callback that runs at 2 Hz for periodic graph maintenance. @@ -434,6 +451,19 @@ class GraphManagementNode(Node): self.scene_graph.nodes[room[0]]['data'].class_id = msg.label.data break + def objects_callback(self, msg: ObjectPointCloudList): + #TODO complete function + for obj in msg.objects: + cloud = obj.point_cloud + label = obj.label + + def functional_objects_callback(self, msg: FunctionalObjectPointCloudList): + #TODO complete function + for fobj in msg.functional_objects: + cloud = fobj.point_cloud + f_label = fobj.functional_label + affordances = list(fobj.affordances) + def bounding_boxes_callback(self, msg): """ Callback for incoming 3D bounding boxes from object detection. @@ -465,21 +495,14 @@ class GraphManagementNode(Node): # Process each detected object for object in msg.bbox: - + size_x = abs(object.bounding_box[0].x - object.bounding_box[1].x) size_y = abs(object.bounding_box[0].y - object.bounding_box[1].y) size_z = abs(object.bounding_box[0].z - object.bounding_box[1].z) - # Limit in Metern (z.B. 3 Meter) - # Alles was an irgendeiner Seite länger ist, wird gelöscht. MAX_SIZE_LIMIT = 3 if size_x > MAX_SIZE_LIMIT or size_y > MAX_SIZE_LIMIT or size_z > MAX_SIZE_LIMIT: - # Optional: Warnung ausgeben, damit du siehst, was gefiltert wurde - # self.get_logger().warn(f"Riesiges Objekt ignoriert ({object.name.data}): {size_x:.2f}m x {size_y:.2f}m") - - # 'continue' springt sofort zum nächsten Objekt in der Liste - # und ignoriert den Code darunter für dieses eine Objekt. continue # Check if object already exists in graph (by overlap)