OPENCV & C++ TUTORIALS - 125 | createTemplateMatching() | OpenCV Template matching with Cuda

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome back in this video we are going to learn about create template matching function which is included in the Cuda module of open CV and I'm not going to get into the detail of the template matching because we already learned this in another video in the previous videos so I'm just going to focus how to use this in the uh Cuda module of open CV how to use this function so the uh usage is very easy you are just giving the source type uh which is going to most probably is going to be the same with the template type and also we are going to uh give the me there are couple of methods we are going to see the results with the different methods in the code part also we are going to can be as a as a choice we can also give the size which is the uh Target size it SC be okay um we can also there are some uh couple of in here uh uh explanation of the input parameters for example the input can only take uh 32 flat or the 8 bit unsigned Char images from one to four Channel you can give uh as a uh as a parameter and also you can specify the way to compare the image for there are several ways there are some mathematical in the behind but we can check the details in the code part okay for this actually you are going to need uh two kind of um images first of all is going to be the source image and second is going to be the template image so you are going to search the template image inside the source image so we can create I thought in this video because we I already have a Lena image but for this maybe I can just screenshot in here and I'm going to choose couple of place and I'm going I'm just going to search this area inside this image just for an example also at the beginning I can tell you from my experiences this template matching is not really good function I can say because uh to be able to use this function you you are needed to be searching totally the same part of same crop image inside image not totally same but should be very similar to the Target image this area should be included in the Target image very clearly so this is important if you want to use this function you should be uh aware of okay I'm searching this area but uh you should know at the beginning this area should be uh very similarly included in the Target image otherwise it's not going to work properly okay we can write template and uh I can copy the pet into the here uh by the way I'm just for the gray scale but you can also try with the different channels RGB or even included Alpha Channel okay um first of all we need to create our GPU met types for the source and the template image as we always did in the previous videos also the source image um Source GPU met Source GPU maybe we can write and we need to upload the source image into the GPU mat also similarly we need to do for the template image so template GPU and template image okay so this is done um we already uploaded to the GPU site and after that all we need to do is just uh creating the function accordingly okay just I need to call in here okay but I think I need to Define here accordingly I think this is going to be needed Cuda template matching okay so um we can template template mature maybe okay template meure and is equal to all I need to do is just calling here create create template matching and the source the type input type is going to be same like the this source source image type so I can write type okay Source image that type okay and the second is going to be the method for the beginning maybe um you can start with this which is the first one I think this one okay this is not like this so maybe the name is different let's just try to get the name what was the or just this how to get this this tmq what is the name in the tmq diff maybe we can direct get okay TM sqd let's go to the definitions okay this is the first one maybe we can start with this nored one then we can try the others and the we can make the third parameter empty so it's not really important for our example um this is done we already created our template matching object and after that all we need to do is just calling the match function and we can go into the here match function parameters is defined in here clearly so we are just going to give our uh input and the I mean the template and Source image and it's going to give that into inside the result so we are going to analyze the result and we are going to get the outputs okay first of all we need to give the source image and the second is the template image which is written in here also uh but sorry this is going to be of course in the GPU level and after that we are going to give the template GPU and the third one is going to be our result which is going to be the um we can we need to give similarly to this GPU mat so this is going to be the result in the GPU level and we are going to get it and I think all is done after that uh we need to download the result into a mat type which is going to be the mat uh mat result maybe we can say okay then just we need to call result GPU do download into the mat result so we are downloading the uh result into a m level CPU level I mean so we can use this uh at the output after this uh we get the result in here we can call a function which is mean Max log because this included many information inside so by calling mean Max loog we are going to get the best point which is matching with the template so after that we can easily use that okay math result the second parameter minimum we don't need maximum value we don't need and the after this minimum location I only need the maximum location and I need to define the point and this going to give me the starting point of the template matching inside the this Source image so Point uh Max location maybe we can call okay Max location point and uh I need to give in here as a reference okay and I think all is done so now I can draw a rectangle inside the source image so I can see if uh it's F it's found successfully or not so I need to call a rectangle rectangle okay uh and we can use this one I think the I want it to draw in the source image um rectangle we need to Define okay after that just parentheses maybe 01 okay maybe we can use this one or just the 0.1 and the point two uh maybe this one better the point x is going to be the or okay just giving the point one and also the other point which is going to be the uh other point of the end point of the rectangle just calling point and here uh since this is the starting point which is left and the upper point of the rectangle and I'm calling the um x-axis of that one and plus uh width of the template image because it should be in the same width which is is is which is going to be search in the uh Source image so I can give the width uh sorry not WID of course columns and is the x of the point x axis of the point and similarly I need for the Y AIS and this is going to be rows and all is done what is next is needed why it's not suggesting me I think just going but why is not suggesting me because I'm not remembering the parameters okay rectangle scalar thickness okay now we can continue rectangle scalar since this is a gray scale we can give zero which is going to be the black let's see the the thickness is four and all is done so I think this is going to be working fine what's wrong um something wrong in here okay okay because I didn't put parentheses okay now I think all is done I believe so okay we are able to draw the rectangle if the template image exist in the source image after that all I need to do is calling imow um and then um we can call in the window and after that I can call the result which is going to be our source image we are going to see the rectangle inside this and calling the weight key um okay zero and done uh let me check what we are doing basically we are calling the this object we are creating this one this one we are going to try the different options of this in numerator and we are matching The Source input template GP we already uploaded to GPU side and we are expecting to see the result in this one but of course since also this is GPU M we are downloading again into the mat so in CPU level now and after that uh we are getting the maximum location maximum probability location which is template which is starting as a rectangle of course then after that we are we are we want to draw a rectangle around so we are this is the starting point of course and but after that we need to define the second point of the rectangle we are using the template image width and height in here so we are drawing the rectangle at let's see the result okay uh let me check the cropped area so we basically just cropped here is the same or not it's starting little above ice um I think it's same so it's detected successfully maybe we can uh little Zoom so we are playing in some way because this is also screenshot we are playing with the uh pixel ratio so let's see it's now I'm a uh maybe this is we can call I sorry I okay so now I'm expecting it to uh show me the eye of the L let's see again the result okay for example this one is not successfully defined maybe we can try the different uh options of this one maybe okay this even not enough maybe we can make couple of try also because we zoomed right at the beginning I talk about the problem so this issue we see now for example even this one maybe Already There is five option we almost righted at all but all is not successful so yeah this is the issue at the beginning I talk for example this is little finding but of course it's still wrong because I zoomed I little changed the ratio so pixel are um pixels are changed because in here we are directly playing with this area so everything is successfully found but let's me try again I I I think the same I will be successfully found now because let me try we can name I to because we didn't Zoom we didn't do anything yeah you see successfully found in here the issue is this template match is uh very um checking very clearly this pixel to pixel uh analysis so this is that's why this is not really good in many cases uh so I also don't like this function but if you search any area inside an image and this area for example you search this I totally so you you can search and it's going to give you the result you you you can do this function by yourself also by checking pixel to pixel but it's not going to an efficient there's already an efficient function which is this it's giving you uh very faster so you don't need to uh write a very efficient function is already in here for that kind of cases this is good but uh in many cases for example I see in the forums they are trying to search for example this ice but in many kind of different perspectives they trying to search this size of course it's not going to give this is not an AI this is just morphologic operation so uh yeah I just wanted to show how this is working in the ca uh level just that's all yeah see you in the next videos
Info
Channel: Computer Vision Lab
Views: 110
Rating: undefined out of 5
Keywords: opencv, computer vision, python, opencv python tutorial, opencv tutorial, opencv tutorial for beginners, opencv c++ tutorial, createTemplateMatching, cuda template matching, template matching, opencv template matching, template matching in image processing, image processing, computer vision lab, cuda accelarated opencv functions, cuda opencv c++, opencv c++ tutorials, cuda installation
Id: D0sLSRI6czE
Channel Id: undefined
Length: 14min 43sec (883 seconds)
Published: Mon Feb 26 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.