I am trying to build a point cloud with ARkit's depthmap, when I convert the depthmap to PNG file with following code, the depth map lose Z axis data.Any idea to solve this problem?
This is my code to store depthmap.
let depthimage = frame.sceneDepth!.depthMap
let ciImageDepth = CIImage(cvPixelBuffer: depthimage)
let contextDepth:CIContext = CIContext.init(options: nil)
let cgImageDepth:CGImage = context.createCGImage(ciImageDepth, from: ciImageDepth.extent)!
let width:Int = cgImageDepth.width
let height:Int = cgImageDepth.height
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceGray()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder16Little.rawValue)
let depthcontext:CGContext = CGContext(data: nil, width: width, height: height, bitsPerComponent: 16, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!
let rect:CGRect = CGRect.init(x: 0, y: 0, width: width, height: height)
depthcontext.draw(cgImageDepth, in: rect)
let outPutImage:CGImage = depthcontext.makeImage()!
let newImage:UIImage = UIImage.init(cgImage: outPutImage, scale: 1, orientation: UIImage.Orientation.up)