Created
March 2, 2021 07:48
-
-
Save chunibyo-wly/4a373d029770616493a779e464895b2e to your computer and use it in GitHub Desktop.
get depth data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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