鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    4.2.4人脸检测客户端实现错误

    已定时 已固定 已锁定 已移动
    动手学ROS2
    not numpy错误 人脸检测
    3
    5
    574
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 4
      开心
      最后由 编辑

      [INFO] [1712386054.199687907] [face_detect_client]: 等待服务端上线......
      Traceback (most recent call last):
      File "/home/tingbo/chapt4/chapt4_ws/src/install/demo_python_service/lib/demo_python_service/face_detect_client_node", line 33, in <module>
      sys.exit(load_entry_point('demo-python-service==0.0.0', 'console_scripts', 'face_detect_client_node')())
      File "/home/tingbo/chapt4/chapt4_ws/src/install/demo_python_service/lib/python3.10/site-packages/demo_python_service/face_detect_client_node.py", line 43, in main
      face_detect_client.send_request()
      File "/home/tingbo/chapt4/chapt4_ws/src/install/demo_python_service/lib/python3.10/site-packages/demo_python_service/face_detect_client_node.py", line 21, in send_request
      request.image = self.bridge.cv2_to_compressed_imgmsg(self.image)
      File "/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/core.py", line 228, in cv2_to_compressed_imgmsg
      raise TypeError('Your input type is not a numpy array')
      TypeError: Your input type is not a numpy array
      [ros2run]: Process exited with failure 1

      客户端代码
      import rclpy
      from rclpy.node import Node
      from chapt4_interfaces.srv import FaceDetector
      from sensor_msgs.msg import Image
      from ament_index_python.packages import get_package_share_directory
      import cv2
      from cv_bridge import CvBridge

      class FaceDetectorClient(Node):
      def init(self):
      super().init('face_detect_client')
      self.client = self.create_client(FaceDetector, '/face_detect')
      self.bridge = CvBridge()
      self.test1_image_path = get_package_share_directory(
      'demo_python_service')+'resource/test1.jpg'
      self.image = cv2.imread(self.test1_image_path)
      def send_request(self):
      while self.client.wait_for_service(timeout_sec=1.0) is False:
      self.get_logger().info(f'等待服务端上线......')
      request = FaceDetector.Request()
      request.image = self.bridge.cv2_to_compressed_imgmsg(self.image)
      future = self.client.call_async(request)
      rclpy.spin_until_future_complete(self, future)
      response = future.result()
      self.get_logger().info(
      f'接收到响应: 图像中共有:{response.number}张脸,耗时{response.use_time}')
      self.show_face_locations(response)

      def show_face_locations(self,response):
          for i in range(response.number):
              top = response.top[i]
              right = response.right[i]
              bottom = response.bottom[i]
              left = response.left[i]
              cv2.rectangle(self.image, (left, top), (right, bottom),(255, 0, 0), 2)
          cv2.imshow('Face Detection Result',self.image)
          cv2.waitKey(0)
      

      def main(args=None):
      rclpy.init(args=args)
      face_detect_client = FaceDetectorClient()
      face_detect_client.send_request()
      rclpy.shutdown()

      小鱼小 2 2 条回复 最后回复 回复 引用 0
      • 小鱼小
        小鱼 技术大佬 @43996173
        最后由 编辑

        @43996173 确认下图片路径下是否有对应图片,可以加个文件路径打印

        新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

        4 1 条回复 最后回复 回复 引用 0
        • 4
          开心 @小鱼
          最后由 编辑

          @小鱼 e1fabfff-9a3d-40cc-8e48-b507d750d4b0-image.png

          1 条回复 最后回复 回复 引用 0
          • 2
            2041525450 @43996173
            最后由 编辑

            @43996173 Traceback (most recent call last):
            File "/home/ros2-ll/chapt4/chapt4_ws/install/demo_python_service/lib/demo_python_service/face_detect_client_node", line 33, in <module>
            sys.exit(load_entry_point('demo-python-service==0.0.0', 'console_scripts', 'face_detect_client_node')())
            File "/home/ros2-ll/chapt4/chapt4_ws/install/demo_python_service/lib/python3.10/site-packages/demo_python_service/face_detect_client_node.py", line 41, in main
            face_detect_client = FaceDetectorClient()
            TypeError: Node.init() missing 1 required positional argument: 'node_name'
            [ros2run]: Process exited with failure 1
            复制了又有这种报错

            小鱼小 1 条回复 最后回复 回复 引用 0
            • 小鱼小
              小鱼 技术大佬 @2041525450
              最后由 编辑

              @2041525450 https://fishros.org.cn/forum/topic/151/提问前必看-不符合要求的问题拒绝回答

              新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

              1 条回复 最后回复 回复 引用 0
              • 第一个帖子
                最后一个帖子
              皖ICP备16016415号-7
              Powered by NodeBB | 鱼香ROS