Skip to content

Instantly share code, notes, and snippets.

@chunibyo-wly
Created March 2, 2021 07:48
Show Gist options
  • Save chunibyo-wly/4a373d029770616493a779e464895b2e to your computer and use it in GitHub Desktop.
Save chunibyo-wly/4a373d029770616493a779e464895b2e to your computer and use it in GitHub Desktop.
get depth data
CVPixelBufferLockBaseAddress(depthFrame, .readOnly)
let rowData = CVPixelBufferGetBaseAddress(depthFrame)! + Int(depthPoint.y) * CVPixelBufferGetBytesPerRow(depthFrame)
// swift does not have an Float16 data type. Use UInt16 instead, and then translate
var f16Pixel = rowData.assumingMemoryBound(to: UInt16.self)[Int(depthPoint.x)]
CVPixelBufferUnlockBaseAddress(depthFrame, .readOnly)
var f32Pixel = Float(0.0)
var src = vImage_Buffer(data: &f16Pixel, height: 1, width: 1, rowBytes: 2)
var dst = vImage_Buffer(data: &f32Pixel, height: 1, width: 1, rowBytes: 4)
vImageConvert_Planar16FtoPlanarF(&src, &dst, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment