ros2配合yolov8具体实现

效果图
ros2配合yolov8具体实现_第1张图片

  1. 用yolov8实时检测物体,包括物体的类别,置信度和坐标
  2. 通过ros2发布出去

自定义消息

int64 xmin
int64 ymin
int64 xmax
int64 ymax
float32 conf
string name

发布端代码

from ultralytics import YOLO
import cv2
import rclpy
from yolo_interfaces.msg import Msgyolo

def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('yolo_pub')
    pub = node.create_publisher(Msgyolo, 'msgyolo', 10)

    model = YOLO("/home/galactic/yolo_ws/src/yolo_detection/resource/yolov8m.pt") 

    while rclpy.ok():
        results = model.predict(source=0, show=True, stream=

你可能感兴趣的:(YOLO)