gpt4 book ai didi

ios - 如何从 AVDepthData 缓冲区读取 CGPoint 处的深度数据

转载 作者:IT王子 更新时间:2023-10-29 05:53:15 25 4
gpt4 key购买 nike

我试图在捕获的图像中的某个点找到深度数据,并返回以 为单位的距离。

我已启用深度数据并在图像旁边捕获数据。我从图像中心的 X、Y 坐标(以及按下时)获取点,并使用

将其转换为缓冲区索引
Int((width - touchPoint.x) * (height - touchPoint.y))

WIDTHHEIGHT 是捕获图像的尺寸。不过,我不确定这是否是实现此目标的正确方法。

我这样处理深度数据:

func handlePhotoDepthCalculation(point : Int) {

guard let depth = self.photo else {
return
}

//
// Convert Disparity to Depth
//
let depthData = (depth.depthData as AVDepthData!).converting(toDepthDataType: kCVPixelFormatType_DepthFloat32)
let depthDataMap = depthData.depthDataMap //AVDepthData -> CVPixelBuffer

//
// Set Accuracy feedback
//
let accuracy = depthData.depthDataAccuracy
switch (accuracy) {
case .absolute:
/*
NOTE - Values within the depth map are absolutely
accurate within the physical world.
*/
self.accuracyLbl.text = "Absolute"
break
case .relative:
/*
NOTE - Values within the depth data map are usable for
foreground/background separation, but are not absolutely
accurate in the physical world. iPhone always produces this.
*/
self.accuracyLbl.text = "Relative"
}

//
// We convert the data
//
CVPixelBufferLockBaseAddress(depthDataMap, CVPixelBufferLockFlags(rawValue: 0))
let depthPointer = unsafeBitCast(CVPixelBufferGetBaseAddress(depthDataMap), to: UnsafeMutablePointer<Float32>.self)

//
// Get depth value for image center
//
let distanceAtXYPoint = depthPointer[point]

//
// Set UI
//
self.distanceLbl.text = "\(distanceAtXYPoint) m" //Returns distance in meters?
self.filteredLbl.text = "\(depthData.isDepthDataFiltered)"
}

我不相信我得到了正确的位置。从我的研究来看,精度似乎只在 .relative.absolute 中返回,而不是 float /整数?

最佳答案

要访问 CGPoint 的深度数据,请执行以下操作:

let point = CGPoint(35,26)
let width = CVPixelBufferGetWidth(depthDataMap)
let distanceAtXYPoint = depthPointer[Int(point.y * CGFloat(width) + point.x)]

我希望它有用。

关于ios - 如何从 AVDepthData 缓冲区读取 CGPoint 处的深度数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47229698/

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