Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Camera Translation from ARCamera

I am experimenting with Apple's ARKit and have a question regarding camera transformations. Which of the values in the transform matrix represent how far the user has travelled from the point of origin? Calling

self.sceneView.session.currentFrame!.camera.transform.columns.0.x 

does not seem to yield the correct X translation.

Additionally, what would be the correct location for Y and Z?

like image 475
Alex Wulff Avatar asked Jun 29 '17 20:06

Alex Wulff


People also ask

How do I use the Translate feature in the camera app?

Using the translate feature is as simple as opening up the Camera app and pointing it at the text you want to translate. Tap on the text selection button in the app to select the detected text, and then choose the translate option to get an instant translation.

How do I use the point camera to translate?

Point the app camera to any text on photos or documents and tap the button to auto-translate to the target language. The camera can scan large documents in various languages and convert to other languages. The scanning and translating process are done by machine learning trained with big data.

How do I get the camera information from an arframe?

You get camera information from the camera property of each ARFrame ARKit delivers. The general quality of position tracking available when the camera captured a frame. Values for position tracking quality, with possible causes when tracking quality is limited. The position and orientation of the camera in world coordinate space.

Can the camera scan large documents and convert to other languages?

The camera can scan large documents in various languages and convert to other languages. The scanning and translating process are done by machine learning trained with big data. Camera Translator - best dictionary app for language learner & traveler: - Supports more than 100 languages. - Recognizes text documents with lots of formats.


2 Answers

The last column of a 4x4 transform matrix -- matrix.columns.3 in this case -- is the translation vector. See this old answer for some background on 4x4 transform matrices and how they work.

like image 172
rickster Avatar answered Sep 19 '22 03:09

rickster


The simplest way to get ARCamera's translation is the following:

func getCameraTransform(for sceneView: ARSCNView) -> MDLTransform {
    guard let transform = sceneView.session.currentFrame?.camera.transform else { return }
    return MDLTransform(matrix: transform)
}

let position = SCNVector3(cameraTransform.translation.x, 
                          cameraTransform.translation.y, 
                          cameraTransform.translation.z)
like image 35
Andy Jazz Avatar answered Sep 19 '22 03:09

Andy Jazz