我正在尝试从当前获取图像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: https://i.stack.imgur.com/1cG5P.png
预期的: https://i.stack.imgur.com/aflGN.png
首先我应该说这绝对是一个令人不快的错误.
问题是,当你转换一个Portrait
ARFrame 包含的图像,对于 CIImage 或 CGImage,它会失去其方向并将其逆时针旋转 180 度。此问题仅影响Portrait
图片。Landscape
完全不受影响。
发生这种情况是因为Portrait
图像在转换阶段没有有关其方向的信息,因此,即使转换为 CIImage 或 CGImage,纵向图像仍保持纵向模式。
要解决这个问题,你应该比较“标准”景观 width
/height
with a “非标准”肖像 width
/height
,如果这些值不同,则旋转图像以顺时针 180 度(或应用定向案例.portraitUpsideDown https://developer.apple.com/documentation/uikit/uiinterfaceorientation/portraitupsidedown).
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)