imwrite 16位png深度imag

2024-06-01 02:50:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码。我试图将从Kinect v1检索到的16位深度图像保存为png文件。我编写了以下代码示例:

def display_depth(dev, data, timestamp):
    global keep_runningp    
    #cv2.imshow('Depth', frame_convert2.pretty_depth_cv(data))
    cv2.imshow('Depth', frame_convert2.pretty_depth_cv(data))
    print type(data)
    print data.shape
    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位无符号的NumPy数组转换为8位无符号的NumPy数组)时,它起作用:

depth = depth.astype(np.uint8)

没有这一行,我只是得到整个空白/白色png图像。但是我需要一个16位的png文件。

如何将其保存为16位png文件?


Tags: 文件代码图像datapngprettycv2frame