gpt4 book ai didi

swift - DepthData - 获取每像素深度数据(CVPixelBuffer数据分析)

转载 作者:行者123 更新时间:2023-12-02 18:21:05 24 4
gpt4 key购买 nike

现在我运行 AVDepthPhotoFilter,从 iPhone7Plus 的立体摄像头渲染深度 Deta。

所以,我想访问每像素深度数据,但是,我不知道该怎么做。请指教。

最佳答案

如何获取DepthData并分析CVPixelBuffer数据

  1. 您需要确保 AVCapturePhotoSettings() 的 isDepthDataDeliveryEnabled = true

  2. 您必须使用函数func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?)

    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

    //## Convert Disparity to Depth ##

    let depthData = (photo.depthData as AVDepthData!).converting(toDepthDataType: kCVPixelFormatType_DepthFloat32)
    let depthDataMap = depthData.depthDataMap //AVDepthData -> CVPixelBuffer

    //## Data Analysis ##

    // Useful data
    let width = CVPixelBufferGetWidth(depthDataMap) //768 on an iPhone 7+
    let height = CVPixelBufferGetHeight(depthDataMap) //576 on an iPhone 7+
    CVPixelBufferLockBaseAddress(depthDataMap, CVPixelBufferLockFlags(rawValue: 0))

    // Convert the base address to a safe pointer of the appropriate type
    let floatBuffer = unsafeBitCast(CVPixelBufferGetBaseAddress(depthDataMap), to: UnsafeMutablePointer<Float32>.self)

    // Read the data (returns value of type Float)
    // Accessible values : (width-1) * (height-1) = 767 * 575

    let distanceAtXYPoint = floatBuffer[Int(x * y)]

    }

如果您想了解有关 CVPixelBuffer 分析的更多信息,这里有一篇有用的文章 -> details

关于swift - DepthData - 获取每像素深度数据(CVPixelBuffer数据分析),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46794561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com