I'm using ARKit to collect LiDAR data. I have read the depth map and its format is 'kCVPixelFormatType_DepthFloat32'. I saved the depth map to a PNG image by converting it to UIImage, but I found that the PNG depth map is incorrect. The PNG format only supports 16bit data.
let ciImage = CIImage(cvPixelBuffer: pixelBuf)
let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
let uiImage = UIImage(cgImage: cgImage!).pngData()
So, I have to save the depth map to a TIFF image.
let ciImage = CIImage(cvPixelBuffer: pixelBuf)
do {
try context.writeTIFFRepresentation(of: ciImage, to: path, format: context.workingFormat, colorSpace: context.workingColorSpace!, options: [:])
} catch {
self.showInfo += "Save TIFF failed;"
print(error)
}
How to convert the depth map from kCVPixelFormatType_DepthFloat32 to Float16? Is there a correct way to save the depth map to a PNG image?