I Ran a Raspberry Pi License Plate Scanner for 2 Hours

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm going to use this and this to do this [Music] and you can see the license plate recognition system captured that in this case the license plate is literally school bus in case you couldn't tell that's the Raspberry Pi cheers as you can see these are the cars passing by I'm gonna see how it goes hopefully without getting arrested oh uh it's for a YouTube video now I was explaining this concept to a friend last week and she was totally doubting that I could pull this off for whatever reason I don't know if she's being a hater or what but she just doesn't think that I can pull this off so why don't you think I can make this happen nope I don't think you can bro not by this Sunday I don't think the Raspberry Pi has enough capacity to accomplish what you're trying to do by this Sunday nope okay she sounds so confident so this is what we're gonna do we're gonna place a bet if I can get the Raspberry Pi to recognize 30 license plates in one hour then I win the bet you have to send me a selfie admitting defeat and I'm gonna post that selfie on the video but if I can't get it to work by Sunday then I'm gonna venmo you a hundred dollars sound good sound good for sure let's do it and with that the pressure was on can I get it to work with just the five days I have to make it happen so the way this setup will work is we're going to program a Raspberry Pi to continuously record video of cars passing by at the same time we'll run another program that will periodically convert that video into pictures and then send those pictures to a cloud license plate recognition service which will analyze that image for license plates and return the results we'll then take those results and save it to Google Cloud datastore which is a cloud database all in real time so say farewell to vehicular privacy sit right back buckle up and enjoy the ride so for those coming in cold a Raspberry Pi is a single board computer about the size of a credit card what's amazing about it is it only costs 35 dollars okay so the first thing we want to take our micro SD card out of our Raspberry Pi I'm going to use the micro 2sd and then what I'm going to do is throw this right into my computer okay so with the micro SD card inserted into my computer we can see it showing up as this boot drive here so we're going to download Raspberry Pi imager and Flash the operating system we're going to go to raspberry pi.com and then we're going to go to software and then we're going to download imager in my case for Mac go ahead and install that okay and then we're going to boot that up and then for operating system we're just going to choose stable 32-bit and then for storage I'm going to select my 32 gigabyte micro SD card and then we're going to pre-configure and input our Wi-Fi credentials as well as allow SSH okay so we're going to set the hostname to raspberry pi.local that's the default that works we're going to enable SSH and then we're going to supply a password and then we're going to go ahead and select right okay and it looks like that just completed so we'll go ahead and eject our SD card okay and we can see the SD card has been ejected okay so I'm just going to go ahead and remove this from my computer and we're going to pop out the micro SD card and then we're going to pop it into the Raspberry Pi okay so now that the micro SD card is formatted we just need to connect the camera ribbon and and place it into the chassis so the way we do that is you open up this here see this class goes up and down take the camera ribbon here we ultimately want this thing to go like that right kind of hard to do but make sure that the metal strips are facing towards the I guess the Raspberry Pi logo put that in like that down okay now what we should be able to do is to put this in here okay cool and then you can see that is the camera lens okay and then I'm gonna screw this um mounted tripod head to the Raspberry Pi like this and then we're going to put this on an actual tripod okay and then I'm just gonna put this guy on this tripod here okay so that is our Raspberry Pi and it is facing towards a license plate that I printed out so we're going to program it and run some tests and make sure that it can detect that license plate and then when we feel comfortable we'll bring it on the road okay so let's connect to the raspberry pi over SSH so the first thing I'm going to do is Ping the hostname to make sure that it is connected to our Network and we can see that it's returning icmp traffic so that looks good to me and then we're going to SSH and so we're gonna do PI at Raspberry Pi dot local and then I just need to clear out these fingerprints here so I'll do that with vim and then we'll establish a new connection okay do we want to create a new fingerprint we do and then we're going to supply the password that we set in the pre-configuration and you can see that we're in our Raspberry Pi and this looks pretty good here so I'm going to elevate myself to root and the first thing I'm going to do is update the operating system with these commands here and again all the commands are available in the description so you can just cut and paste those okay and so the Raspberry Pi is going to reboot so let's try to connect to it it looks like it's back up though it's SSH back in Elevate to root okay and notice that when we upgraded everything we got all our folders here so I'm going to navigate to desktop and we're going to install some of the dependencies that we're going to need here so the first thing we're going to want to install is node because we're going to write our script in node.js and then we're going to install 13.5 using node version manager NVM and then we're going to 0.2 13.5 so we're going to do NVM use 13.5 and then we're just going to validate what version of node we have have 13.5 so that looks good okay and then we're going to download the GitHub repository that I set up so this is my GitHub account if I go to Repository is this is the new video video license plate detection repository so I'm going to click into it and then I'm going to go to code and I'm just going to copy this address here and we're just going to run git clone and then Supply that address and this is going to download that entire directory and then we can start programming with it and again we put it on the desktop okay so there's an extension called remote SSH which lets you connect to a Remote device and edit those files using vs code it's super useful and so I set this up and I pointed it to Pi at raspberry pi.local which is going to be the host name and then it's just going to prompt me for the password okay and it's asking like what file should I look into so I'm going to run PWD and I'm going to grab this path and I'm going to supply it over here so now you can see these are all the files that we downloaded from GitHub so for instance this is one of our JavaScript files right here and what's also cool is you can preview these images here right here in vs code so this is just an easy way to develop on the Raspberry Pi we don't have to do it over SSH okay so the two main files here are going to be only capture video this file here and then watch video and we need to run both of these simultaneously but the gist of how it works is this guy here only capture video just uses libcam vid to take 10 second videos and every time it finishes taking a 10 second video it just overwrites this flag.txt file and this here listens for changes on flag.text so basically every time a new video comes through it then will split it up into frames and then it'll analyze the images and send the data off to our remote Cloud license plate detector so that's the gist of how it works okay so I just want to make sure our camera is working properly so I'm going to run this command here lib camera JPEG that is just going to take a still image and then we can review what that looks like okay and then it wrote the file to test.jpg so I'm just going to click that and this looks pretty good so we'll leave the camera as is and we'll run our program against what is currently presented in front of it there okay so let's see if we can't get our first script to run so this is only capture video dot JS there's a function here that says take video and essentially it runs the lib cam it takes a 10 second video it outputs it to dot h264 it sets the dimensions of the video once it's done with that it will just update this flag file and the reason it does that is because their other script is going to be listening for their updates to that flag file and anytime an update is made it's then going to kick off the analysis process but this scripts only job is to take videos 10 seconds at a time so let's go ahead and see if we can't run this so the way we would do that is we would just run node and then Supply the file name so you can see it logged this take video function and that looks good and that was about 10 sec seconds right and now it it it wrote the flag and it's taking another video so it's writing the file to here.h.264 now vs codecamplay.h264 it should be working properly we can see it's it's working here so that's fine so let's go ahead and kill that we'll come back to that later now the second script is watchvideo.js script here so again what this does is it listens for the flag file and anytime the flag file is touched it converts the dot h.264 to an mp4 and then it takes that video and splits it out into a bunch of frames right because we need images to run the analysis and then when that's done it will iterate through all the images and send the data off to plate recognizer.com and then it takes the results and it will save the results and it say saves the results to datastore Google data store which we imported up here so there's a bunch of dependencies in the script so let's try running this script and see if we can't at least get all the functions to run properly so I'm just going to supply node and then we're going to do watch video okay so everything ran except for the save data function so the reason that didn't work is because in order to save data to Google Cloud datastore we need to be able to connect to um to a Google Cloud platform so the way we do that is first let's go set up our account so I'm going to go over to my browser here then I'm going to go to a Google Cloud platform if you don't have an account you can go ahead and create one they'll give you a 300 credit so we want to use a product called datastore This is a nosql database okay so there's currently nothing in datastore but I have a project set up I enabled a datastore it might ask you to enable the datastore API you're going to want to do that because we're interacting with this nosql database this is kind of like mongodb but Google's version we're going to be interacting with this using the API now in order to authenticate we need to create a service account so we're going to go into IAM which is identity and access management and then we're going to come down to service accounts okay and then we're going to go to create new service account and I'm just going to call this a license plate detection and then we can continue through this and the role we want to give it we're going to do basic and then we're going to do owner because it needs to be able to read and write data there's probably a more granular access level we can get it but I don't want to contend with that right now so we're just going to use this okay and now we have this service account here so this is now a way that we can authenticate and get into our gcp account now there are different ways to actually download the data we're going to do a Json key so we're going to do manage keys and then we're going to do add key and then we're going to do create new key and we're going to select Json create this and then what you can do is you can just open this file and copy the contents and we'll go back over to vs code and we just want to add that to the Raspberry Pi so what we can do is we could just do new text file and then we could paste this in and then we can save it as a key keys.j keys.json super quick but if you have issues editing the files like it won't let you save because of permission issues then run this guy chmod recursive 777 on the topmost directory like the GitHub repository and then that should make everything editable for you so when we execute this watch video JS file is by prefacing the command with a reference to the service account watchvideo.js but we also preface it with this and that should authenticate us so let's go ahead and give that a shot okay so now we can see that the program's working correctly it's periodically taking pictures we can see the preview of those pictures and it's saving those frames as output followed by the index and so just to prove that this is all real time I'm going to go over and move the license plate and we should see it update in the image previewer here okay and now we can see that it did in fact move because it is taking pictures in real time okay so for the license plate recognition we're going to use a service called plate recognizer.com and we're going to be able to do this all using the free tier so you're going to want to go ahead and just create an account and that will provide you with an API key okay and once you log into a plate recognizer you can select apps and it should bring you to this dashboard here and this is going to give you your API token and it's also going to show you how many requests you've made so we get 250 for free at a rate limit of one per second which is very generous and then as we take pictures they're going to show up in the dashboard section here additionally once we are out on the road we need to have our Raspberry Pi automatically connect to my iPhone's mobile hotspot so the way you can set up preferred networks is by editing a file called WPA supplicant so all I'm going to do is add a new entry to that file file at the top that provides my mobile hotspot Wi-Fi credentials and once you've completed that anytime the Raspberry Pi boots up it will automatically try to connect to that Network first and that will give us internet access on the go and so I'm just going to reboot the Raspberry Pi and test that it's able to connect to my mobile hotspot and I turned off my Wi-Fi in my apartment so it only has one option okay now you can see it's connected to my hotspot not my apartment's Wi-Fi so we can see uh the images being rendered in real time and that is our camera would be better if we had more flow but uh it seems to be working because check this out if we go to the dashboard page here we can just see all of them and so if we go over to dashboard we can see basically every image that we sent to the API that had a license plate detected it will store here and it shows the time stamp it shows the actual license plate that was determined it also shows the confidence level so we could like add a threshold to say like it has to be 95 percent confident in order to store it you can do a lot of fancy things but I really like this dashboard it's all real time and you can see these are a lot of the pictures that we took on the road so like this car was moving when we took that that car was moving and you can see like they're pretty small sometimes and it's still like SRB 7D srb70 it's pretty good hex 2-2 look how small that is so it's doing it did pretty well school bus I thought this was funny right school bus and then you can see that's it literally says School Bus that was funny CXC w20 CXC w20 so it's really really accurate now these should also be stored in Google data store so we can go take a look at that and we can see that we have a bunch of entries here yeah so we successfully stored these in Google cloud data store I just wanted to show how to store the results into a database as well and at the very end I sent evidence to Lexi proving that I was able to detect 30 license plates in under an hour and she gracefully admitted defeat with this picture she sent you never had you never had your car if you like this video then you're gonna love my video showing how I did license plate detection using a custom tensorflow machine learning model running on the edge it's super impressive you'll learn a ton and you can check that video out here anyways thanks for watching
Info
Channel: Data Slayer
Views: 24,975
Rating: undefined out of 5
Keywords: Data Slayer, raspberry pi, raspberry pi 3 b+, raspberry pi 3, raspberry pi zero w, raspberry pi tutorial, install raspbian on micro sd card, install raspbian, camera module, ip camera, setup camera hikvision for computer, raspi-config, raspberry pi camera, alpr, license plate detection, opencv python, computer vision, openalpr, openalpr raspberry pi, vehicle recognition, platerecognizer, google cloud datastore, node.js, ffmpeg, vs code
Id: xhi2FKmnJ4k
Channel Id: undefined
Length: 18min 35sec (1115 seconds)
Published: Sat Oct 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.