获取媒体与 AVDepthData 没有 iPhone 7+

Get media with AVDepthData without an iPhone 7+

在没有 iPhone 7+ 的情况下为 AVDepthData 构建应用程序的最佳方法是什么?

深度数据只能在 iPhone 7+ 的双镜头相机上拍摄。但我想任何 iOS11 设备都可以处理深度数据,前提是它可以访问包含深度数据的照片。我无法从 Apple 或在线其他方找到任何此类媒体资源。有人有吗?或者有更好的方法吗?

我尝试查看 iPhone 7+ 模拟器库,但模拟器崩溃,因为它不支持深度演示应用程序正在使用的 Metal。

我想您可以在任何 iOS 设备上处理照片的深度数据。您只需要 iPhone 7+ 拍摄的照片样本。 Here 是其中的几个。

你需要有 iPhone 7+ 和 iOS 11 的人(比如我)才能向你发送图片。

在 iOS 11 上使用 Safari 访问此 link 并点击 more... -> Save Image

http://hellocamera.co/img/depth-photo.heic

注意:我从这张图片中删除了 gps 数据。

虽然这是一项艰巨的任务,但可以生成 AVDepthData 并将其添加到您自己的图像中。

  1. CGImageSource.h CGImageSourceCopyAuxiliaryDataInfoAtIndex 中记录的那样创建一个 depth/disparity 字典 - 但是,以下是更多详细信息:

Key kCGImageAuxiliaryDataInfoData - (CFDataRef) - 深度数据

仅包含一个二进制像素缓冲区。因为它是您通过读取 CVPixelBufferLockBaseAddress 中的指针从像素缓冲区中提取的数据。您使用一种受支持类型的格式创建 CVPixelBuffer:

  • kCVPixelFormatType_DisparityFloat16 = 'hdis', /* IEEE754-2008 binary16(半浮点数),描述比较两个图像时的归一化偏移。单位是 1/米:( pixelShift / (pixelFocalLength * baselineInMeters) ) */
  • kCVPixelFormatType_DisparityFloat32 = 'fdis', /* IEEE754-2008 binary32 float,描述比较两个图像时的归一化偏移。单位是 1/米:( pixelShift / (pixelFocalLength * baselineInMeters) ) */
  • kCVPixelFormatType_DepthFloat16 = 'hdep', /* IEEE754-2008 binary16(半浮点数),以米为单位描述深度(到物体的距离)*/
  • kCVPixelFormatType_DepthFloat32 = 'fdep', /* IEEE754-2008 binary32 float,以米为单位描述深度(到物体的距离)*/

要将任意灰度图像转换为假深度缓冲区,您需要将每个像素的灰度像素值(0=黑色到 1=白色、zNear 到 zFar 等)转换为米或 1/米,具体取决于您的目标格式。并将它们转换为正确的浮点格式,具体取决于您从何处获取它们。

Key kCGImageAuxiliaryDataInfoDataDescription - (CFDictionary) - 深度数据描述

告诉您如何解释我们给您的缓冲区,或告诉我们如何解释您给我们的缓冲区:

  • kCGImagePropertyPixelFormat 是 CoreVideo/CVPixelBuffer.h depth/disparity 格式之一
  • kCGImagePropertyWidth/Height 是像素尺寸
  • kCGImagePropertyBytesPerRow 是它在罐子上所说的正确

密钥kCGImageAuxiliaryDataInfoMetadata - (CGImageMetadataRef) - 元数据

这个值是可选的。

  1. 创建 AVDepthData,init(fromDictionaryRepresentation: [AnyHashable : Any]) 传递上面创建的字典。
  2. 使用 ImageI/O 创建图像:

    // create the image destination (not shown)
    
    // add an image to the destination
    CGImageDestinationAddImage(cgImageDestination, renderedCGImage, attachments)  
    
    // Use AVDepthData to get auxiliary data dictionary          
    

    var auxDataType :NSString?

    let auxData = depthData.dictionaryRepresentation(forAuxiliaryDataType: &auxDataType)

    // Add auxiliary data to image destination  
    CGImageDestinationAddAuxiliaryDataInfo(cgImageDestination, auxDataType!, auxData! as CFDictionary)  
    
    if CGImageDestinationFinalize(cgImageDestination) {  
        return data as Data  
    }