gpt4 book ai didi

ios - swift 3 : How to access the value of matrix_float3x3 in a 48-byte CFData?

转载 作者:搜寻专家 更新时间:2023-10-31 22:40:07 27 4
gpt4 key购买 nike

我正在尝试访问此 answer 之后的内在矩阵.

通过运行下面的指令,我能够得到一个 48 字节的 AnyObject。 ,我进一步将其转换为 CFData .

let camData = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil)

但是,我检查了 CMSampleBuffer.h 中 sampleBuffer 的输出:

/*! @constant   kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix
@abstract Indicates the 3x3 camera intrinsic matrix applied to the current sample buffer.
@discussion Camera intrinsic matrix is a CFData containing a matrix_float3x3, which is column-major.
....
*/
CM_EXPORT const CFStringRef kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix // CFData (matrix_float3x3) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_11_0);

我应该如何从 CFData 访问 matrix_float3x3 中的值?

最佳答案

这应该有效:

  • 使用来自 CFData 的桥接至 NSDataData , 和
  • withUnsafeBytes获取所需指针的方法键入数据字节,
  • .pointee取消引用指针。

例子:

if let camData = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil) as? Data {
let matrix: matrix_float3x3 = camData.withUnsafeBytes { $0.pointee }

// ...

}

指针类型(闭包内的 $0)是从上下文中推断出来的作为UnsafePointer<matrix_float3x3> .

关于ios - swift 3 : How to access the value of matrix_float3x3 in a 48-byte CFData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48565286/

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