usb_cam的ROS2甜点

举报
zhangrelay 发表于 2021/09/11 00:11:16 2021/09/11
【摘要】 最近收到一些反馈,不多但是都非常有价值,感谢反馈的朋友们。关于ROS2的实践和应用类型课程已经开发完成,ROS1最终版Noetic也会出一版纪念版镜像配合教程,但博客更新主要集中于ROS2的相关应用。 usb_cam这是非常典型有价值的摄像头包。主要有两个: ros2_usb_camera-foxy-develusb_cam-ros...

最近收到一些反馈,不多但是都非常有价值,感谢反馈的朋友们。关于ROS2的实践和应用类型课程已经开发完成,ROS1最终版Noetic也会出一版纪念版镜像配合教程,但博客更新主要集中于ROS2的相关应用。

usb_cam这是非常典型有价值的摄像头包。主要有两个:

  • ros2_usb_camera-foxy-devel
  • usb_cam-ros2

代码差异还是有不少的。

推荐使用usb_cam。

  •  ros2 launch usb_cam demo_launch.py 

效果如下:

这个是640*480

如果需要1280*720,需要修改如下:

usb_cam_node.cpp


  
  1. // declare params
  2. this->declare_parameter("camera_name", "default_cam");
  3. this->declare_parameter("camera_info_url", "");
  4. this->declare_parameter("framerate", 10.0);
  5. this->declare_parameter("frame_id", "default_cam");
  6. this->declare_parameter("image_height", 720);
  7. this->declare_parameter("image_width", 1280);
  8. this->declare_parameter("io_method", "mmap");
  9. this->declare_parameter("pixel_format", "yuyv");
  10. this->declare_parameter("video_device", "/dev/video0");

这样就可以吗?应该是不行的,还需要的操作如下:

先看下启动文件launch


  
  1. # Copyright 2018 Lucas Walter
  2. # All rights reserved.
  3. #
  4. # Software License Agreement (BSD License 2.0)
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following
  14. # disclaimer in the documentation and/or other materials provided
  15. # with the distribution.
  16. # * Neither the name of Lucas Walter nor the names of its
  17. # contributors may be used to endorse or promote products derived
  18. # from this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. # POSSIBILITY OF SUCH DAMAGE.
  32. import argparse
  33. from launch import LaunchDescription
  34. from launch_ros.actions import Node
  35. import os
  36. import sys
  37. from ament_index_python.packages import get_package_share_directory
  38. def generate_launch_description():
  39. ld = LaunchDescription()
  40. parser = argparse.ArgumentParser(description='usb_cam demo')
  41. parser.add_argument('-n', '--node-name', dest='node_name', type=str,
  42. help='name for device', default='usb_cam')
  43. args, unknown = parser.parse_known_args(sys.argv[4:])
  44. usb_cam_dir = get_package_share_directory('usb_cam')
  45. # get path to params file
  46. params_path = os.path.join(
  47. usb_cam_dir,
  48. 'config',
  49. 'params.yaml'
  50. )
  51. node_name = args.node_name
  52. print(params_path)
  53. ld.add_action(Node(
  54. package='usb_cam', executable='usb_cam_node_exe', output='screen',
  55. name=node_name,
  56. # namespace=ns,
  57. parameters=[params_path]
  58. ))
  59. ld.add_action(Node(
  60. package='usb_cam', executable='show_image.py', output='screen',
  61. # namespace=ns,
  62. # arguments=[image_manip_dir + "/data/mosaic.jpg"])
  63. # remappings=[('image_in', 'image_raw')]
  64. ))
  65. return ld

注意到如下这一段:


  
  1. # get path to params file
  2. params_path = os.path.join(
  3. usb_cam_dir,
  4. 'config',
  5. 'params.yaml'
  6. )

需要修改啦:

camera_info.yaml


  
  1. image_width: 1280
  2. image_height: 720
  3. camera_name: test_camera
  4. camera_matrix:
  5. rows: 3
  6. cols: 3
  7. data: [438.783367, 0.000000, 305.593336, 0.000000, 437.302876, 243.738352, 0.000000, 0.000000, 1.000000]
  8. distortion_model: plumb_bob
  9. distortion_coefficients:
  10. rows: 1
  11. cols: 5
  12. data: [-0.361976, 0.110510, 0.001014, 0.000505, 0.000000]
  13. rectification_matrix:
  14. rows: 3
  15. cols: 3
  16. data: [0.999978, 0.002789, -0.006046, -0.002816, 0.999986, -0.004401, 0.006034, 0.004417, 0.999972]
  17. projection_matrix:
  18. rows: 3
  19. cols: 4
  20. data: [393.653800, 0.000000, 322.797939, 0.000000, 0.000000, 393.653800, 241.090902, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]

params.yaml


  
  1. /**:
  2. ros__parameters:
  3. video_device: "/dev/video0"
  4. framerate: 30.0
  5. io_method: "mmap"
  6. frame_id: "camera"
  7. pixel_format: "yuyv"
  8. image_width: 1280
  9. image_height: 720
  10. camera_name: "test_camera"
  11. camera_info_url: "package://usb_cam/config/camera_info.yaml"

参数合适吗?不管,效果还是有的:


然后,就可以愉快玩耍各种图形处理算法啦,欢乐不^_^


文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/120214789

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。