gpt4 book ai didi

image - 在没有 iPhone 7+ 的情况下使用 AVDepthData 获取媒体

转载 作者:行者123 更新时间:2023-12-02 15:09:28 26 4
gpt4 key购买 nike

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

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

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

最佳答案

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

  1. 创建深度/视差字典,如 CGImageSource.h CGImageSourceCopyAuxiliaryDataInfoAtIndex 中所述 - 然而,以下是更多详细信息:

Key kCGImageAuxiliaryDataInfoData - (CFDataRef) - 深度数据

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

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

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

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

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

  • kCGImagePropertyPixelFormat 是 CoreVideo/CVPixelBuffer.h 深度/视差格式之一
  • kCGImagePropertyWidth/Height 是像素尺寸
  • kCGImagePropertyBytesPerRow 是正确的,就像它在 jar 头上所说的那样

kCGImageAuxiliaryDataInfoMetadata - (CGImageMetadataRef) - 元数据

这个值是可选的。

  1. init(fromDictionaryRepresentation: [AnyHashable : Any]) 创建 AVDepthData传递上面创建的字典。
  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?

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

    // Add auxiliary data to image destination  
    CGImageDestinationAddAuxiliaryDataInfo(cgImageDestination, auxDataType!, auxData! as CFDictionary)  

    if CGImageDestinationFinalize(cgImageDestination) {  
    return data as Data  
    }  

关于image - 在没有 iPhone 7+ 的情况下使用 AVDepthData 获取媒体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44809961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com