{"id":45,"date":"2018-08-25T00:22:09","date_gmt":"2018-08-25T00:22:09","guid":{"rendered":"https:\/\/www.xlsoft.com\/doc\/kudan\/?page_id=45"},"modified":"2019-07-26T17:37:50","modified_gmt":"2019-07-26T17:37:50","slug":"marker-basics","status":"publish","type":"page","link":"https:\/\/www.xlsoft.com\/doc\/kudan\/marker-basics\/","title":{"rendered":"iOS Marker Basics"},"content":{"rendered":"<p>This tutorial goes over the basics of creating a marker and setting up the image tracker.<\/p>\n<div>\n<section class=\"content-body\">\n<div class=\"magic-block-textarea\">\n<p>This tutorial uses assets for the marker and image node. You can download these assets\u00a0<a href=\"https:\/\/www.xlsoft.com\/doc\/kudan\/files\/2019\/04\/Kudan-Marker-Basics-Assets.zip\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>In this asset bundle you should find:<\/p>\n<ul>\n<li>Kudan Lego Marker &#8211; This is our marker image that will be detected by the tracker.<\/li>\n<li>Kudan Cow &#8211; This is the image that will appear when the marker has been detected.<\/li>\n<\/ul>\n<p>Once you have downloaded the file, unzip it and add the assets to your Xcode project.<\/p>\n<\/div>\n<div class=\"magic-block-api-header\">\n<div id=\"section-set-up-the-image-trackable\" class=\"anchor waypoint\"><\/div>\n<h2 class=\"header-scroll is-api-header\">Set up the Image Trackable<\/h2>\n<\/div>\n<div class=\"magic-block-textarea\">\n<p>To create an Image Trackable, you are first going to need an image to track. A marker can be any image natively supported by iOS. Commonly used formats are\u00a0<code>.jpg<\/code>\u00a0and\u00a0<code>.png<\/code>.<\/p>\n<\/div>\n<div class=\"su-note\"  style=\"border-color:#c9d3d8;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e3edf2;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\">\n<h3 style=\"color: #5bc0de;\"><i class=\"fa fa-info-circle\" title=\"Info\"><\/i>Bad Markers<\/h3>\n<p style=\"color: gray;\">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 <a href=\"https:\/\/www.xlsoft.com\/doc\/kudan\/what-makes-a-good-marker\/\">What Makes a Good Marker?<\/a><\/p>\n<\/div><\/div>\n<div class=\"magic-block-textarea\">\n<p>To setup your image trackable, first create an\u00a0<code>ARImageTrackable<\/code>\u00a0object and initialise it with a UIImage. Then, initialise the\u00a0<code>ARImageTrackerManager<\/code>\u00a0and add the trackable to it. The code to do this looks like the following:<\/p>\n<\/div>\n<div class=\"su-tabs su-tabs-style-default su-tabs-mobile-stack\" data-active=\"1\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-tabs-nav\"><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.m<\/span><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.swift<\/span><\/div><div class=\"su-tabs-panes\"><div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.m\">\n[code lang=&#8221;Java&#8221;]- (void)setupContent<br \/>\n{<br \/>\n  \/\/ Initialise the image trackable.<br \/>\n  ARImageTrackable *imageTrackable = [[ARImageTrackable alloc] initWithImage:[UIImage imageNamed:@&quot;Kudan Lego Marker.jpg&quot;] name:@&quot;Lego Marker&quot;];<\/p>\n<p>  \/\/ Get the single instance of the image tracker manager.<br \/>\n  ARImageTrackerManager *imageTrackerManager = [ARImageTrackerManager getInstance];<br \/>\n  [imageTrackerManager initialise];<\/p>\n<p>  \/\/ Add the image trackable to the image tracker manager.<br \/>\n  [imageTrackerManager addTrackable:imageTrackable];<br \/>\n}[\/code]\n<\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.swift\">\n[code lang=&#8221;Java&#8221;]override func setupContent()<br \/>\n{<br \/>\n\t\/\/ Initialise the image trackable.<br \/>\n\tlet imageTrackable = ARImageTrackable(image: UIImage(named:&quot;Kudan Lego \tMarker.jpg&quot;), name:&quot;Lego Marker&quot;)<\/p>\n<p>\t\/\/ Get the single instance of the image tracker manager.<br \/>\n\tlet imageTrackerManager = ARImageTrackerManager.getInstance()<br \/>\n\timageTrackerManager?.initialise()<\/p>\n<p>\t\/\/ Add the image trackable to the image tracker manager.<br \/>\n\timageTrackerManager?.addTrackable(imageTrackable)<br \/>\n}[\/code]\n<\/div><\/div><\/div>\n<h2 class=\"header-scroll is-api-header\">Add an ARImageNode to the trackable<\/h2>\n<p>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.<\/p>\n<p>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\u00a0<code>ARImageNode<\/code>, which is tailored towards displaying 2D images.<\/p>\n<div class=\"su-note\"  style=\"border-color:#c9d3d8;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e3edf2;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\">\n<h3 style=\"color: #5bc0de;\"><i class=\"fa fa-info-circle\" title=\"Info\"><\/i>Add content on the background thread<\/h3>\n<p style=\"color: gray;\">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.<\/p>\n<\/div><\/div>\n<div class=\"su-note\"  style=\"border-color:#c9d3d8;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e3edf2;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;\">\n<h3 style=\"color: #5bc0de;\"><i class=\"fa fa-info-circle\" title=\"Info\"><\/i>Types of ARNode<\/h3>\n<p style=\"color: gray;\">For more information on the different types of ARNode, please refer to our API Reference or our\u00a0<a class=\"doc-link\" href=\"https:\/\/www.xlsoft.com\/doc\/kudan\/nodes\/\">Nodes<\/a> page.<\/p>\n<\/div><\/div>\n<div class=\"magic-block-textarea\">\n<p>To set up an\u00a0<code>ARImageNode<\/code>\u00a0and add it to our image trackable, add the following code to the end of the\u00a0<code>setupContent<\/code>\u00a0method:<\/p>\n<\/div>\n<div class=\"su-tabs su-tabs-style-default su-tabs-mobile-stack\" data-active=\"1\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-tabs-nav\"><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.m<\/span><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.swift<\/span><\/div><div class=\"su-tabs-panes\"><div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.m\">\n[code lang=&#8221;Java&#8221;]\/\/ Initialise the image node with our image.<br \/>\n\/\/ We don&#8217;t include the file extension for this image because it&#8217;s a PNG.<br \/>\nARImageNode *imageNode = [[ARImageNode alloc] initWithBundledFile:@&quot;Kudan Cow&quot;];<\/p>\n<p>\/\/ Add the image node to our image trackable.<br \/>\n[imageTrackable.world addChild:imageNode];[\/code]\n<\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.swift\">\n[code lang=&#8221;Java&#8221;]\/\/ Initialise the image node with our image.<br \/>\n\/\/ We don&#8217;t include the file extension for this image because it&#8217;s a PNG.<br \/>\nlet imageNode = ARImageNode(image: UIImage(named: &quot;Kudan Cow&quot;))<\/p>\n<p>\/\/ Add the image node to our image trackable.<br \/>\nimageTrackable?.world.addChild(imageNode)[\/code]\n<\/div><\/div><\/div>\n<div class=\"magic-block-textarea\">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. It looks good, but it&#8217;s a little on the small side.<\/div>\n<div class=\"magic-block-api-header\">\n<p>&nbsp;<\/p>\n<div id=\"section-scale-the-image-node\" class=\"anchor waypoint\"><\/div>\n<h2 class=\"header-scroll is-api-header\">Scale the Image Node<\/h2>\n<\/div>\n<div class=\"magic-block-textarea\">Sometimes, if your content isn\u2019t the same size as your marker, you may wish to scale your node. Provided your content is the same aspect ratio as your trackable, you can divide one width from the other to get the correct scale. This value can then be used to scale your nodes.In this case, we will be scaling our image so that it has the same width as our marker. To do this, add the following code to the end of the\u00a0<code>setupContent<\/code>\u00a0method:<\/p>\n<\/div>\n<div class=\"su-tabs su-tabs-style-default su-tabs-mobile-stack\" data-active=\"1\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-tabs-nav\"><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.m<\/span><span class=\"\" data-url=\"\" data-target=\"blank\" tabindex=\"0\" role=\"button\">ViewController.swift<\/span><\/div><div class=\"su-tabs-panes\"><div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.m\">\n[code lang=&#8221;Java&#8221;]\/\/ Find the scale ratio.<br \/>\nfloat scaleRatio = (float)imageTrackable.width \/ imageNode.texture.width;<\/p>\n<p>\/\/ Apply it to your ARNode.<br \/>\n[imageNode scaleByUniform:scaleRatio];[\/code]\n<\/div>\n<div class=\"su-tabs-pane su-u-clearfix su-u-trim\" data-title=\"ViewController.swift\">\n[code lang=&#8221;Java&#8221;]\/\/ Find the scale ratio.<br \/>\nlet scaleRatio = Float(imageTrackable!.width)\/Float(imageNode!.texture.width)<\/p>\n<p>\/\/ Apply it to your ARNode.<br \/>\nimageNode?.scale(byUniform: scaleRatio)[\/code]\n<\/div><\/div><\/div>\n<div class=\"magic-block-textarea\">\n<p>This will scale all three of the image node&#8217;s axes by the same value. It&#8217;s also possible to scale each axis independently, but you&#8217;ll rarely have to do this.<\/p>\n<p>Run the app again, and you should see that the Kudan Cow has increased a bit in size to better fit the marker. This will also work with other types of content, including videos and 3D models.<\/p>\n<\/div>\n<hr \/>\n<div class=\"nextSteps\">\n<h3>What&#8217;s Next<\/h3>\n<p>Go through the basics of setting up Kudan&#8217;s ArbiTrack feature for markerless tracking.<\/p>\n<table>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/www.xlsoft.com\/doc\/kudan\/arbitrack-basics\"><i class=\"fa fa-chevron-right\"><\/i>ArbiTrack Basics<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0here. In this asset bundle you should find: Kudan Lego Marker &#8211; This is our marker image that will be detected by the tracker. Kudan &#8230; <a title=\"iOS Marker Basics\" class=\"read-more\" href=\"https:\/\/www.xlsoft.com\/doc\/kudan\/marker-basics\/\">Read more<span class=\"screen-reader-text\">iOS Marker Basics<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"bekko_page_header":""},"_links":{"self":[{"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/pages\/45"}],"collection":[{"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":90,"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/pages\/45\/revisions"}],"predecessor-version":[{"id":2276,"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/pages\/45\/revisions\/2276"}],"wp:attachment":[{"href":"https:\/\/www.xlsoft.com\/doc\/kudan\/wp-json\/wp\/v2\/media?parent=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}