【发布时间】:2017-11-10 19:15:18
【问题描述】:
我试图在捕获的图像中的某个点找到深度数据,并在meters 中返回距离。
我已启用深度数据并在图像旁边捕获数据。我从图像中心的 X、Y 坐标(按下时)获取点,并使用
将其转换为缓冲区索引Int((width - touchPoint.x) * (height - touchPoint.y))
WIDTH 和 HEIGHT 是捕获图像的尺寸。我不确定这是否是实现这一目标的正确方法。
我这样处理深度数据:
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 中返回,而不是浮点数/整数?
【问题讨论】:
标签: ios swift avcapturesession