I have the following code. I am trying to save a 16 bit depth image which I retrieve from Kinect v1 as a png file. I wrote the following code sample:
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
It works when I add the following code, which converts data from a 16 bit unsigned to an 8 bit unsigned NumPy array:
depth = depth.astype(np.uint8)
Without this line, I am just getting the whole blank/white png image. But I need to have a 16 bit png file.
How I can save it as a 16 bit png file?
a = np.random.randint(0, 65536, size=(48, 48, 3)).astype(np.uint16)
and then runcv2.imwrite('foo.png', a)
, I get a 16 bit RGB file. If instead I usea = np.random.randint(0, 65535, size=(48, 48)).astype(np.uint16)
, I get a 16 bit grayscale image. In other words,cv2.imwrite()
works for me. I think we need a minimal, complete and verifiable example to help you. – Nucleusframe_convert2.pretty_depth(data)
this means you are NOT saving a 16 bit image but a 8 bit image. If you take a look to the function implementation it actually doesdepth = depth.astype(np.uint8)
– Importunate