不知道我在这里做错了什么,但是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最小深度为-109677129931746407817494761329131520.000000
看起来不像米。
答案 0 :(得分:0)
呃,这是我的记忆。我必须做...
float *bufferAddress = (float*)CVPixelBufferGetBaseAddress(session.currentFrame.capturedDepthData.depthDataMap);
memcpy(buffer, bufferAddress, ciImageWidth*ciImageHeight*bytesPerPixel);