Depth data export

Hello,
I am currently working on figuring out how to export the TrueDepth camera Depth data from the sample code found here. I want to convert AVDepthData object to a list of real world XYZ coordinate, that i could export to a .txt file.

After searching the developer forum, I stumbled upon this arcticle. The following code:

Code Block Swift
privatefunc getPoints(avDepthData: AVDepthData)->Array{
let depthData = avDepthData.converting(toDepthDataType: kCVPixelFormatType_DepthFloat32)
guard let intrinsicMatrix = avDepthData.cameraCalibrationData?.intrinsicMatrix,
}
CVPixelBufferLockBaseAddress(depthDataMap, CVPixelBufferLockFlags(rawValue: 0))
let width = CVPixelBufferGetWidth(depthDataMap)
let height = CVPixelBufferGetHeight(depthDataMap)
var points = Array()
let focalX = Float(width) * (intrinsicMatrix[0][0] / PHOTO_WIDTH)
let focalY = Float(height) * ( intrinsicMatrix[1][1] / PHOTO_HEIGHT)
let principalPointX = Float(width) * (intrinsicMatrix[2][0] / PHOTO_WIDTH)
let principalPointY = Float(height) * (intrinsicMatrix[2][1] / PHOTO_HEIGHT)
for y in 0 ..< height{
for x in 0 ..< width{
guard let Z = getDistance(at: CGPoint(x: x, y: y) , depthMap: depthDataMap, depthWidth: width, depthHeight: height) else {
continue
}
let X = (Float(x) - principalPointX) * Z / focalX
let Y = (Float(y) - principalPointY) * Z / focalY
points.append(PointXYZ(x: X, y: Y, z: Z))
}
}
CVPixelBufferUnlockBaseAddress(depthDataMap, CVPixelBufferLockFlags(rawValue: 0))
return points
}

The problem with this is, that the sample code doesn't implement PHOTOWIDTH and PHOTOHEIGHT. Also, the rectification of the depth map was not posted, in my scenario it is not needed at the moment.

Maybe someone can help to manipulate this code in order to get the values ?

Replies

@Ricards97 Did you found the solution to your problem? If yes, can you please share it.

Thanks.