anvesh yadav
anvesh yadav

Reputation: 176

Augmented Reality - Distance between marker image and Camera in ArKit?

I want to calculate the distance between any marker image saved in the iOS project which is used for detecting in Augmented Reality and your current position i.e. camera position using ARKIT ?

Upvotes: 1

Views: 1292

Answers (2)

Avitzur
Avitzur

Reputation: 161

If you're using SceneKit and have the SCNNode* that came with

-(void) renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor*)anchor

then

[node convertPosition:{0,0,0} toNode:self.sceneView.pointOfView].z

is distance to camera.

Upvotes: 0

rickster
rickster

Reputation: 126177

As Apple’s documentation and sample code note:

  • A detected image is reported to your app as an ARImageAnchor object.
  • ARImageAnchor is a subclass of ARAnchor.
  • ARAnchor has a transform property, which indicates its position and orientation in 3D space.
  • ARKit also provides you an ARCamera on every frame (or you can get it from the session’s currentFrame).
  • ARCamera also has a transform property, indicating the camera’s position and orientation in 3D space.
  • You can get the translation vector (position) from a 4x4 transform matrix by extracting the last column vector.

That should be enough for you to connect the dots...

Upvotes: 6

Related Questions