Gui*_*uig 2 image depth iphone7plus ios11
在没有 iPhone 7+ 的情况下为 AVDepthData 构建应用程序的最佳方法是什么?
深度数据只能在配备双镜头摄像头的 iPhone 7+ 上捕获。但我想任何 iOS11 设备都可以处理深度数据,只要它能够访问包含深度数据的照片。我在网上找不到苹果或其他方的任何此类媒体资源。有人有吗?或者,还有更好的方法?
我尝试查看 iPhone 7+ 模拟器库,但模拟器崩溃了,因为它不支持深度演示应用程序正在使用的 Metal。
虽然这是一项不简单的任务,但可以生成 AVDepthData 并将其添加到您自己的图像中。
\n\nCGImageSource.h CGImageSourceCopyAuxiliaryDataInfoAtIndex- 但是,以下是更多详细信息:键kCGImageAuxiliaryDataInfoData- ( CFDataRef) - 深度数据
仅包含一个二进制像素缓冲区。如其中\xe2\x80\x99s 所示,您通过读取 CVPixelBufferLockBaseAddress 中的指针从像素缓冲区中提取数据。您可以使用受支持类型之一的格式创建 CVPixelBuffer:
\n\n要将任意灰度图像转换为假深度缓冲区,您\xe2\x80\x99需要将每个像素的灰度像素值(0=黑色到1=白色,zNear到zFar等)转换为米或1/米,具体取决于您的目标格式。并将它们转换为正确的浮点格式,具体取决于您从何处获取它们。
\n\n键kCGImageAuxiliaryDataInfoDataDescription- ( CFDictionary) - 深度数据描述
告诉您如何解释我们给您的缓冲区,或者告诉我们如何解释您给我们的缓冲区:
\n\n键kCGImageAuxiliaryDataInfoMetadata- ( CGImageMetadataRef) - 元数据
该值是可选的。
\n\n使用 ImageI/O 创建图像:
\n\n// create the image destination (not shown)\n\n//\xc2\xa0add\xc2\xa0an image to the destination\nCGImageDestinationAddImage(cgImageDestination,\xc2\xa0renderedCGImage,\xc2\xa0attachments)\xc2\xa0\xc2\xa0\n\n//\xc2\xa0Use\xc2\xa0AVDepthData\xc2\xa0to\xc2\xa0get\xc2\xa0auxiliary\xc2\xa0data\xc2\xa0dictionary\xc2\xa0\xc2\xa0 \nRun Code Online (Sandbox Code Playgroud)\n\nvar\xc2\xa0auxDataType\xc2\xa0:NSString?\xc2\xa0
\n\nlet\xc2\xa0auxData\xc2\xa0=\xc2\xa0depthData.dictionaryRepresentation(forAuxiliaryDataType:\xc2\xa0&auxDataType)\xc2\xa0\xc2\xa0
\n\n//\xc2\xa0Add\xc2\xa0auxiliary\xc2\xa0data\xc2\xa0to\xc2\xa0image\xc2\xa0destination\xc2\xa0\xc2\xa0\nCGImageDestinationAddAuxiliaryDataInfo(cgImageDestination,\xc2\xa0auxDataType!,\xc2\xa0auxData!\xc2\xa0as\xc2\xa0CFDictionary)\xc2\xa0\xc2\xa0\n\nif\xc2\xa0CGImageDestinationFinalize(cgImageDestination)\xc2\xa0{\xc2\xa0\xc2\xa0\n return\xc2\xa0data\xc2\xa0as\xc2\xa0Data\xc2\xa0\xc2\xa0\n}\xc2\xa0\xc2\xa0\nRun Code Online (Sandbox Code Playgroud)