Car Parking Space Counter + Detector using OpenCV With Basic Image Processing | Easiest Method

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to my channel in this video we will see how to make and car parking detection press counter in this video i will go step by step everything you will learn and we will use basic image operations hey guys welcome back to my channel in this video we will make an car parking space counter plus detection so let's start so right over here i have here two files called main dot py and cast space speaker so from this i will process this image and find and position and i'll store it in a pickle file like this i will just delete it and i have an mp4 file okay so right over here for the main part of the typical thing of the creating the pickle file we need cv2 and we need and typical right-wing and module and right over here what i am going to do is run here and try try and i will see if there is a file or not if there is an file then the try will get no error if there is no file then the try will get an error and if there is an error then you can do something else means we are just uh asking it if the file is there or not which means this is that just an easy way you can use it os or aspires module to do that but i am using try and s except for increasing the performance in the try i will use fifth open in that i need the file name it's car park position and then the move will be read binary and as okay right over here you say picking dot load and in here i'll just be there then simple as that if there is no file then what you can just do is create one file called position boost yeah and i will also store this in the same list position list okay there we go so next thing is to add up here and while loop while two here we will do all the processing right in here we'll say image equals to i am three key image equals to cv2 dot i am method and then the file name will be image.kng this image so the main thing right over here if we use it with that for loop it will work for the bird eye view like this means the top view will work for the document but if you are using a side view or something else or tilted then it will make a problem so to so we will not use the for loop and what we will ask the user to choose it okay and right over here one more thing if you have something like these not the straight line if you have the tilted lines till this then also this method will work that i am showing right now okay and here image equals to ivory i will say i am show image and then i will add wheat key as one and i will also see a cv2 and what i want to do is okay what i would like to do is add up these rectangles on it okay means i will ask the user to choose and also i will make an option to remove in case we add one rectangle by mystically so what you can just do is you can find and perfect width and height afterwards but right now i have finded the width and height before only so i'm just showing you the width and height which i found with before and right over here if i go here we'll define a function called mouse click and here will be an event for the clicks here events x y flags and then paragraphs okay so i will just call this function right over here cb2 dot set mouse call back window name is image and on mouse mouse click so now we are using the function over there and that will give us events x y means the position where we have clicked in flags and the parameters that the those are the things which this function will give us from the cv2 into this function so in this function what i'm just going to do is check if the events is equals to cv2 dot event underscore l button down means we have click means we have clicked with the left button means we have clicked the if we do and left click and for the right click also we will use it for removing if you have clicked then go to the pose list and append those values of the x and y when we have killed and the next thing is for the right click so if we have right click then what you can just do for right clicking you can just change the l to r okay if you have right click then what you can just do is random for loop and position and i will just enumerate it so what enumerate does it will give the indexes of the position and also give the element also okay it gives us two things position and why i need this index that's why i have call in it because it will be used for removing guys but before that i will also need to check that it is valid or not if the user clicks somewhere else not inside of the rectangle then it will also happen that we will remove and wrong element right i'll just define x1 and y1 as position right over here and right over here what i'm just going to do is check that it's valid or not if x1 is less than greater than sign x less than greater than sign except the correct width and so we have checking for the x so let's also check for the y also so here will be y one is y and he will come y one plus left height okay so what you can just do after checking then means we have clicked correctly on the rectangle we have verified it then you can just pop that element means we can remove the element with the pop function and at last we will save those changes in our pickle file so for saving we will use the width open thing and right over here either on rb i will use wb and here either i'm saying you post this what i am just going to do is say hypical dot dump this will save those changes as we click next thing is to get a preview so we will know that it's correct or not i'll get a preview right over here so i will just use the for loop and i will draw a rectangle right so let's make it in one line because the code is just one line only image and then the part one will be the position and then the part two will be the y plus the rect width and then the x sorry the x plus fifth and y plus and the y plus the height right and next thing is to also get the color that will be red and then the thickness that will be two and nothing else so let's check it out if i left click it adds some rectangle and if i right click it removes the rectangles if i just exit it and again open it it saves okay so right now what i will just do is add all the rectangles right over here i will just skip the part okay so here i have drawn all the rectangles guys i know it's not that proper but i've tried my best so now you can see we have all the rectangles now there is no need of this file so i will close it but still we can copy some code so we need the code here and i will just remove this try and accept statement because we don't need it because the file will always exist and next thing will be our uh also import the numpy model so there we go we are also importing the num pipe module and right over here i'll also copy the white glue okay so right over here what we are just doing is copy paste we just remove that okay so what i will just do right over here is waitress not this yeah so what i'm just going to do right over here is i will also remove this statement and i will also remove this statement and i will create hand video capture not for the webcam i'm using if you want to use it for the webcam or and cc tv then also you can use but i have your mp4 file if you want to use it for cctv or webcam then you can just specify the number for the cctv or webcam index and if you are using mp4 file just specify the file name of it and now i can read it so now we can see the video let's so the video is a bit fast forward so that's why i'm adding a bit more delay of milliseconds so now you can see the video next thing is to go to the main processing part by creating a function okay so right over here for and function the function name will be uh let's call it check and the arguments will be the processed image so for now i'll pass it and i will just do my image processing post yeah then the next thing is i also need to apply some gassy gaussian blur [Music] gray the corners will be three by three and the sigma x will be 1 and we will also add some threshold so right now i think so that adaptive threshold will be perfect for this project and the adaptive threshold for it i will use block and max value will be 2 by 5 and adaptive method will be cv2 dot uh what so the code will be something like adaptive thresh gas gaussian c and right over here cv2 dot uh thresh binary invert and next thing after adding the thresh binary inward block size that will be let's keep it 25 and 16 as you see okay so we are also getting our threshold next thing is to add median blow let's call it blue also let's overwrite the block tv2 dot million though here i need the source threshold cornell size oh let's keep yeah then then we need nothing so adding the medium blue is too too simple then what i need to is to add some dilation and of course for that i will need a kernel that's why i imported the numpy and in the ones three by three because i specified the color size at three by three i will add some dilations that's why i'm doing it right and then let's apply some ligation so if this cv yeah see we do not dilate in the function i need and source which will be blur of course and then i need the kernel and then i will set the iterations as one mostly we use one but sometimes it will be different also and right over here we'll call the function so i will give the processed image means the diluted and in this function for the counter i will create a space count variable that will help us to get several count for position and position list and right over here i'll add a color and next thing is i will add x y as position so if you ask from where we are getting position list from here so i will be using some lazy techniques right over here i will crop the image and for cropping the image pretty much process so what i mean by cropping the image i will crop every every rectangle chooser means for this cup or this car everything that i will check okay and in the image processed i will say here y colon y and here we need the rectangle size means the cropping position uh let's uh that was a correct right w right yeah actually here's a direct height now it's correct and similarly i will say here x colon yeah so now we have cropped the image to the specific cells so now i need to also get an account count is an specific number means it will count how much pixel how much better it is and i think so it will count will be greater than 900 if it's uh if there is no vehicle it will be less than 900 if there is a vehicle because or the vehicle is huge that's why it will be less than mine the the vehicle is not that small that i will say here cb2 dot count non zero yeah cv2 dot count non zero is specify the cropped image from it will count and here i will learn run on if loop if crop is less than greater than 900 then i depend count and i will also change the color to green and we will also have to change the thickness because we are overlaying it so the user must realize that's why i think and i think five should be enough accurate will be more than enough actually else copy it east and it should be red right and here i will draw the rectangle simple as that angle means i will draw a rectangle for all the specific cells so one more problem is there if i try to put the count over here means right over here right over here if i put it there could be something white so the text color depends on the image so what i'll just do is draw the text on and rectangle so it will be depend not depend on the image it will be and constant so will be constant okay yeah i will say image drawn image from where we get image from here we are calling it right over here that's why it will not give us any error so it's again on shortcut method here the part two will be both x plus correct [Music] right so as per the rule of c v 2 we need to also add x and y with the width and height next thing is color as color the variable that we have created and thickness as thick thickness there we go and next thing is add up the text so as i tell we will add the text on a rectangle so let's create that rectangle first and the arguments of the let's give that 45 by 30. and let's go over here and then that should be 250 and 75 and then the color let's keep that purple on purple the white will look a bit better and if you ask why i'm not using else like green and red because the color is used a lot that's where it will look too bad thickness as minus one minus one stands for build usually what used to do is write cv2 dot filled but now i knew it we can also use the minus man so now i use minus 1 to text so in the put text i will write image then the text will be an f string and here will be the space count slash and i will use the length of the position list to get all the cars and next thing is to get the position let's try 50x60 pawn face at cv2 dot font so she's simplex let's try it 0.9 color as white white color code is 255 255 255 that's the white color code and thickness as to right let's try that out okay it gives an error yeah i specified here crop instead of it through the account yeah yeah now you can see the vehicles count yes you can see 12 13 one car has gone should be 14 this car has gone okay so it did it properly guys so it works fine so that this car also got so now it's 15 okay so one more thing if you also want to add for this card you what you can just do is add one more rect width and height then if you look for the card also and one more thing don't forget if you're using a side view or something else still it will work fine if you have something like tilted lines means like a diagonal light still you can use that rectangle in the diagonal line you can use a perfect size for it then it will it will work still fine it will work in any case it works fine guys so thanks for watching
Info
Channel: Techno kidzo
Views: 10,077
Rating: undefined out of 5
Keywords: parking space detection algorithm, parking space detection + counter, parking space counter + detection, Using basic image proccessing, parking space detection api, parking space detection ai, vehicle parking space detection, vehicle parking space counter, car parking space detection, parking space detection cv2, parking space detection opencv, parking space counter cv2, parking space counter opencv, parking space counter api, parking space counter ai, parking space counter
Id: LlRlPv1uQqc
Channel Id: undefined
Length: 25min 38sec (1538 seconds)
Published: Wed Dec 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.