Skip to content

Instantly share code, notes, and snippets.

@chunibyo-wly
Created March 2, 2021 07:46
Show Gist options
  • Save chunibyo-wly/d6efa175d5a1fd2b34207826daca1bff to your computer and use it in GitHub Desktop.
Save chunibyo-wly/d6efa175d5a1fd2b34207826daca1bff to your computer and use it in GitHub Desktop.
get depth data
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