当前位置:   article > 正文

CompressImage、Image传输时出现size=0的情况!_acdbrasterimage imagesize为0

acdbrasterimage imagesize为0
  1. def capture_image(self, ret, image) -> CompressedImage:
  2. if ret:
  3. obj_cimage = CompressedImage()
  4. obj_head = Header()
  5. obj_head.frame_id = "camera"
  6. obj_head.stamp = rospy.Time.now()
  7. obj_head.seq = 0
  8. # 编码图像为PNG格式的二进制数据
  9. retval, buffer = cv2.imencode('.png', image)
  10. if retval:
  11. obj_cimage.data = np.array(buffer).tobytes()
  12. obj_cimage.format = "png"
  13. obj_cimage.header = obj_head
  14. return obj_cimage
  15. else:
  16. rospy.logerr("图像编码失败")
  17. else:
  18. rospy.logerr("没有摄像头数据")
  1. cvbridge=CvBridge()
  2. class Sub_image():
  3. def __init__(self) -> None:
  4. self.image_sub=rospy.Subscriber("/cam_image",CompressedImage,self.showcb,queue_size=1)
  5. def showcb(self,data):
  6. cv_image=cvbridge.compressed_imgmsg_to_cv2(data,"bgr8")
  7. cv2.imshow("dd",cv_image)
  8. cv2.waitKey(1)
  9. def main():
  10. rospy.init_node("test1",anonymous=True)
  11. # 实例化的时候自动就会执行init
  12. sub_obj=Sub_image()
  13. rospy.spin()

可以将图像通过cv2.imencode编码一下,就可以了,具体原因不知道为什么。。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/845603
推荐阅读
相关标签
  

闽ICP备14008679号