gpt4 book ai didi

ios - ARKit ARCamera 变换错误地顺时针旋转 90 度

转载 作者:行者123 更新时间:2023-11-28 23:28:48 26 4
gpt4 key购买 nike

我正在关注 ARKit 上的一个较旧的 WWDC 视频: https://developer.apple.com/videos/play/wwdc2017/602/

在此视频中,他们创建了一个 AR 应用程序,该应用程序监听点击手势并使用场景 View 的快照创建图像平面。

这是视频中的相关代码:

code

但是,当我在我的设备上运行代码时,生成的平面总是相对于我的设备方向顺时针旋转 90 度。例如,当我的设备处于纵向模式时,生成的平面如下所示:

code2

同样,如果我以横向右手方向握住设备,图像平面的“顶部”将指向下方。

ARCamera 转换似乎总是相对于设备方向偏离 90 度,这是有原因的吗?

最佳答案

By default, image captured by iPhone or iPad's camera is encoded in the camera sensor's native landscape orientation. When you make a snapshot (even if your device is in portrait orientation), iOS writes an orientation value of:

CGImagePropertyOrientation.right

in the resulting image file. ARKit app reads this value from the file's metadata and then displays the image applying a 90° ClockWise rotation, so your captured image appears in the intended photographer's orientation.

您需要应用相反的操作——旋转图像 90° CounterClockWise

因此,请阅读 this post 以了解如何使用 CVPixelBuffer 进行制作。

此外,以下扩展方法也可以帮助您:

extension CGImagePropertyOrientation {

init(_ uiOrientation: UIImage.Orientation) {

switch uiOrientation {
case .up: self = .up
case .upMirrored: self = .upMirrored
case .down: self = .down
case .downMirrored: self = .downMirrored
case .left: self = .left
case .leftMirrored: self = .leftMirrored
case .right: self = .right
case .rightMirrored: self = .rightMirrored
@unknown default: fatalError()
}
}
}
extension UIImage.Orientation {

init(_ cgOrientation: UIImage.Orientation) {

switch cgOrientation {
case .up: self = .up
case .upMirrored: self = .upMirrored
case .down: self = .down
case .downMirrored: self = .downMirrored
case .left: self = .left
case .leftMirrored: self = .leftMirrored
case .right: self = .right
case .rightMirrored: self = .rightMirrored
@unknown default: fatalError()
}
}
}

关于ios - ARKit ARCamera 变换错误地顺时针旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57501327/

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