|
1 | 1 | from cv_bridge import CvBridge |
2 | 2 | from sensor_msgs.msg import Image, PointCloud2 |
| 3 | +from visualization_msgs.msg import MarkerArray |
3 | 4 | from ultralytics import YOLO |
4 | 5 | from fusion_utils import * |
5 | 6 | import rospy |
@@ -38,7 +39,7 @@ def __init__(self): |
38 | 39 | # Publishers |
39 | 40 | self.pub_pedestrians_pc2 = rospy.Publisher("/point_cloud/pedestrians", PointCloud2, queue_size=10) |
40 | 41 | self.pub_centroids_pc2 = rospy.Publisher("/point_cloud/centroids", PointCloud2, queue_size=10) |
41 | | - self.pub_bbox_corners_pc2 = rospy.Publisher("/point_cloud/bbox_corners", PointCloud2, queue_size=10) |
| 42 | + self.pub_bboxes_markers = rospy.Publisher("/markers/bboxes", MarkerArray, queue_size=10) |
42 | 43 | if(self.visualization): |
43 | 44 | self.pub_image = rospy.Publisher("/camera/image_detection", Image, queue_size=1) |
44 | 45 |
|
@@ -67,7 +68,6 @@ def fusion_callback(self, rgb_image_msg: Image, lidar_pc2_msg: PointCloud2): |
67 | 68 | # Unpacking box dimentions detected into x,y,w,h |
68 | 69 | pedestrians_3d_centroids = [] |
69 | 70 | pedestrians_3d_dims = [] |
70 | | - pedestrians_3d_bbox_corners = [] |
71 | 71 | flattened_pedestrians_2d_pts = [] |
72 | 72 | flattened_pedestrians_3d_pts = [] |
73 | 73 |
|
@@ -114,39 +114,36 @@ def fusion_callback(self, rgb_image_msg: Image, lidar_pc2_msg: PointCloud2): |
114 | 114 | dims = calculate_dimensions(extracted_3d_pts) |
115 | 115 | if dims != None: |
116 | 116 | pedestrians_3d_dims.append(dims) |
117 | | - |
118 | | - # Calculate bbox corners for visualization |
119 | | - corners = calculate_bbox_corners_3d(centroid, dims) |
120 | | - if corners != None: |
121 | | - pedestrians_3d_bbox_corners = pedestrians_3d_bbox_corners + corners |
122 | 117 |
|
123 | 118 | # Used for visualization |
124 | 119 | if(self.visualization): |
125 | 120 | cv_image = vis_2d_bbox(cv_image, xywh, box) |
126 | | - |
127 | | - if len(flattened_pedestrians_3d_pts) > 0: |
128 | | - # Draw projected 2D LiDAR points on the image. |
129 | | - for pt in flattened_pedestrians_2d_pts: |
130 | | - cv2.circle(cv_image, pt, 2, (0, 0, 255), -1) |
131 | | - |
132 | | - # Create point cloud from extracted 3D points |
133 | | - ros_extracted_pedestrian_pc2 = create_point_cloud(flattened_pedestrians_3d_pts) |
134 | | - self.pub_pedestrians_pc2.publish(ros_extracted_pedestrian_pc2) |
135 | | - |
136 | | - if len(pedestrians_3d_centroids) > 0: |
137 | | - # Create point cloud from pedestrain centroid |
138 | | - ros_pedestrians_centroids_pc2 = create_point_cloud(pedestrians_3d_centroids, color=(255, 0, 255)) |
139 | | - self.pub_centroids_pc2.publish(ros_pedestrians_centroids_pc2) |
140 | | - |
141 | | - if len(pedestrians_3d_bbox_corners) > 0: |
142 | | - # Create point cloud from pedestrain centroid |
143 | | - ros_pedestrians_bbox_corners_pc2 = create_point_cloud(pedestrians_3d_bbox_corners, color=(0, 0, 255)) |
144 | | - self.pub_bbox_corners_pc2.publish(ros_pedestrians_bbox_corners_pc2) |
145 | 121 |
|
146 | 122 | # Used for visualization |
147 | 123 | if(self.visualization): |
| 124 | + if len(flattened_pedestrians_3d_pts) > 0: |
| 125 | + # Draw projected 2D LiDAR points on the image. |
| 126 | + for pt in flattened_pedestrians_2d_pts: |
| 127 | + cv2.circle(cv_image, pt, 2, (0, 0, 255), -1) |
| 128 | + |
| 129 | + # Create point cloud from extracted 3D points |
| 130 | + ros_extracted_pedestrian_pc2 = create_point_cloud(flattened_pedestrians_3d_pts) |
| 131 | + self.pub_pedestrians_pc2.publish(ros_extracted_pedestrian_pc2) |
| 132 | + |
| 133 | + if len(pedestrians_3d_centroids) > 0 and len(pedestrians_3d_dims) > 0: |
| 134 | + # Create point cloud from pedestrain centroid |
| 135 | + ros_pedestrians_centroids_pc2 = create_point_cloud(pedestrians_3d_centroids, color=(255, 0, 255)) |
| 136 | + self.pub_centroids_pc2.publish(ros_pedestrians_centroids_pc2) |
| 137 | + |
| 138 | + # Create bbox marker from pedestrain dimensions |
| 139 | + ros_delete_bboxes_markers = delete_bbox_marker() |
| 140 | + self.pub_bboxes_markers.publish(ros_delete_bboxes_markers) |
| 141 | + ros_pedestrians_bboxes_markers = create_bbox_marker(pedestrians_3d_centroids, pedestrians_3d_dims) |
| 142 | + self.pub_bboxes_markers.publish(ros_pedestrians_bboxes_markers) |
| 143 | + |
| 144 | + # Convert cv2 image to imgmsg |
148 | 145 | ros_img = self.bridge.cv2_to_imgmsg(cv_image, 'bgr8') |
149 | | - self.pub_image.publish(ros_img) |
| 146 | + self.pub_image.publish(ros_img) |
150 | 147 |
|
151 | 148 |
|
152 | 149 |
|
|
0 commit comments