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?
Though type of my data was like this
<type 'numpy.uint16'>
Solution , to my problem was adding this line to my code
depth.astype(np.uint16)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With