小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
[FishBotCamera]3.结合YOLO实现检测
-
@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 -
-
@小鱼 对的小鱼,应该问题出在了setuptools上,这个需要怎么解决呀?
-
@pengzhju 搜搜默认版本和怎么回退,我帮你看下我的
fishros$ pip list| grep setuptools --- setuptools 59.6.0
-
@小鱼 我的是Ubuntu22.04 humble,是按照图片这个步骤来的,可能我哪里出错了。好的小鱼,我先试一下,谢谢呀