1
+ #!/usr/bin/env python3
2
+
1
3
import rclpy
2
4
from rclpy .node import Node
3
- from sensor_msgs import Image
4
- from std_msgs import Int32
5
- from nav_msgs import Odometry
6
- from zed_msgs import Object
5
+ from sensor_msgs . msg import Image
6
+ from std_msgs . msg import Int32
7
+ from nav_msgs . msg import Odometry
8
+ # from zed_msgs import Object
7
9
import pyzed .sl as sl
8
10
from ultralytics import YOLO
9
11
import cv2
@@ -24,7 +26,7 @@ def __init__(self):
24
26
self .initialize_camera ()
25
27
self .raw_image = sl .Mat ()
26
28
self .objects = sl .Objects ()
27
- self .model = YOLO ("model " )
29
+ self .model = YOLO ("src/buggy/scripts/vision/01-15-25_no_pushbar_yolov11n.pt " )
28
30
29
31
self .runtime_params = sl .RuntimeParameters ()
30
32
self .object_det_params = sl .ObjectDetectionRuntimeParameters ()
@@ -169,15 +171,16 @@ def loop(self):
169
171
image_net = self .raw_image .get_data ()
170
172
171
173
# publish raw frame
172
- self . raw_image = cv2 .cvtColor (image_net , cv2 .COLOR_RGBA2RGB )
173
- raw_frame_publish = self .bridge .cv2_to_imgmsg (image_net , encoding = "rgb8" )
174
+ raw_image_np = cv2 .cvtColor (image_net , cv2 .COLOR_RGBA2RGB )
175
+ # raw_frame_publish = self.bridge.cv2_to_imgmsg(raw_image_np , encoding="rgb8")
174
176
175
177
# pass frame into YOLO model (get 2D)
176
- detections = self .model .predict (self .raw_image , save = False )
177
- custom_boxes = self .detections_to_custom_box (detections , image_net )
178
+ detections = self .model .predict (raw_image_np , save = False )
179
+ detection_boxes = detections [0 ].cpu ().numpy ().boxes # what is the [0] indexing into, does this pull out the first detection
180
+ custom_boxes = self .detections_to_custom_box (detection_boxes , image_net )
178
181
179
182
# publish annotated frame
180
- annotated_frame_publish = detections [0 ].plot ()
183
+ # annotated_frame_publish = self.bridge.cv2_to_imgmsg( detections[0].plot(), encoding="rgb8" )
181
184
182
185
# pass into 2D to 3D to get approximate depth
183
186
self .cam .ingest_custom_box_objects (custom_boxes )
@@ -188,19 +191,21 @@ def loop(self):
188
191
self .objects .object_list .sort (key = lambda obj : obj .confidence , reverse = True )
189
192
190
193
num_detections = len (self .objects .object_list )
194
+ NAND_pose = None
191
195
if num_detections > 0 :
192
196
utms = self .objects_to_utm ()
193
197
# NOTE: we're currently defining NAND to just be the first bounding box, we might change how we figure out what NAND is if there are multiple detections
194
- NAND_utm = utms [0 ]
195
198
NAND_pose = Odometry ()
199
+ NAND_utm = utms [0 ]
196
200
NAND_pose .pose .pose .position .x = NAND_utm [0 ]
197
201
NAND_pose .pose .pose .position .y = NAND_utm [1 ]
198
202
NAND_pose .pose .pose .position .z = NAND_utm [2 ]
199
203
200
- self .raw_camera_frame_publisher .publish (raw_frame_publish )
201
- self .annotated_camera_frame_publisher .publish (annotated_frame_publish )
202
- self .num_detections_publisher .publish (num_detections )
203
- self .observed_NAND_odom_publisher .publish (NAND_pose )
204
+ # self.raw_camera_frame_publisher.publish(raw_frame_publish)
205
+ # self.annotated_camera_frame_publisher.publish(annotated_frame_publish)
206
+ self .num_detections_publisher .publish (Int32 (data = num_detections ))
207
+ if (NAND_pose is not None ):
208
+ self .observed_NAND_odom_publisher .publish (NAND_pose )
204
209
205
210
206
211
def main (args = None ):
0 commit comments