【问题标题】:DepthData - Get per-pixel depth data (CVPixelBuffer data analysis)DepthData - 获取每像素深度数据(CVPixelBuffer 数据分析)
【发布时间】:2017-10-25 19:58:32
【问题描述】:

现在我从 iPhone7Plus 的立体摄像头运行 AVDepthPhotoFilter Rendering Depth Deta。

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

【问题讨论】:

    标签: swift ios11 cvpixelbuffer iphone7plus


    【解决方案1】:

    如何获取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

    【讨论】:

    • 帮了我很多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 2018-06-26
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    相关资源
    最近更新 更多