1

I am trying to use the depthmap data, but in a very simple way. I am reading data from the Lidar. The data is somehow unexpected. When the iPhone 14 Pro is parallel to a flat wall, say in a distance of 0.3 meter. I would expect to read that 0,3 meter (the one exactly opposite to the camera.) But do not. All data is more than 0,3 meter, even 1.2 meter and more. Any insight would be highly appreciated.

  func depthDataOutput(syncedDepthData: AVCaptureSynchronizedDepthData) {
        let depthData = syncedDepthData.depthData.converting(toDepthDataType: kCVPixelFormatType_DepthFloat16)
        let depthMapWidth = CVPixelBufferGetWidthOfPlane(depthData.depthDataMap, 0)
        let depthMapHeight = CVPixelBufferGetHeightOfPlane(depthData.depthDataMap, 0)
        print("Depth quality: \(depthData.depthDataQuality) accuracy: \(depthData.depthDataAccuracy) pixelSize: \(String(describing: depthData.cameraCalibrationData?.pixelSize))")
        CVPixelBufferLockBaseAddress(depthData.depthDataMap, .readOnly)
        if let rowData = CVPixelBufferGetBaseAddress(depthData.depthDataMap)?.assumingMemoryBound(to: Float16.self) {
            var depthArray = [Float16]()
            for y in 0...depthMapHeight-1 {
                var distancesLine = [Float16]()
                for x in 0...depthMapWidth-1 {
                    let distanceAtXYPoint = rowData[y * depthMapWidth + x]
                    distancesLine.append(distanceAtXYPoint)
                }
                let sum = distancesLine.reduce(0, +)
                let average = sum / Float16(distancesLine.count)
                let min_r = distancesLine.min()
                depthArray.append(Float16(min_r!))
            }
            let sum2 = depthArray.reduce(0, +)
            let average2 = sum2 / Float16(depthArray.count)
            let min = depthArray.min()            
            print("Depth value in meters avg: \(average2) min: \(min!) meters")
        }
        CVPixelBufferUnlockBaseAddress(depthData.depthDataMap, .readOnly)
    }
Taras Buha
  • 11
  • 1
  • what a great piece of code I spent so much time trying to read this pixel buffer! – Nicolas Manzini Jul 25 '23 at 16:17
  • did you find something? on my sides values seems to be completely irrelevant moving from 50cm to 1.5m for the same distance and never going down for close objects. I'm on an iPhone12 pro with the lidar camera. – Nicolas Manzini Jul 26 '23 at 13:00

0 Answers0