【问题标题】:imwrite 16 bit png depth imageimwrite 16 位 png 深度图像
【发布时间】: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


【解决方案1】:

虽然我的数据类型是这样的

<type 'numpy.uint16'>

解决方案,我的问题是将这一行添加到我的代码中

depth.astype(np.uint16)

【讨论】:

  • 感谢您的修复,我正在为此而烦恼。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-25
  • 2014-08-25
  • 1970-01-01
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
相关资源
最近更新 更多