参考:
源码
安装YOLO_V5环境以及测试——NVIDIA Jetson Xavier AGX平台
0.ros-yolo5介绍
实现yolo作为service的server,发送sensor::Imge 图片,得到yolo检测的结果(置信度,2dbbox左上右下点坐标,附加文本信息,分类结果), 使用步骤如下:
版本:torch==1.10.0 大于该版本yolo会报错
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
1.下载源码
cd catkin_ws/src
git clone https://github.com/OuyangJunyuan/ros-yolov5.git
git clone https://github.com/catkin/catkin_simple.git
然后回到工作空间目录下
catkin_make
2.修改config.yaml文件
- 文件位置:ros-yolov5-master/config/config.yaml
修改如下:
yolov5:
action: False #是否使用action
path: /home/agx/YOLOV5/yolov5 #yolo模型位置
# weight: /home/ou/workspace/ros_ws/dev_ws/src/ros_yolo/model/best.pt
weight: /home/agx/YOLOV5/yolov5/weights/yolov5s.pt #yolo 模型的weight位置
device: gpu
img_size: 640
3.使用虚拟环境下的python
- 修改src/demo_service_server.py中首行 #!xxxxxx替换为你的虚拟环境下的python路径。
修改如下:
#!/home/agx/mambaforge/envs/py36/bin/python3.6
# /home/ou/software/anaconda3/envs/dl/bin/python
import rospy
from yolo_bridge.yolo_bridge import Ros2Yolo
if __name__ == "__main__":
yoloBridge = Ros2Yolo()
rospy.spin()
4.进入yolov5虚拟环境
conda activate yolov5
5.运行服务端
source devel/setup.bash
roslaunch ros_yolo service_demo.launch
终端输出:
Fusing layers…
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients
labels:
[0:‘person’, 1:‘bicycle’, 2:‘car’, 3:‘motorcycle’, 4:‘airplane’,
5:‘bus’, 6:‘train’, 7:‘truck’, 8:‘boat’, 9:‘traffic light’,
10:‘fire hydrant’, 11:‘stop sign’, 12:‘parking meter’, 13:‘bench’, 14:‘bird’,
15:‘cat’, 16:‘dog’, 17:‘horse’, 18:‘sheep’, 19:‘cow’,
20:‘elephant’, 21:‘bear’, 22:‘zebra’, 23:‘giraffe’, 24:‘backpack’,
25:‘umbrella’, 26:‘handbag’, 27:‘tie’, 28:‘suitcase’, 29:‘frisbee’,
30:‘skis’, 31:‘snowboard’, 32:‘sports ball’, 33:‘kite’, 34:‘baseball bat’,
35:‘baseball glove’, 36:‘skateboard’, 37:‘surfboard’, 38:‘tennis racket’, 39:‘bottle’,
40:‘wine glass’, 41:‘cup’, 42:‘fork’, 43:‘knife’, 44:‘spoon’,
45:‘bowl’, 46:‘banana’, 47:‘apple’, 48:‘sandwich’, 49:‘orange’,
50:‘broccoli’, 51:‘carrot’, 52:‘hot dog’, 53:‘pizza’, 54:‘donut’,
55:‘cake’, 56:‘chair’, 57:‘couch’, 58:‘potted plant’, 59:‘bed’,
60:‘dining table’, 61:‘toilet’, 62:‘tv’, 63:‘laptop’, 64:‘mouse’,
65:‘remote’, 66:‘keyboard’, 67:‘cell phone’, 68:‘microwave’, 69:‘oven’,
70:‘toaster’, 71:‘sink’, 72:‘refrigerator’, 73:‘book’, 74:‘clock’,
75:‘vase’, 76:‘scissors’, 77:‘teddy bear’, 78:‘hair drier’, 79:‘toothbrush’]
service mode : yolo_service
6.运行服务端
rosrun ros_yolo service_client_demo
查看节点与话题:
ROS教程1 消息查看和使用服务
rosservice list
显示
/client_node/get_loggers
/client_node/set_logger_level
/demo_server/get_loggers
/demo_server/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level
/rostopic_21344_1651755517549/get_loggers
/rostopic_21344_1651755517549/set_logger_level
/rqt_gui_py_node_32263/get_loggers
/rqt_gui_py_node_32263/set_logger_level
/yolo_service
- 服务消息的使用
7.ROS Action 使用
填写config/config.demo中参数 action=True
action-client 参考src/action_client_demo.cpp
action_client发出的goal只需包含iamge即goal.image = //sensor_msgs::Image
action_client接受到的结果result包含原始图像msg和检测结果即result->image 和 result->result
rosrun ros_yolo action_client_demo
8.修改硬件的视频流
- 原始读取的是本地视频文件;
- 调用内置USB摄像头,所以参数为0,如果有其他的摄像头可以调整参数为1,2;
- 修改对应的客户端代码,使得读取实际的硬件视频流,如USB摄像头、rtsp摄像头;
//①先实例化再初始化:
VideoCapture capture;
capture.open(0);//0,笔记本是内置摄像头
//②实例化的同时进行初始化
VideoCapture capture(0);
近期评论