Image Processing Tutorial Using Python | Python OpenCV Tutorial | Python Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi all this is junaid yaw from idioca and i welcome you all to this session where we'll be talking about image processing using python so without any further ado let me quickly walk you through today's agenda we'll start this session by understanding what exactly is image processing and why do we need it moving ahead i'll be speaking about how python can be used for computer vision finally we'll end this session by walking through some of the fundamental concepts that revolve around computer vision and then we shall see how we can implement it by building an application that recognizes handwritten characters before we begin do consider subscribing to our youtube channel and hit the bell icon to stay updated on training technologies and also if you're looking for online training certification in python check out the link given in the description box below alright to start off now what exactly is image processing right well image processing is a method to perform some operation on an image this is done in order to get an enhanced image or to enhance some useful information from it well you can say this is a type of signal processing in which input is actually an image and output can also be an image or a characteristics or a feature that is associated with that particular image but why do we need image processing right well we all know nowadays image processing is among the rapidly growing technologies it forms a core research area within the engineering and computer science discipline you see image processing is used in various fields as you can see here we can use image processing to track human behavior and their positions this can further be used to develop games or any kind of security task the another popular use case of image processing is driverless cars we all are the witness to this you see driverless cars are one of the most coolest piece of technology that exists today and the top players when it comes to driverless cars are like tesla audi mercedes and many more moving on to the last but not least application that is implementing image processing in medical images you see we can use this x-ray ct scan or mri to find abnormalities you see if a person has a kind of a fracture or a cancer that is being detected in using an mri we can actually compare that particular image with respect to the other set of image which does not have or which are totally normal and then based on certain criterias and by applying that to a deep learning model we can figure out whether there is any abnormalities that are present there but you see we cannot use the output or whatever the opinion given out by a machine learning algorithm this is always treated as a third opinion or something that we can show it to a patient that so and so plays has so and so issues all right so now that we know the motivation behind image processing i'm sure now you might be wondering how can i work with image processing right well you see we have various number of programming languages and frameworks to work with but one of the popular approach is by using python you see python has many built-in libraries and tools with which we can not only perform actions on these images like thresholding augmentation or whatever it is but we can also process the images using deep learning or machining algorithms to perform classification operations some of the popular frameworks or libraries here are opencv pytorch then we have tensorflow numpy and many more all right now that we have a brief intuition about image processing let's see some of the fundamental concepts that revolves around this one of the most fundamental concepts in image processing is image filters you see in image processing filters are mainly used to suppress either the high frequencies in the image that is by smoothing an image or by lowering the frequency that is by enhancing or detecting the edges in that particular image an image can be filtered either by using a frequency domain or in a spatial domain speaking about frequency domain it involves transforming that particular image into a frequency domain multiply that frequency with a frequency filter and then again once that's done re-transforming the result into a spatial domain you see spatial domain is nothing but a matrix the other way to filter our image is by using a kernel kernel or it can also be referred to as a filter can be used to extract any information from this some of the popular filters that are there is mean filter then we have mode filter maximum filter minimum filter gaussian filters and many more the way this works is that you know we have a image which is present in a special domain and this particular kernel just moves over it and this is what is happening here as you can see here we have our image okay so this particular thing is our image and this is what we said as a kernel okay we can say a kernel or a filter and this is basically here what we're using is you know a filter and every time this filter goes through all of these points of the special domain you can see here it gives us certain values so this is how a filtering works all right so then in the next component if we move ahead we have something called as padding okay so as i have mentioned uh we will be using you know we will be using a filter right so let me quickly show you that so this thing over here is a filter and this is our image but as this filter moves through this image that is across this three cross three grid you know most of the time what happens is you know our image gets cropped and when an image gets cropped that is this particular pixels these get cropped and when an image gets cropped what happened is most of the features are lost like what is what if there is an important feature which is present at this edge right so this would actually crop the image so in order to prevent that we'll add some extra layer of pixels with this what happens is you know this all of these external layers will be included in our final transformation all right so this is exactly why we use padding basically we use padding in order to remove or in order to reduce the loss of information from our image moving ahead to the next concept that is thresholding you see thresholding is a type of image segmentation what happens over here is like when i say image segmentation as the name suggests here segmenting means basically to separate right so here we have an image okay and this is basically it can be a colored image or an rgb image and then you all know that images or the images is basically a pixel value so they are the grid of pixels and the pixel value of an image can range from 0 to 255 0 typically means it is a black image and 255 means it is a white pixel so what we do in image thresholding is that we set a particular threshold value you say you know something like we have like somewhere midway around right we come down and we set a threshold value and whatever value that lies below this threshold we say this is uh like to replace that pixel with either one or zero or that is nothing but either it can be a black or white and whatever the value which is there on the other side will take the alternate value here and so what happens in the resulting thing is we have a blob which is performed here all right so as you can see here we have over here we have a man who is taking a like he's trying to record something over here now once we are done performing thresholding you can see the image has been converted to now black and white so with this what happens is it becomes easier to extract noise and also to uh scan for any abnormalities moving ahead to the next topic that is connected components now that we know what does this image thresholding does right so it's basically i know like either the value can be one or zero so now what happens is we have to process our image right so this particular part or this particular image over here is nothing but thresholded image so here whatever the values were there has been converted to either ones or zeros but now this is still of no use for us so this is where the connected components come in so whenever there is the continuous structure of pixels right like as you can see here this guy's hand this is one continuous row of pixels then we have you can see the other hand but there is a small white pixel area which is present here right so if there is a small bridge or there is a small gap here that means those two are two different components that's why when i perform this connected components you can see here this right arm of this guy and a laptop are considered as one because there is no pixel gap between them with this what happens is you know we can say we can perform analysis over here we can say this this is the guy's head and then we have earphones and then mostly we can we can whatever this image whatever this output we have we can mask it on an original image to get a better understanding of what are the things we are trying to detect and we can also perform various operations like such as building a bounding box we can get this particular value here and this will just create a bounding box around this and like if let me just change the pen color here okay if i take up this green so this particular thing will create a bounding box by taking the maximum and minimum value of this coordinates and then we can detect this particular part here so this is exactly why we perform image thresholding and then we see what are the various continuity in the pixels that we have so that we can see various different dimensions in an image all right so now that we have a basic understanding of what exactly is image processing let's now move ahead and let me show you how we can implement whatever we have learned into a form of an application all right so for this let me quickly move to my code editor here and the code editor that i would be using is visual studio code all right so let me quickly set our directory here all right so now that we are here what i'm going to do is we're going to perform uh this operation in two stages so let me quickly take up this let me go to my paint so let me tell you what i'm doing here exactly okay so first thing is we have to create a model so what this model does is this model will take in multiple images okay this model will have multiple images and we'll train this model on mnist data so amnesty's data is basically a set of handwritten digits and this model uh this would be basically on a deep learning model that we're gonna create on our own and the way this works is once we train this model whatever input image i provide which the size would be 28 comma 28 it will give me a correct prediction what that image exactly is doing okay this is stage one and the second stage is we have to whatever model we have created we will create dot h5 file for this so that we can use this in our application now what happens in our application is so let me show you what we'll be doing here so we'll create a board something like this okay and inside this board anytime like you take up any hand written image and you press nine what happens is we will get a bounding box which will detect this particular number that is nine and give me an output over here all right and if i write eight it will just detect this and give me a number it and all of this will be happening in real time okay so this sounds pretty interesting so let us now quickly start working on this so first off we would be needing a jupyter notebook right to train our model so what i'm gonna do is in this folder i have couple of images here this images is nothing but uh mnist image so as you can see here this is a small image it's a seven and then if i put like five okay so this image represents three so this is basically a small data set which i have done and now inside this we'll train a model so let's quickly get that done so to open a jupyter notebook here we just need to press ctrl alt p all right and now we just hit that and now finally we'll save this all right so now we are supposed to train this particular model right so what i'm gonna do here is we'll first try saving this up so i'll save this inside this model development and i'll just give a name here as model development and we'll save this all right and now all right guys so now that we are here at our jupiter notebook first off we have to install couple of dependencies right so in order to install i don't have to actually go back to my anaconda command prompt and type so we have the simple shortcut what we can do is we can put an exclamatory mark and type pip install keras okay and then we can also do similarly for pip install sql and let's execute this all right guys so as you can see here we have successfully installed keras in our jupyter notebook uh this would usually take time depending upon your internet speed all right so let me quickly import keras now so we have from keras dot data set import mnist data right and then a couple more things that we i would be needing is like numpy import numpy as np and then at the same time we'll also use matplotlib import matlab dot pipelot as plt all right so the reason why i was having this issue is because i was choosing some other kernel so let me re-execute this now uh it should definitely work right all right so meanwhile that thing loads what i'm going to do here is we have this we if you have to load our data on our mnist from nist we have data is equal to we call this class mnist dot load data so let's wait for this and now what this returns us is a train and test right so if i can see the documentation here so you can see here this returns as the labels okay so it gives us x test white test xtrain and white ring so let me quickly copy this and paste it over here and now once i execute this by shift enter you will see that we like if i put here x strain that is maybe i'm supposed to remove this up over here and change this from lowercase to uppercase right just the x all right so let me just put back the braces here and execute this so now uh let's see how our extend would look like so x strain dot shape so you can see we have 60 000 images uh whose size is 28 comma 28 now let's see how this images should look like so in order to see the image what i will do is we can use plt dot show right so plt dot i am show and now all you need to do is pass my value here so it will be x strain we obviously need the zeroth value right so let me just put plt dot show okay so as you can see we have a number five now now you might be wondering where's the label data right so let me also give you the label that is present in white rain so if i put title here so what i can do is y train of zero so as you can see this is five and now similarly if i put some another value let's say 300 some random value you will see it's giving me ah it's labeled correctly and now if you're thinking that this is a color image it's wrong it's not colored image the reason why we are getting this is because matplotlib is trying to convert this so if you want to prevent this what you can do is see map we can just ascend this to gray so now our image will be in grayscale all right so now that we know how our data is let's now create a model so what i'm going to do is i'll just give a comment here creating model okay so in order to create model if you know a bit of how deep learning works here we'll be using something called as keras framework all right and the way this works is we'll be having multiple layers and each of these layers will have you know a convolution layer to take up extra features if you have to reduce the dimensions we'll be then using filters for this so let's now see how we can do that from keras dot layers import dense layer all right and then we have convolution layer so this is basically a filter so contour d all right and then we have average pool okay and the actual name for this is average pool 2d and then we have to flatten it so flatten layer all right so this is what we have and apart from that we also need couple more stuff that is sequential model so from keras dot models import sequential mode okay and now what i'm going to do is we'll get on to create a model so first off i'll give here variable name so model so this should be equal to sequential all right now we need to add a couple more components to this model so we'll have model dot add now we'll call our convolution 2d all right and now we have to give number of filters so as this is a small image what i'm going to do is i'll just give a few filters that is 4 then the kernel size that is the size of a filter usually this kernel size first off it is given in the odd numbers and we usually use kernel size like three cross three or five cross five totally depends upon what you're using it for so here i'll be using 5 cross 5 and as is the first layer right we'll be we have to specify the input shape so input shape so the input shape here is going to be 28 comma 28 comma 28 and one that's because it's not an rgb image and finally we have to give an activation function we use activation function in order to enhance the non-linearity okay and the one that i'm going to use here is reload all right so looks cool so let me execute this okay i think i've done a small typo here so okay i'm supposed to just change it to e and again a typo here so now what i'm gonna do here is let me zoom out a bit we'll create similar such layers okay so as this is just a convolution 2d after this we'll have something called as average pool this is done usually to decrease your the dimensions okay so model dot add so we'll add average pool and now we'll just have to provide a pool size so we'll just put here pool size and this is usually three cross three as or five cross five but as is a small image we'll just give two cross two all right so this is done we are done with one particular layer now after this we'll again pass a convolution layer so i'll just copy this over here and paste it and i'll just do couple changes instead of input shape i'll just replace this by nothing and then the kernel size we can just give instead of five cross five we can give seven cross seven or eight cross eight totally depends upon you so here i'll be giving seven cross seven and then this would still remain the same all right so after this what we're gonna do is we have to flatten our model so model dot add now we'll add up a flattened layer and finally to perform the classification operation we have to perform dense layer so model dot dense so it's going to be add and now for this we'll add the dense layer all right so here we'll have units so as is performing a classification task so units here represents how many number of outputs we have as we know that the number of outputs here range from zero to nine okay because that's the numbers we have right so we'll give here units as 10. all right and then we have activation so the activation that we're going to use is softmax alright so let us now compile this or before that let me run this cell and finally we'll compile it model dot compile okay and now here we have to give the loss so here we'll say loss this should be equal to what kind of loss we are looking for we can say categorical cross entropy we can also use something called a sparse categorical cross entropy if i use past categorical cross entropy then i don't have to convert my outputs into one hot layers okay so i'm gonna do that so it will be sparse categorical cross entropy all right and the optimizer that i'm gonna use here is adam you can use anything that you want you can use like stochastic gradient descent then you have various types that you can use the best one that is that is others now is adam and then metrics that we want to represent this is by accuracy all right so this is done and now finally we will compile our model so let me execute this all right maybe we have done a small typo here so let me change this from accuracy to acc to accuracy oh yeah it's going to be optimizer right so optimizer all right so now what we are going to do is finally we are going to see the model dot summary so model dot summary this just basically gives us what we have included here so as you can see we have total number of layers as 1446 the number of parameters it's pretty small when you compare to our deep learning applications okay so finally we are going to train our model so to train our model we have model dot fit okay and now i have to pass just my values here so it's going to be x test then we will take white test so it's going to be white rain all right then number of epochs is q1 because if we give more it's gonna overfist right so number of epochs this would be one and the batch size will just give one so in one go it will just take up all the values right and let me execute this all right so we basically have to reshape our image so let me quickly get that done as well okay so basically we have to pre-process our image so to do that we have to reshape it so let me just quickly show here what i'm trying to say so if i put here extra in dot shape so after this let me add this so if i put like x strain dot shape all right we are getting this right apart from this i also need to have one over here so in order to do that what i'm going to do is just put reshape here so what this would do is like we will just get down here add one more column or so okay and now we will take x strain this should be equal to x train dot reshape all right and now we'll pass a tuple value which gives us this thing okay so minus 1 comma 28 comma 28 comma 1. so if i see the shape now you'll see here for this you have one okay so the reason why we are getting this error is because our shape is we don't have one present here okay so we have to add this one so it's pretty simple all we need to do is reshape so we'll just kind of do reshape over here all right so here we are getting an error so let's see what is this error that we have right so error here we have is with the shape so it was expecting dimension three but then it received this particular shape so the problem over here is we're supposed to have one okay so number of dimensions should be four so here i should be one comma 28 comma 28 comma one this has a simple fix here so what i'm going to do is i'm just going to take this x strain i'll just reshape it okay so x train dot reshape all right so we are going to pass minus 1 here and then we want to give 28 comma 28 that's the image and number of dimensions similarly we'll do it for y values so let's scale x test and this would remain completely same so let me copy this and paste it here and instead of train it's going to be test looks good so once i execute this let us rerun this part over here model.fit okay so for this what we have what we'll do is we'll rerun this model from start okay so we'll run this from here yeah yeah yeah so as you can see here now our model is working and this currently is in our training phase right now and the way this thing trains totally depends upon your cpu or compute power what people usually do is you know if they have any machine learning or deep learning model they would just go down to google call app as it's shortly free of cost okay so let's now wait for this thing to train off all right so we have now successfully trained our model so now what i'm gonna do here is i'm just gonna like save this model and if you think how this works so let me now show you like if you remember we have couple of images here right so now what i'm gonna do is i'm gonna load this image over here and then let's see what this image value represents okay what does this model predict this value all right so now uh what i'm going to do is like import cv2 all right now with cv2 i can just provide a path or i can also have something like pandas okay and now what i'm going to do is i want to read this particular image right so pandas all right apart from pandas i can just use cv2 so let me quickly import that so i'll have cv2 all right and now if i want to read the image let me just give a variable here the cv2 dot i am read all right and now let me just take any random image and we know this image is 3 so i will copy this and i'll paste it over here copy path relative path and then we'll paste it over here all right and let's quickly execute this and let's see what is this image here dot shape okay the reason why i'm getting an error is because obviously i'm supposed to give a path like this and yeah so it should work now all right so now uh we'll try reading this image over here all right so the reason why we're getting this error is because it's kind of unable to read this so sometimes what happens is you know depending upon the system we have to use different orientation of this particular path okay so let me fix that up here so let's see how this thing works all right so this is not working so what i'm going to do is instead of this we have our test data set right so let me say x test let's say if i take 0 and if i plot this plt dot i am show all right so this should show me seven right okay so this is showing me seven now what i'm gonna do is i'm gonna pass this image into our model and let's see what this thing predicts so before i can do that uh let's say i have to resize it okay so i have to take x so i'll make test value then i'll pass here x test we want the first image dot reshape all right now we'll take minus 1 and then we have to obviously it will be 28 comma 28 and then one so if i say test dot shape all right so as you can see we have this now we'll just predict this so we'll have model dot predict class and now i'm just going to give test value so you can see here we are getting the value here as 7 right so similarly if i take up any random value let's say let's say i want something like 78 so this is 9 right so let's see how does 9 looks like here so what is the value 78 and as you can see our model is predicting well so finally what i'm going to do is i'm going to save this model in order for you to save the model we have keras function which says model dot save all right and now what this model.save do is we have to pass a path and all we need to do is like my model dot h5 and now once execute this uh you can see here we'll have an h5 file all right so this is how we work and train our model now what i'm going to do is in our next stage we will get back to our python and we'll just pass a value like like this particular image okay to a model and once it predicts this so now if i have to load it we'll use load model and then we'll just put a model underscore my model underscore a model and then just dot predict and we can get the output all right so let me now quickly move to my code editor so let's save this and let's create a python file here all right and the name of this python file that i'm going to give is let's say app.py all right and let me quickly get that open that up okay so now when it comes to app.py let me zoom in a bit so that you can see here clearly so first off let me tell you how we are going to work through here so what we are going to do is we are going to use something called as pi game module and pi game audio if you know its one of the most popular application or a framework to develop games okay the reason why i'm going to use pi game is because here we have something called as event loop which is a constantly running loop and unless we don't close our application window so that means our window is continuously getting fresh so let me quickly show you how we can work over here so first of all we'll import pygame and then system framework then we also need to import numpy okay and then we we have keras.model import load model so load model we basically use to uh the load the model right so load model all right and apart from this we also will import or it will be like this from pi game dot locals import star it is we are trying to import all the packages and finally we need cv2 import cv2 all right so now what i'm gonna do here is so first off what i'm gonna do here is we'll initialize our pi game so for that we'll have pygame dot in it all right and now uh what i'm gonna do here is we'll have to create a page all right so pygame dot display all right so pi game dot display dot set okay underscore mode and here we are gonna pass the name or whatever the size of the screen that you want okay so window size that i'm going to give here is 640 pixels by 480px it's totally up to you you can give whatever you want all right and apart from that we can also uh like have this so for this let's give a name we'll say display surface all right and now what i'm going to do is for this display surface we'll also add some colors so white in it so display surface at what we have described earlier dot map rgb and we'll give here as white okay and this what this white value over here represents is whatever we type in right so like it accepts only white value so we'll give it here as white and this would be 255 comma 255 comma 255 all right this looks good and now finally coming down to caption let's set the caption for our image so for this it will be pygame dot display dot set caption so this would be let's say edius demo all right now finally what i'm gonna do is something that is related to our image so he's writing basically i'm using it for my while loop is writing if this is false all right and finally we'll have whatever the numbers we have right like whatever the numbers are percent right on a blackboard we have to take up the coordinates so that we can i can put them in a bounding box okay so number underscore x coordinate so this is basically a list and similarly number for y coordinate all right and by default i'll give number of image as one that is image count so this should be one so finally coming down to the event loop so if you know about pi games event loop is basically an infinitely running loop here we can capture whatever input that is being given from the input user and it constantly refreshes the screen so this is like while true okay as i mentioned it is constantly running so what i'm gonna do is i will capture the event okay so while or we can use for loop here for event in pygame dot event dot get all right so basically i'm trying to capture my event here so now what i'm going to do is if even dot type is equal equal to quit okay that is if i close the button so then i want what i want is pygame dot quit all right and similarly i'll use this sys.exist all right and now what i'm gonna do is if i'm writing right so if someone is trying to write so if even dot type is equal equal to mouse motion and is writing so if you remember we have declared this is writing over here so now if this is the situation what i'm going to do is first off take off the x coordinates so x chord and then y chord we have a built in function here that is event dot position all right and then finally what we can do is pygame dot draw then we have something called a circle and we have to do this on our display surface so i just pass our display surface and the color i want is white if you remember the white is uh it's basically a variable which is over here 255 250 255 and then finally we'll pass our area that is x and y coordinates so it will be x chord and y chord and finally like shape or the size of that and zero and finally we'll append the coordinates to our so number x chord dot append we'll give here as x chord and similarly for y chord all right so this is one thing so next off if we have if event dot type and now is writing will be true okay so here we'll have mouse button all right so it's going to be mouse button up so when the mouse button is up we have to do perform various tasks that is nothing but once we are done writing right we have to whatever the values that we have we have to take it and pass it to a model but before that let's also do it for mouse button up or when the mouse button is down so if even dot type is equal equal to mouse button up or mouse button down that is and this is going to be down okay so when a person starts writing then what happens is is writing variable this would be true and now coming down to mouse button up so this is a pretty important part here so now what happens is first off we will change is writing to be false because we all know that this is a constantly running rule so we'll just update the value first okay and now we'll take the value of x coordinates so this will be sorted all right so number of x coordinate and then similarly you are going to do it for y coordinate y coordinates all right so now we have to find out the rectangles right so for that particular bounding box so it's pretty simple so we'll just give as xmin we can say rec t underscore minimum x and then we'll have rectangle max y all right and now basically we'll just find the maximum value which is present over here so we'll just do max okay and number x coordinate that is the zeroth column here minus boundary okay we also have supposed to put on this boundary ink so we'll just give that so it'll be just come down here and give a variable this is basically like padding okay so boundary so we'll just give here as five and similarly if i come down here it will be boundary inc and then comma zero and now similarly for minimum value so this would it would remain same so i just have to take here as minimum value okay and then we'll give here as window size okay so let me fix this up so here will be minimum value all right and we'll change some arguments here so window size all right so window size x is some a variable that will be defining up and then we have number of x chord here we'll take the minus one because we have sorted out right if you remember and then we'll add this to boundary okay so we'll have boundary inc okay so now what i'm going to do is we're going to find the rectangle for both even y coordinates so let me copy this and come down here so if you're gonna go here instead of x it's gonna be y and similarly here instead of x it's gonna be y and now similarly what i'm gonna do here is instead of x coordinate this would be y coordinate so and this would be minus so this is absolutely fine and then so for minimum what i'm going to do is window size y right so window size y and this is going to be y coordinate so now we have the bounding boxes value for both rectangles okay and now similarly what i'm going to do here is window size x and y so let me go there on top and give window size x so it will be 640 and then window size y will be 480. so basically this is this values here okay so now what i'm gonna do is we'll create one more list down here so number record x and then number record y okay and then we have input amg or i can just put here as image ar image array so it'll be np dot array okay and now we have something called as this built-in function when pi game so it is pygame dot pixel array and now we'll just give our display surface all right and now what i'm gonna do is if image save that is if i want to save the image all right and this is basically a variable that we're supposed to define on top so let's quickly get that done so we have this and we'll give the value here as false so if it's if it's a new image then what i want is to save it so cv2 dot i am right all right and we'll just give here some value dot png all right and now we'll increase the count of our image so image count so if you remember we have done that so this will be plus equal to 1 all right now finally coming down to predict so if predict all right so this is also a variable that we're supposed to define on top so we'll give here as predict and we'll give the value here as true because we want to predict it right so if predict so here we'll have image so this would be something similar to cv first of all we have to resize it okay so cv2 dot resize okay so i'll pass my image array and the size that i want is 28 comma 28 because we have trainer model to be working on that right so this is it and now we have image so this would be np dot pad so i'm adding padding layer so i have image i'll add like 10 pixels okay 10 comma 10 and finally uh the value is gonna be constant and the value of the constant is zero all right and now coming down to uh like drawing a rectangle here but before that let's also we have to normalize our data in our image so image is equal to cv2 dot resize so it will be -1 that is the size of an image okay so here we're going to pass the image name so image so 28 comma 28 and then finally to normalize it we have white in it so if you remember white in it is 255 comma 255 comma 255. so in order to predict we just have to do model dot predict right and we have already loaded our model so i'll give here label as label so it'll be string right htr so now i have labels so np dot rmax and now we'll have model dot predict so finally i'll have image here rotary shape all right so now what i'm going to do here is we'll call a model okay so we'll load our model here so we'll create a variable called as model and to load our model we have a function that is load model and now we are going to just pass the value so if you remember we have loaded our model present over here dot h5 file so copy the path here and paste it over here looks good so finally we are done with the predict now all i'm gonna do is whatever we have predicted i just have to put that in a rectangular form right so we have pygame dot draw dot rectangle so now we have something called as display surface all right we have this rad we will try to define this i'll tell you what exactly this is so rad and then we have minimum and maximum value of rectangles that is the coordinates right so we have first one is the rectangle minimum that is x value and then we have a minimum value of y okay and then we have the maximum value rectangle max the minimum and then if i go for rectangle max of y minus minimum of y all right and finally i want the thickness to be three all right so once this is done uh we are done with the predict part so what happens is if event dot type if this is equal to key down okay if this happens then we have if event dot unicode is equal equal to n then what will happen is display surface dot fill that is to we are basically here trying to reset our image right so black so black is yet another constant here so we'll give vlack so this is to take a tuple value so zero comma zero comma zero so once this is done we have to do pi game dot update all right so with this we have completed our application in prog python so let me now quickly run this and see how this would look like okay so let's run this run python file in terminal so basically now i should get a console so this is taking quite some time so let's wait for a minute or two okay so as you can see here we have got our console and now if i try to press eight like if i draw it you can see here we are getting this value eight and now again uh if i say nine right you know what is happening here is the features okay so if i put this curve like this this is a feature of zero like if i put something like this right so this is zero so if word one right so it is it is representing two because we have this curve as this is a deep learning model it's more of a pattern okay so now if i have to represent eight it's something like this okay so it's showing two but if i put it like this eight all right so it's all about patterns okay so this is five so you can see it's showing five and now similarly if i have to put on some other values let's say something which you haven't tried so i think four right so we have four something like this so as you can see we are getting four over here and now every time i click n what happens is the board gets reset all right so this is basically what is happening in image processing we basically are trying to create a bounding box and then given output this is a very simple example of what image processing is capable of all right guys with this we come to the end of our session i hope you enjoyed and learned something new if you have any further queries please do mention them in a comment box below until next time good bye and take care i hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to edureka channel to learn more happy learning you
Info
Channel: edureka!
Views: 169,900
Rating: undefined out of 5
Keywords: yt:cc=on, Image Processing Tutorial Using Python, image processing using python, digital image processing, python image processing opencv, image processing crash course, image processing, opencv tutorial python, opencv python, opencv tutorial for beginners, opencv python tutorial, opencv tutorial, open cv, opencv python 3, computer vision, learn computer vision, computer vision tutorial, opencv python projects, edureka, Python edureka, Edureka python
Id: sfheWK72L74
Channel Id: undefined
Length: 46min 1sec (2761 seconds)
Published: Thu May 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.