ARKit 2.0 Image Recognition and Tracking

Mohammad Azam
2 min readJun 6, 2018

--

At WWDC 2018 Apple announced lots of new features in ARKit 2.0 framework. One of those features was improved Image Detection and Tracking. Image Detection was introduced in ARKit 1.5 but now with tracking you can create some really amazing AR apps. Check out the demo below:

Prerequisites

Before we dive into the implementation details let’s take a look at the prerequisites of the course.

  • Xcode 10 (beta or above)
  • iOS 12 (beta or above)
  • Physical iPhone 6S or above

Now, let’s dive into code.

Implementing Image Detection and Tracking

Reference images can be added dynamically or through “AR Resources”. We are going to use the AR Resources approach since, it is much simpler. Click on “Assets.xcassets” and add a new “AR Resources” group. Drag and drop an image which will act as a reference image. Make sure to give dimensions to the image.

Next, we need to create an ARImageTrackingConfiguration instance which allows to track the reference images in the real world.

After instantiating the ARImageTrackingConfiguration instance, we assign the reference images to the trackingImages property. If you are tracking multiple images then you can also use maximumNumberOfTrackedImages property of the configuration object.

Now, when the reference image is found in the real world, it will trigger renderer function as below:

The renderer function will get the phone model out of the scene file and then adds it to the anchor found. If you try to move the reference image around you will notice that the virtual model also moves with it.

That’s it! happy coding!

[Download Sample]

If you are interested in learning more about ARKit then check out my course “Mastering ARKit for iOS”.

More where this came from

This story is published in Noteworthy, where thousands come every day to learn about the people & ideas shaping the products we love.

Follow our publication to see more product & design stories featured by the Journal team.

--

--

Mohammad Azam

Lead instructor at a coding bootcamp. Top iOS mobile instructor on Udemy. Author of multiple books and international speaker. azamsharp.school