ROS压缩深度图像收听是真的麻烦,自己记录一下,针对32FC1的压缩深度图。
import struct, cv2
import numpy as np
def depthcompressCB(data):
nparr = np.fromstring(data.data[12:], np.uint8)
depthraw = cv2.imdecode(nparr, cv2.IMREAD_ANYDEPTH)
# 16UC1的到上面就可以了
rawheader = data.data[:12}
[fmt, dqA, dqB] = struct.unpack('iff', rawheader)
depthimg = dqA / (depthraw.astype(np.float32) - dqB)
depthimg[depthraw==0] = 0