小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
[FishBotCamera]3.结合YOLO实现检测
-
@lingzhiying 可以忽略,直接测试看看能不能用。
-
此回复已被删除! -
-
小鱼,我想用自己训练的模型。将模型放入config文件夹,在程序中修改选取的模型名字,可以运行我自己的模型吗?有哪些要注意的?
-
@2826778595 可以的,没什么要注意的,注意版本即可
-
@小鱼 自己训练的yolo5模型确实可以。之前测试不知道用的是yolo8模型,发现不行,才有此一问。
-
@小鱼 大佬您好,我想订阅/yolo_result话题中的分类结果,
例如:header.detections.id中的值person,但是仔细研究发现您是把Detection2D接口信息嵌入到了Detection2DArray的detections[ ]中,我不知道该如何获取嵌入到detections[ ]的id的值,能否给些提示,或者更新一个案例。
我这是属于喂到嘴边不知道怎么下口去吃,尴尬。 -
@2826778595 这里有一个递归读取的方式,读取header.detections.id中的值person。
代码如下:
import rclpy
from rclpy.node import Node
from vision_msgs.msg import Detection2DArrayclass DetectionSubscriber(Node):
def init(self):
super().init('detection_subscriber')
self.subscription = self.create_subscription(
Detection2DArray, # 消息类型
'yolo_result', # 订阅的话题名称
self.listener_callback, # 回调函数
10 # 队列大小
)
self.subscription # prevent unused variable warningdef listener_callback(self, msg: Detection2DArray): self.get_logger().info('Received a Detection2DArray message') for detection in msg.detections: # 打印出每个检测到的对象的ID self.get_logger().info(f"Detected object ID: {detection.id}")
def main(args=None):
rclpy.init(args=args)
detection_subscriber = DetectionSubscriber()
rclpy.spin(detection_subscriber)
# 关闭和清理ROS 2节点
detection_subscriber.destroy_node()
rclpy.shutdown()if name == 'main':
main()
我个人觉得比较呆,期待有更好的方法。 -
import rclpy from rclpy.node import Node from vision_msgs.msg import Detection2DArray class DetectionSubscriber(Node): def __init__(self): super().__init__('detection_subscriber') self.subscription = self.create_subscription( Detection2DArray, # 消息类型 'yolo_result', # 订阅的话题名称 self.listener_callback, # 回调函数 10 # 队列大小 ) self.subscription # prevent unused variable warning def listener_callback(self, msg: Detection2DArray): self.get_logger().info('Received a Detection2DArray message') for detection in msg.detections: # 打印出每个检测到的对象的ID self.get_logger().info(f"Detected object ID: {detection.id}") def main(args=None): rclpy.init(args=args) detection_subscriber = DetectionSubscriber() rclpy.spin(detection_subscriber) # 关闭和清理ROS 2节点 detection_subscriber.destroy_node() rclpy.shutdown() if __name__ == '__main__': main()
-
@2826778595 既然是数组,遍历读取就好,这个做法没啥问题
-
@小鱼 好嘞,谢谢。
-
新问题:
1、pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple yolov5 我把这行换成yolo8,代码里导入的包也是yolo8,可以运行yolo8的模型吗?
2、同时安装yolo5和8在Linux会产生冲突吗?
担心冲突,所以先问问。 -
小鱼,我在这一节里启动yolov5的时候提示警告不匹配版本该怎么解决呀,这个不匹配了在rqt里也看不到图像 -
@2431039560 我也遇到这个问题 请问你是如何解决的呢
-
@1004461581 摄像头和小车和电脑在同一个子网下就可以了,改一下IP最后面的那个数字
-
@2431039560是udpserver_ip吗,改了这个还是不行哎
-
@1004461581 发一下网络结构看看
-
@小鱼 感谢已经解决
-
-
sudo apt update
sudo apt install python3-pip ros-$ROS_DISTRO-vision-msgs
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple yolov5
为什么运行上面指令之后,我所有曾经成功编译过的代码现在colcon build 之后都会出错了,以前面FishBotCamera为例,我可以成功运行了,但是按照 “3.结合YOLO实现检测”内容操作之后,再运行前面的FishBotCamera,就会出现colcon build 错误,错误指示如下:
tarting >>> fishbot_camera
/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
--- stderr: fishbot_camera
/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
Traceback (most recent call last):
File "/home/hance/fishbot_ws/src/fishbot_camera/setup.py", line 5, in <module>
setup(
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/init.py", line 117, in setup
return distutils.core.setup(**attrs)
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 183, in setup
return run_commands(dist)
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 199, in run_commands
dist.run_commands()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 954, in run_commands
self.run_command(cmd)
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/dist.py", line 999, in run_command
super().run_command(command)
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 973, in run_command
cmd_obj.run()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 312, in run
self.find_sources()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 320, in find_sources
mm.run()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/command/egg_info.py", line 546, in run
self.prune_file_list()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/command/sdist.py", line 162, in prune_file_list
super().prune_file_list()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py", line 380, in prune_file_list
base_dir = self.distribution.get_fullname()
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_core_metadata.py", line 267, in get_fullname
return _distribution_fullname(self.get_name(), self.get_version())
File "/home/hance/.local/lib/python3.10/site-packages/setuptools/_core_metadata.py", line 285, in _distribution_fullname
canonicalize_version(version, strip_trailing_zero=False),
TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'Failed <<< fishbot_camera [4.58s, exited with code 1]
Summary: 0 packages finished [5.19s]
1 package failed: fishbot_camera
1 package had stderr output: fishbot_camera