arkit - iOS ARKit AVDepthData 返回巨大的数字
问题描述
不知道我在这里做错了什么,但是 AVDepthData,它应该以米为单位用于非差异数据,它返回了巨大的数字。我有代码...
-(bool)getCurrentFrameDepthBufferIntoBuffer:(ARSession*)session buffer:(BytePtr)buffer width:(int)width height:(int)height bytesPerPixel:(int)bytesPerPixel
{
// do we have a current frame
if (session.currentFrame != nil)
{
// do we have a captured image?
if (session.currentFrame.capturedDepthData != nil)
{
// get depth data parameters
int ciImageWidth = (int)CVPixelBufferGetWidth(session.currentFrame.capturedDepthData.depthDataMap);
int ciImageHeight = (int)CVPixelBufferGetHeight(session.currentFrame.capturedDepthData.depthDataMap);
// how many bytes per pixel
int bytesPerPixel;
if (session.currentFrame.capturedDepthData.depthDataType == kCVPixelFormatType_DisparityFloat16 ||
session.currentFrame.capturedDepthData.depthDataType == kCVPixelFormatType_DepthFloat16)
bytesPerPixel = 2;
else
bytesPerPixel = 4;
// copy to passed buffer
CVPixelBufferLockBaseAddress(session.currentFrame.capturedDepthData.depthDataMap, kCVPixelBufferLock_ReadOnly);
memcpy(buffer, session.currentFrame.capturedDepthData.depthDataMap, ciImageWidth*ciImageHeight*bytesPerPixel);
float *floatBuffer = (float*)buffer;
float maxDepth = 0.0f;
float minDepth = 0.0f;
for (int i=0; i < ciImageWidth*ciImageHeight; i++)
{
if (floatBuffer[i] > maxDepth)
maxDepth = floatBuffer[i];
if (floatBuffer[i] < minDepth)
minDepth = floatBuffer[i];
}
NSLog(@"In iOS, max depth is %f min depth is %f", maxDepth, minDepth);
CVPixelBufferUnlockBaseAddress(session.currentFrame.capturedDepthData.depthDataMap, kCVPixelBufferLock_ReadOnly);
}
}
return true;
}
但它返回最小值和最大值,例如......
2019-06-27 12:32:32.167868+0900 AvatarBuilder[13577:2650159] 在 iOS 中,最大深度为 3531476501829561451725831270301696000.000000 最小深度为 -10967712993094046407301024
看起来一点也不像米。
解决方案
呃,这是我的memcpy。我必须做...
float *bufferAddress = (float*)CVPixelBufferGetBaseAddress(session.currentFrame.capturedDepthData.depthDataMap);
memcpy(buffer, bufferAddress, ciImageWidth*ciImageHeight*bytesPerPixel);
推荐阅读
- javascript - 如何验证登录页面的 websql 数据库中是否存在用户名和密码?
- javascript - 如何在 Javascript 中按名称删除兑现 - pwa
- flutter - 如何比较 Dart 中“is”运算符中的类型变量
- angular - 使用动态创建具有多个段的 SVG 圆
和 - laravel - 外键约束形成错误,Laravel
- javascript - 更新了关于获取一个字段值的旧问题的答案
- java - 在 Android 中过滤 - 代码有效但未按预期返回屏幕的问题
- c# - 是否可以将节点的 InnerXml 转换为新的节点集合?(C#)
- php - 如何使用 PHPUnit 测试命令行计算器?
- jquery - 如何在同一页面中打开更多模式