swift - displayTransform 调用后图像方向错误

标签 swift augmented-reality arkit ciimage cvpixelbuffer

我正在尝试使用以下方法从当前 ARFrame 获取图像:

if let imageBuffer = sceneView.session.currentFrame?.capturedImage {
    let orientation = UIApplication.shared.statusBarOrientation
    let viewportSize = sceneView.bounds.size
    let transformation = sceneView.session.currentFrame?.displayTransform(for: orientation, viewportSize: viewportSize)

    let ciImage = CIImage(cvPixelBuffer: imageBuffer).transformed(by: transformation)
}    



对于风景,效果很好。对于人像,我以错误的角度获取图像(旋转 180 度)。知道为什么吗?

Output:

output

Expected:

expected

最佳答案

At first I should say that it definitely is an unpleasant bug.

问题是,当您转换 Portrait图像,ARFrame 包含的内容,对于 CIImage 或 CGImage,它失去了方向并将其逆时针旋转 180 度。此问题仅影响 Portrait图片。 Landscape完全不受影响。

发生这种情况是因为 Portrait图像在转换阶段没有关于其方向的信息,因此,即使转换为 CIImage 或 CGImage,纵向图像仍保持纵向模式。

要解决此问题,您应该比较“标准”景观的 width/height带有“非标准”肖像的 width/height ,如果这些值不同,则将图像旋转到 CW 180 度(或应用方向案例 .portraitUpsideDown)。

希望这对您有所帮助。

关于swift - displayTransform 调用后图像方向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54903747/

相关文章:

包含闭包的 Swift 数组

ios - 你如何检查 SwiftUI 是否处于预览模式?

ios - 快速更改 UIContainerView 的高度和宽度

ios - iPhone 上的增强现实 + 实时图像识别

android - 具有光学字符识别的增强现实

opencv - 如何将使用 EPnP 计算的相机位姿变换应用于 VTK 相机?

swift - 如何在 Swift 中制作日期格式化程序以仅显示日期的年份部分?

ios - 如何在 Scenekit/ARKit 中使用 ShadowMode=deferred 移除灯光?

ios - 如何更改 SCNShape 的大小?

ios - SCNNode 查看当前位置并始终相对向上