DepthData-获取每个像素的深度数据(CVPixelBuffer数据分析) [英] DepthData - Get per-pixel depth data (CVPixelBuffer data analysis)

查看:98
本文介绍了DepthData-获取每个像素的深度数据(CVPixelBuffer数据分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我运行的 AVDepthPhotoFilter 可以从iPhone7Plus的立体摄像机渲染深度Deta.

Now I run AVDepthPhotoFilter that Rendering Depth Deta from a stereo camera of iPhone7Plus.

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

So, I want to access per-pixel depth data, but, I don’t know how to do it. Please advice.

推荐答案

如何获取DepthData和分析CVPixelBuffer数据

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

  1. You need to make sure your AVCapturePhotoSettings() has isDepthDataDeliveryEnabled = true

您必须使用函数 func photoOutput(_输出:AVCapturePhotoOutput,didFinishProcessingPhoto照片:AVCapturePhoto,错误:错误?)

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分析的更多信息,请参阅以下有用的帖子-> 详细信息

If you want more informations about CVPixelBuffer analysis, here is a useful post -> details

这篇关于DepthData-获取每个像素的深度数据(CVPixelBuffer数据分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆