Home > database >  Value of type 'ARFrame' has no member 'viewTrans'
Value of type 'ARFrame' has no member 'viewTrans'

Time:06-01

I can't figure out how to solve this error:

Value of type 'ARFrame' has no member 'viewTrans'

Nothing came up when I tried googling the error. below is a code snippet and I put a comment called //ERROR right above the line that is producing this error.

var viewTrans : CGAffineTransform? = nil


func session(_ session: ARSession, didUpdate frame: ARFrame) {

    let depthData = frame.capturedDepthData
    if depthData != nil {

        self.displayCalibrationData(depthData: (frame.capturedDepthData?.cameraCalibrationData)!, colorData: frame.camera.intrinsics)

        // Render depth data to background texture (not quite as fast as using Metal textures)
        let depthBuffer : CVPixelBuffer = depthData!.depthDataMap
        let colorBuffer : CVPixelBuffer = frame.capturedImage
        // Output scene dimensions
        let frameWidth = sceneView.frame.size.width
        let frameHeight = sceneView.frame.size.height
        let targetSize = CGSize(width: frameWidth, height: frameHeight)
        // ERROR
        self.viewTrans = frame.viewTrans(for: UIInterfaceOrientation.portrait, viewportSize: targetSize)

        renderDepthColorOverlay(depthBuffer: depthBuffer, colorBuffer: colorBuffer, viewTrans: self.viewTrans!, targetSize: targetSize)
    }
}

CodePudding user response:

ARFrame doesn't have any viewTrans method: https://developer.apple.com/documentation/arkit/arframe

Instead you should change this line:

self.viewTrans = frame.viewTrans(for: UIInterfaceOrientation.portrait, viewportSize: targetSize)

To this:

self.viewTrans = frame.displayTransform(for: UIInterfaceOrientation.portrait, viewportSize: targetSize)

displayTransform(for:viewportSize:) Returns an affine transform for converting between normalized image coordinates and a coordinate space appropriate for rendering the camera image onscreen.

See here: https://developer.apple.com/documentation/arkit/arframe/2923543-displaytransform

  • Related