注意:此信息基于 SICK 支持论坛上的SICK TriSpector 常见问题解答(不可公开访问,但您可以请求访问)。
SICK TriSpector 生成的 PNG 图像存储两个像素缓冲区的串联:
生成的 PNG 图像与每个组件具有相同的宽度,而高度是其三倍(因为 PNG 是 8 位的,每个像素位置总共有 3 个字节)。
让我们考虑一个简单的示例,其中组件有 3 行和 4 列。存储在 PNG 中的数据将具有以下结构:

如上图所示,第一步是将图像拆分为两个组件。PNG 包含 9 行,其中三分之一是 3 行——因此第 0-2 行包含强度,其余的是高度图。强度图直接可用,高度图需要进一步处理。
如果我们使用 little-endian 架构并且不关心可移植性,我们可以利用内存中的布局并将像素缓冲区重新解释为 16 位无符号整数(在 Pythonnumpy.ndarray.view
中,在 C++ 中创建一个新Mat
的包装缓冲区)。
更灵活但速度较慢的方法是手动组合部件。重塑数组以具有正确的行数,然后根据奇数或偶数列数将其拆分(在 Python 中跳过索引)。将每个子数组转换为 16 位无符号整数,最后按公式组合LSB + 256 * HSB
。

Python 中的示例脚本:
import cv2
import numpy as np
img = cv2.imread('combined.png', cv2.IMREAD_GRAYSCALE)
height, width = img.shape
# Determine the actual height of the component images
real_height = height/3
# Extract the top (intensity) part
intensity_img = img[:real_height,...]
# Extract the botton (heightmap) part
# Since this has two values per pixel, also reshape it to have the correct number of rows
heightmap_raw = img[real_height:,...].reshape(real_height,-1)
# The heightmap is 16 bit, two subsequent 8 bit pixels need to be combined
# ABCD -> A+256*B, C+256*D
# Quick but non-portable (needs little-endian architecture)
heightmap_img = heightmap_raw.view(np.uint16)
# Slower but portable
heightmap_a = heightmap_raw[...,::2].astype(np.uint16)
heightmap_b = heightmap_raw[...,1::2].astype(np.uint16)
heightmap_img = heightmap_a + 256 * heightmap_b
# Note: intensity is np.uint8, heightmap is np.uint16
cv2.imwrite('intensity.png', intensity_img)
cv2.imwrite('heightmap.png', heightmap_img)
提取的强度图像:

提取的高度图图像(请注意,原始数据被缩小了 256 倍,同时保存以作说明,丢失了很多细节):
