@@ -50,6 +50,39 @@ def pose_mat_to_ros(rot: np.ndarray, trans: np.ndarray):
5050 return msg
5151
5252
53+ class DebugPublishers :
54+ def __init__ (self , camera_name : str , node : Node ):
55+ # Debug parameters.
56+ qos_profile = QoSProfile (
57+ depth = 10 , # Queue size (adjust as needed)
58+ durability = DurabilityPolicy .TRANSIENT_LOCAL ,
59+ reliability = ReliabilityPolicy .RELIABLE , # or RELIABLE, depending on your needs
60+ )
61+ self .rgb_pub = node .create_publisher (
62+ Image , f"/debug/tester/{ camera_name } /rgb" , qos_profile
63+ )
64+ self .depth_pub = node .create_publisher (
65+ Image , f"/debug/tester/{ camera_name } /depth" , qos_profile
66+ )
67+ self .aolp_pub = None
68+ self .dolp_pub = None
69+ if camera_name != "photoneo" :
70+ self .aolp_pub = node .create_publisher (
71+ Image , f"/debug/tester/{ camera_name } /aolp" , qos_profile
72+ )
73+ self .dolp_pub = node .create_publisher (
74+ Image , f"/debug/tester/{ camera_name } /dolp" , qos_profile
75+ )
76+
77+ def publish (self , rgb : Image , depth : Image , aolp : Image = None , dolp : Image = None ):
78+ self .rgb_pub .publish (rgb )
79+ self .depth_pub .publish (depth )
80+ if aolp is not None and self .aolp_pub is not None :
81+ self .aolp_pub .publish (aolp )
82+ if dolp is not None and self .dolp_pub is not None :
83+ self .dolp_pub .publish (dolp )
84+
85+
5386class BOPCamera :
5487 def __init__ (self , path , camera_name , img_id ):
5588 self ._load_images (path , camera_name , img_id )
@@ -70,27 +103,31 @@ def _load_images(self, path, camera_name, img_id):
70103 self .dolp = None
71104 self .br = CvBridge ()
72105
73- def to_camera_msg (self , node , debug_pub ) -> CameraMsg :
106+ def to_camera_msg (self , node , debug_pubs : DebugPublishers ) -> CameraMsg :
74107 msg = CameraMsg ()
75108 msg .info .header .frame_id = self .camera_name
76109 # msg.info.header.stamp = node.get_clock().now()
77110 msg .info .k = self .K .reshape (- 1 )
78111 msg .pose = pose_mat_to_ros (self .R , self .t )
79112 msg .rgb = self .br .cv2_to_imgmsg (self .rgb , "8UC1" )
80- debug_pub .publish (msg .rgb )
81113 msg .depth = self .br .cv2_to_imgmsg (self .depth , "32FC1" )
82114 msg .aolp = self .br .cv2_to_imgmsg (self .aolp , "8UC1" )
83115 msg .dolp = self .br .cv2_to_imgmsg (self .dolp , "8UC1" )
116+ if debug_pubs is not None :
117+ debug_pubs .publish (msg .rgb , msg .depth , msg .aolp , msg .dolp )
84118 return msg
85119
86- def to_photoneo_msg (self , node , debug_pub ) -> PhotoneoMsg :
120+ def to_photoneo_msg (self , node , debug_pubs : DebugPublishers ) -> PhotoneoMsg :
87121 msg = PhotoneoMsg ()
88122 msg .info .header .frame_id = self .camera_name
89123 # msg.info.header.stamp = node.get_clock().now()
90124 msg .info .k = self .K .reshape (- 1 )
91125 msg .pose = pose_mat_to_ros (self .R , self .t )
92126 msg .rgb = self .br .cv2_to_imgmsg (self .rgb , "8UC1" )
93127 msg .depth = self .br .cv2_to_imgmsg (self .depth , "32FC1" )
128+ if debug_pubs is not None :
129+ debug_pubs .publish (msg .rgb , msg .depth )
130+ return msg
94131
95132 def _load_camera_params (self , path , camera_name , img_id ):
96133 self .camera_params = load_scene_camera (
@@ -114,13 +151,18 @@ def main(argv=sys.argv):
114151 dataset_name = node .get_parameter ("dataset_name" ).get_parameter_value ().string_value
115152 node .get_logger ().info ("Loading from dataset {dataset_name}." )
116153
117- # Debug parameters.
118- qos_profile = QoSProfile (
119- depth = 10 , # Queue size (adjust as needed)
120- durability = DurabilityPolicy .TRANSIENT_LOCAL ,
121- reliability = ReliabilityPolicy .RELIABLE , # or RELIABLE, depending on your needs
154+ debug_cam_1 = None
155+ debug_cam_2 = None
156+ debug_cam_3 = None
157+ debug_photoneo = None
158+ debug : bool = (
159+ node .declare_parameter ("debug" , False ).get_parameter_value ().bool_value
122160 )
123- debug_pub = node .create_publisher (Image , "/ibpc_tester_debug_images" , qos_profile )
161+ if debug :
162+ debug_cam_1 = DebugPublishers ("cam1" , node )
163+ debug_cam_2 = DebugPublishers ("cam2" , node )
164+ debug_cam_3 = DebugPublishers ("cam3" , node )
165+ debug_photoneo = DebugPublishers ("photoneo" , node )
124166
125167 # Load the test split.
126168 test_split = get_split_params (datasets_path , dataset_name , "test" )
@@ -144,15 +186,17 @@ def main(argv=sys.argv):
144186 for img_id , obj_gts in scene_gt .items ():
145187 request = GetPoseEstimates .Request ()
146188 request .cameras .append (
147- BOPCamera (scene_dir , "cam1" , img_id ).to_camera_msg (node , debug_pub )
189+ BOPCamera (scene_dir , "cam1" , img_id ).to_camera_msg (node , debug_cam_1 )
148190 )
149191 request .cameras .append (
150- BOPCamera (scene_dir , "cam2" , img_id ).to_camera_msg (node , debug_pub )
192+ BOPCamera (scene_dir , "cam2" , img_id ).to_camera_msg (node , debug_cam_2 )
151193 )
152194 request .cameras .append (
153- BOPCamera (scene_dir , "cam3" , img_id ).to_camera_msg (node , debug_pub )
195+ BOPCamera (scene_dir , "cam3" , img_id ).to_camera_msg (node , debug_cam_3 )
196+ )
197+ request .photoneo = BOPCamera (scene_dir , "photoneo" , img_id ).to_photoneo_msg (
198+ node , debug_photoneo
154199 )
155- # request.photoneo = BOPCamera(scene_dir, 'photoneo', img_id).to_photoneo_msg(node)
156200 # todo(Yadunund): Load corresponding rgb, depth and polarized image for this img_id.
157201 for obj_gt in obj_gts :
158202 request .object_ids .append (int (obj_gt ["obj_id" ]))
0 commit comments