因为发布要求的是8位
发布出来的是float64位,需要改变格式
def callback(self,data):
print('callback')
img = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)
img = img[:,:,::-1]
self.img = img
print(img.shape)
m = self.deHaze(img/255)*255
#print(dtype) # 处理完要float64 还有负值
m = np.clip(m,a_min=0,a_max=255) #先归一化到0-255消除负数
print(m)
m = m.astype(np.int8) #在转化为8位数
print(m.dtype)
self.publish_image(self.pub1,m,'base_link')
print('finish remove fog')
def publish_image(self,pub, data, frame_id='base_link'):
assert len(data.shape) == 3, 'len(data.shape) must be equal to 3.'
print(data.shape)
header = Header(stamp=rospy.Time.now())
header.frame_id = frame_id
msg = Image()
msg.height = data.shape[0]
msg.width = data.shape[1]
msg.encoding = 'rgb8' #传入数据要求是8位
msg.data = np.array(data).tostring()
msg.header = header
msg.step = msg.width *1*3
print("**************************")
pub.publish(msg)
print("---------------------------")