【发布时间】:2017-06-17 15:25:53
【问题描述】:
我有以下代码。我正在尝试将从 Kinect v1 检索到的 16 位深度图像保存为 png 文件。我编写了以下代码示例:
def display_depth(dev, data, timestamp):
global keep_runningp
cv2.imshow('Depth', frame_convert2.pretty_depth_cv(data))
depthf.write(repr(timestamp)+" Depth/"+repr(timestamp)+".png\n")
namef="Sample_dataset/Depth/"+repr(timestamp)+".png"
cv2.imwrite(namef,frame_convert2.pretty_depth(data))
if cv2.waitKey(10) == 27:
keep_running = False
当我添加以下代码时它可以工作,它将数据从 16 位无符号转换为 8 位无符号 NumPy 数组:
depth = depth.astype(np.uint8)
没有这条线,我只会得到整个空白/白色 png 图像。但我需要一个 16 位的 png 文件。
如何将其保存为 16 位 png 文件?
【问题讨论】:
-
如果我创建
a = np.random.randint(0, 65536, size=(48, 48, 3)).astype(np.uint16)然后运行 cv2.imwrite('foo.png', a),我会得到一个 16 位 RGB 文件。相反,如果我使用a = np.random.randint(0, 65535, size=(48, 48)).astype(np.uint16),我会得到一个 16 位灰度图像。换句话说,cv2.imwrite()为我工作。我想我们需要minimal, complete and verifiable example 来帮助您。 -
您正在保存
frame_convert2.pretty_depth(data)这意味着您保存的不是 16 位图像,而是 8 位图像。如果你看一下function implementation,它实际上是depth = depth.astype(np.uint8) -
我实现了我的自定义 frame_convert 并正在导入那个。
标签: python opencv numpy kinect