all right in this video you are going to learn how you can set up image recognition on your AR Foundation unity project so let's get started [Music] first you want to make sure that your project is ready for AI deployment that means if you go to the build settings you have your iOS checked here you have imported all the XR things from the package manager and if you don't know what I'm talking about then definitely watch the setting up video I will link it right here and then yeah if you don't have it set up then do it first and then come back to this video to get image recognition working we need to do some sneaky tricks which took me some time to figure out in the moment package manager and in here you want to make sure that yes there at least the version 2.2 point oh because if you just install it like regular installation you will have a different version I think this one exactly the two point zero point two and this one does not support the image recognition yet probably by the time you're watching the video this one will be released already but just make sure that this is the minimum version you have otherwise just take the current version which is in preview because all the stuff is in preview anyway so it doesn't make a big difference but yeah this one is important to get then after you go to the correct version of your package let's go to their session origin and in here we want to add a component which is called the AR tract image manager there we go so this is necessary and in here you see already okay there's a reference library which probably is something like what images you want to track then there's and of it is exactly this and let's just zoom a little bit so then you have a mixed number of moving images so how many images you want to detect at the moment and then yeah attract image prefab this is a prefab we're just getting instantiated when you recognize an image so for this to work we need a X our reference image library which is a scriptable object so let me just create it first so you go right click then create and then all the way down to X are and in here we have the referee image library there we go you can just leave the name like this and there we go by the way if you don't know what a scriptable object this then definitely check out this video over here because it's a general pretty it's not too important but it makes you really professional makes your code really clean and modular so this is something you really really want to know it's not something like specific 4xr development but if you don't know it go watch the video otherwise let's start adding some images to our library and therefore let me actually add something from my desktop just this nice logo over here next try there we go and now we can go to our reference library and then here add images and now we can just drag it in there we go and yeah that's it basically now we can specify our size which is pretty helpful and meters I'm just gonna pull out it something like thirty centimeters that should be okay keep texture runtime means that you can let me just read through if enable the texture will be available in the player otherwise the texture will be null on the player so when you are on you're on your phone you can still access the picture but of course this is gonna blow up your phone and your the size of your application if you have like a bunch of images stored in there so you should only keep it if you really need it obviously I know you hit an image and now we can add a bunch of images this one is now being tracked we can give it a name as well so I'm our City there we go and yeah that's it already let me actually close it and now we need to reference this library of course so let's go back to our a our session origin and then drag it over here and yet now it's getting detected but of course we need to do something like when an image gets detected let's write a little script in a minute but therefore let's go and right click create c-sharp script and then let's just call it something like image recognition example there we go and double click it dip there we go and yeah let's first get rid of those two and let's get started so the first thing we want to do is add a reference of our reference image manager a our thing what hood was called let's see first we need to add our using Unity engine dot AR XR there we go and now we can add our component a our tract image manager of course we need some more references so let's take this one in our foundation and yeah let's just call it just like this there we go and on awake you want to get it so right find object of type and in here we're gonna place our a tract image manager there it is alright so now since we got our component we want to add a public on an enable you want to subscribe to the AR image recognition event so hey our trick image manager dot trick images changed that's the name plus equals and whatever name so that's a method to be were we gonna we are going to right so on image change and now we want to do the same for all when I unsubscribe on disable so on this table so we can just copy this paste it in here and a - there we go and now only we need to write our method over here image changed and there we go now we see we're still getting an error this is because we see that there say a are tracked image change event arcs which we need to put in here so what wasn't him again they are tracked blah blah blah a correct image event arcs this one over here and let's just call it arcs perfect now we are almost ready to go since this is just an example I'm gonna just do some very minimalistic stuff because this is the backbone of how the image recognition works and yeah how you're gonna use it it's like completely up to you there's no little bit doing whatever you wanna do we can call some unity events you can instantiate some objects you can also what I'm going what I'm going to show you is iterate through the list so for each in our X dot edit and here we want to have our tracked image and now you can for example in our debug dot log not logger lock tracked image dot name for example which would be give me a second now it's compiling would be this name over here and then of course based on the name you can do certain actions like if it's this name than this or if it's this name and the size and yeah feel free to do whatever you want to correct image dot and there's lots of stuff over here which it which you can see and let me just go back to name that we go we can actually get rid of those two over here because we don't need them and yeah the last thing we want to talk about is the object which is getting instantiated so where is that again a our session origin which is this one over here therefore let's create an object which we then can use as a prefab to put it in here so we go right click and hierarchy then 3d object cube and then we can move the cube to the front a bit give it a nice rotation and make it a bit smaller there we go that looks fine now we can take this cube from the hierarchy and put it in here to create a prefab get rid of it over here and then we can edit in our correct image prefab the region are we safe and now if we are instantiating no no and if we are detecting our image which we have in our library over here then we are instantiating this cube over here then let's make a build and see how it works so we go to file and if you don't know the build settings then the first video of the series or the second depending on if you are working on Android or on iOS first we have to switch to it I was actually there we go and then yeah actually I see you in a minute when it's done loading to them build it to the platform there we go now we can build image right coke there we go save so here we can see our image recognition working in action let me actually open the image and we see our cube immediately instantiates and now if i move the cube image the cube moves as well let me actually zoom in so we see our image there we go and of course you don't have to just put in cube over there it's a bit basic prefab you can put in there anything you can animate any objects you can do some nice animations you can add sounds you can do some functionalities you can open scenes like you're free to do whatever you want to so this is it already for this video if you liked the video then please leave a like and subscribe and if you have any questions or any video suggestions then leave them in the bottom section below otherwise I see you in the next one