ROS2之OpenCV人脸识别foxy~galactic~humble

举报
zhangrelay 发表于 2022/06/14 00:10:02 2022/06/14
1.8k+ 0 0
【摘要】 OpenCV工具使用非常广。关于在ROS2中如何使用的博客一直没有更新: 最早,2019年:ROS2使用OpenCV基础 最近更新了一些: ROS2之OpenCV基础代码对比foxy~galactic~humble 仿真中使用习题如下: ROS2+Gazebo11+Car+OpenCV巡线识别和速度转向控制学习 那么如何实现...

OpenCV工具使用非常广。关于在ROS2中如何使用的博客一直没有更新:

最早,2019年:ROS2使用OpenCV基础

最近更新了一些:


仿真中使用习题如下:


那么如何实现如下的人脸识别效果呢?

 

蒙娜丽莎的微笑,永远那么神秘…… 


遇到的问题如:


      [INFO] [1655036597.738995500] [face_detection]: Receiving image
      Traceback (most recent call last):
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/core.py", line 194, in imgmsg_to_cv2
          res = cvtColor2(im, img_msg.encoding, desired_encoding)
      RuntimeError: [8UC3] is not a color format. but [bgr8] is. The conversion does not make sense
      During handling of the above exception, another exception occurred:
      Traceback (most recent call last):
        File "/home/zhangrelay/ros_ws/opencv_ros2-main/opencv_ros2/face_detection.py", line 95, in <module>
          main()
        File "/home/zhangrelay/ros_ws/opencv_ros2-main/opencv_ros2/face_detection.py", line 84, in main
          rclpy.spin(face_detection)
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
          executor.spin_once()
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 712, in spin_once
          raise handler.exception()
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
          self._handler.send(None)
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 418, in handler
          await call_coroutine(entity, arg)
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 343, in _execute_subscription
          await await_or_execute(sub.callback, msg)
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
         return callback(*args)
        File "/home/zhangrelay/ros_ws/opencv_ros2-main/opencv_ros2/face_detection.py", line 53, in listener_callback
          current_frame = self.br.imgmsg_to_cv2(data, "bgr8")
        File "/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/core.py", line 196, in imgmsg_to_cv2
          raise CvBridgeError(e)
      cv_bridge.core.CvBridgeError: [8UC3] is not a color format. but [bgr8] is. The conversion does not make sense
  
 

 

如何解决呢? 

提示:

current_frame = self.br.imgmsg_to_cv2(data, "rgb8")

答案:

[8UC3] is not a color format. but [rgb8] is.



      zhangrelay@LAPTOP-5REQ7K1L:~$ ros2 node list
      /face_detection
      /image_publisher
      /rqt_gui_py_node_1492
      zhangrelay@LAPTOP-5REQ7K1L:~$ ros2 node info /face_detection
      /face_detection
        Subscribers:
          /image_raw: sensor_msgs/msg/Image
        Publishers:
          /parameter_events: rcl_interfaces/msg/ParameterEvent
          /rosout: rcl_interfaces/msg/Log
        Service Servers:
          /face_detection/describe_parameters: rcl_interfaces/srv/DescribeParameters
          /face_detection/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
          /face_detection/get_parameters: rcl_interfaces/srv/GetParameters
          /face_detection/list_parameters: rcl_interfaces/srv/ListParameters
          /face_detection/set_parameters: rcl_interfaces/srv/SetParameters
          /face_detection/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
        Service Clients:
        Action Servers:
        Action Clients:
      zhangrelay@LAPTOP-5REQ7K1L:~$
  
 

基础概念

什么是人脸检测?
在计算机视觉中,试图解决的一个基本问题是在没有人工干预的情况下自动检测图像中的对象。人脸检测可以被认为是在图像中检测人脸的问题。人类的面部可能存在细微差异,但总的来说,可以肯定地说,某些特征与所有人类面部相关。人脸检测算法有很多种。

人脸检测通常是许多人脸相关技术的第一步,例如人脸识别或验证。然而,人脸检测可以有非常有用的应用。人脸检测最成功的应用可能是拍照。当您为朋友拍照时,数码相机内置的人脸检测算法会检测人脸的位置并相应地调整焦点。

什么是 OpenCV
在人工智能领域,计算机视觉是最有趣和最具挑战性的任务之一。计算机视觉就像计算机软件和我们周围的可视化之间的桥梁。它允许计算机软件理解和了解周围环境的可视化。例如:根据颜色、形状和大小确定水果。这项任务对人脑来说可能很容易,但是在计算机视觉管道中,首先我们收集数据,然后执行数据处理活动,然后训练和教授模型以了解如何根据大小区分水果,水果的形状和颜色。

目前,存在各种软件包来执行机器学习、深度学习和计算机视觉任务。到目前为止,计算机视觉是此类复杂活动的最佳模块。 OpenCV 是一个开源库。它受到各种编程语言的支持,例如 R、Python。它可以在大多数平台上运行,例如 Windows、Linux 和 MacOS。


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

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

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

作者其他文章

评论(0

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

    全部回复

    上滑加载中

    设置昵称

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

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

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