Kudan

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Marker Basics

This tutorial goes over the basics of creating a marker and setting up the image tracker.

This tutorial uses assets for the marker and image node. You can download these assets here.

In this asset bundle you should find:

  • Kudan Lego Marker - This is our marker image that will be detected by the tracker.
  • Kudan Cow - This is the image that will appear when the marker has been detected.

Once you have downloaded the file, unzip it and add the assets to your Android Studio project.

Set up the Image Trackable

To create an Image Trackable, you are first going to need an image to track. A marker can be any image natively supported by Android. Commonly used formats are .jpg and .png.

Bad Markers

If your content appears to twitch or shake, or does not appear at all, a common cause is that the marker being used is bad for tracking. For more information, please read our page on What Makes a Good Marker?

To setup your image trackable, first create an ARImageTrackable object and initialise it with a name. Then, load your image into the trackable with the trackable's loadFromAsset method. Next, initialise the ARImageTracker and add the trackable to it. The code to do this looks like the following:

@Override
public void setup() 
{
  super.setup();
  
  // Initialise the image trackable and load the image.
  ARImageTrackable imageTrackable = new ARImageTrackable("Lego Marker");
  imageTrackable.loadFromAsset("Kudan Lego Marker.jpg");
        
	// Get the single instance of the image tracker.
	ARImageTracker imageTracker = ARImageTracker.getInstance();
    
  //Add the image trackable to the image tracker.
  imageTracker.addTrackable(imageTrackable);
}

Add an ARImageNode to the trackable

If you run the app as it is now, the marker will detect and track, but how will we know? We need some feedback, and the easiest way to do that is to add a node to the trackable.

There are various types of node, each of which is designed to work with a specific type of content. For this tutorial, we will be using an ARImageNode, which is tailored towards displaying 2D images.

Add content on the background thread

When adding any AR content to your application, you should consider adding it on the background thread. This will help prevent the camera feed from stalling.

Types of ARNode

For more information on the different types of ARNode, please refer to our API Reference or our Nodes page.

To set up an ARImageNode and add it to our image trackable, add the following code to the end of the setupContent method:

// Initialise the image node with our image
ARImageNode imageNode = new ARImageNode("Kudan Cow.png");

// Add the image node as a child of the trackable's world
imageTrackable.getWorld().addChild(imageNode);

Now, if you build and run the app again, the Kudan Cow will appear on the Lego Marker when the marker gets detected by the tracker. Looks good!

Marker Basics

This tutorial goes over the basics of creating a marker and setting up the image tracker.