Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ARKit ARCamera变换不正确地顺时针旋转90度_Ios_Swift_Scenekit_Augmented Reality_Arkit - Fatal编程技术网

Ios ARKit ARCamera变换不正确地顺时针旋转90度

Ios ARKit ARCamera变换不正确地顺时针旋转90度,ios,swift,scenekit,augmented-reality,arkit,Ios,Swift,Scenekit,Augmented Reality,Arkit,下面是ARKit上的一段WWDC旧视频: 在这段视频中,他们创建了一个AR应用程序,该应用程序可以监听点击手势,并使用场景视图的快照创建图像平面 以下是视频中的相关代码: 但是,当我在设备上运行代码时,生成的平面始终相对于设备的方向顺时针旋转90度。 例如,在纵向模式下握住设备时,生成的平面如下所示: 类似地,如果我将设备保持在横向正确方向,则图像平面的“顶部”将指向下方 ARCamera变换相对于设备方向似乎总是关闭90度,这有什么原因吗 默认情况下,iPhone或iPad摄像头捕获的图

下面是ARKit上的一段WWDC旧视频:

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

以下是视频中的相关代码:

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

类似地,如果我将设备保持在横向正确方向,则图像平面的“顶部”将指向下方

ARCamera变换相对于设备方向似乎总是关闭90度,这有什么原因吗

默认情况下,iPhone或iPad摄像头捕获的图像以摄像头传感器的本地横向方向编码。当您制作快照时(即使您的设备处于纵向),iOS会写入一个方向值:

在生成的图像文件中。ARKit应用程序从文件的元数据中读取该值,然后应用
90°顺时针旋转来显示图像,这样您拍摄的图像就会显示在预期摄影师的方向上

您需要应用相反的操作–将图像逆时针旋转90°

因此,请阅读了解如何使用
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()
        }
    }
}
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()
        }
    }
}