Welcome to ROSMASTER M3 repository
07.YOLOv11 Object Detection
YOLOv11 Object Detection
1. Course Content
- Run examples, use YOLOv11 quantized model for accelerated object detection
2. Launch Case
For Raspberry Pi 5 users, if the ROS container is not started, you need to start the container first,
bringup_m3Open a terminal inside the container,
xxxxxxxxxxexec_m3- Run command in terminal:
xxxxxxxxxxros2 launch m3_bringup depthcam_demo.launch.py demo:=yolov11_detectAfter the program runs, a YOLOV11-Detect Panel window opens, performing object detection through the YOLOv11 model, where FPS is the average frame rate per second, and Infer is the inference time for each frame image

- The YOLOv11 object detection model used here is a pre-trained model on the COCO8 dataset, recognizable objects are as follows:
xxxxxxxxxxnames 0person 1bicycle 2car 3motorcycle 4airplane 5bus 6train 7truck 8boat 9traffic light 10fire hydrant 11stop sign 12parking meter 13bench 14bird 15cat 16dog 17horse 18sheep 19cow 20elephant 21bear 22zebra 23giraffe 24backpack 25umbrella 26handbag 27tie 28suitcase 29frisbee 30skis 31snowboard 32sports ball 33kite 34baseball bat 35baseball glove 36skateboard 37surfboard 38tennis racket 39bottle 40wine glass 41cup 42fork 43knife 44spoon 45bowl 46banana 47apple 48sandwich 49orange 50broccoli 51carrot 52hot dog 53pizza 54donut 55cake 56chair 57couch 58potted plant 59bed 60dining table 61toilet 62tv 63laptop 64mouse 65remote 66keyboard 67cell phone 68microwave 69oven 70toaster 71sink 72refrigerator 73book 74clock 75vase 76scissors 77teddy bear 78hair drier 79toothbrush
- To get the highest frame rate and inference speed, the YOLOv11 model used in this case has been optimized for different platforms (OrinNano, OrinNX, Raspberry Pi, RDKx5) in model format, model paths are as follows:
xxxxxxxxxx~/MODELS/yolov11/
3. Core Code Analysis
Source code paths are as follows:
xxxxxxxxxx~/yahboomM3_ws/code_ws/src/m3_common_demo/m3_common_demo/yolov11/yolov11_detect.pyxxxxxxxxxx~/yahboomM3_ws/code_ws/src/m3_common_demo/m3_common_demo/yolov11/yolov11_infer.py
- Class in yolov11_infer.py: YOLO_Detect is a core functionality program that encapsulates model loading and inference
xclass YOLO_Detect(YOLO_MODEL): """YOLOv11 object detection""" def __init__(self,model_path:str): self.model_path=model_path def init_yolo_engine(self): "Initialization of model" try: self.yolo_model = YOLO( self.model_path,task="detect") except: return False return True def get_infer_result(self,source,stream:bool=True): '''Obtain the reasoning result of a single frame image''' result = self.yolo_model.predict(source, stream=stream, half=True, max_det=3, verbose=False) return result- The get_RGBImageCallBack callback function in yolov11_detect.py program is the core program for displaying detection frames, with the following functions:
- Subscribe to camera topic
- Use yolo_model.get_infer_result function method to perform inference on single frame images of camera feed and draw on the frame
- Use cv2.imshow function to display image frame rate and inference time
xxxxxxxxxx def get_RGBImageCallBack(self,rgb_msg): rgb_image = self.rgb_bridge.imgmsg_to_cv2(rgb_msg, desired_encoding='bgr8') infer_start = time.time() results= self.yolo_model.get_infer_result(rgb_image,True) for res in results: if res.boxes is not None: annotated_frame = res.plot() infer_end = time.time() self.frame_count += 1 curr_time = time.time() time_diff = curr_time - self.prev_time if time_diff >= 1.0: self.fps = self.frame_count / time_diff self.frame_count = 0 self.prev_time = curr_time cv2.putText(annotated_frame,f"FPS: {self.fps:.2f}",(10, 25),cv2.FONT_HERSHEY_SIMPLEX,0.6,(0, 255, 0),1,) infer_time = (infer_end - infer_start) * 1000 cv2.putText(annotated_frame, f"Infer: {infer_time:.1f} ms", (10, 45),cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 255), 1) cv2.imshow("YOLOV11-Detect Panel", annotated_frame) cv2.waitKey(1)