Created
March 2, 2021 07:46
-
-
Save chunibyo-wly/d6efa175d5a1fd2b34207826daca1bff 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(pixelBuffer, kCVPixelBufferLock_ReadOnly); | |
const uint8_t* baseAddress = (const uint8_t*)CVPixelBufferGetBaseAddress(pixelBuffer); | |
for (size_t y = 0; y < height; ++y) { | |
const __fp16* data = (const __fp16*)(baseAddress + y * stride); | |
for (size_t x = 0; x < width; ++x, ++data) { | |
__fp16 depth = *data; | |
if (!isnan(depth) && depth > minDepth) { | |
float f32Pixel = 0.0f; | |
vImage_Buffer src, dst; | |
src.data = &depth; src.height = 1; src.width = 1; src.rowBytes = 2; | |
dst.data = &f32Pixel; dst.height = 1; dst.width = 1; dst.rowBytes = 4; | |
vImageConvert_Planar16FtoPlanarF(&src, &dst, 0); | |
} | |
} | |
} | |
CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment