OpenCV 3 KNN Character Recognition C++

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello again everybody and welcome back this is going to be the first video in a six-part video series and first we're going to perform character recognition using KNN in open cv3 and then we're going to perform license plate detection in open cv3 and we're going to do each of those projects in C++ uh Python and visual Basics so that's uh quite a bit to do so let's go ahead and dive right into it so to get started today we're going to go to GI T hubu Mi microcontrollers and more and take out the spaces and then we're going to go to here and then repositories and I'd suggest to go ahead and bookmark uh this site at this time so uh the only prerequisite to this video series here I'll mention that first is open cv3 uh Windows 10 installation tutorial definitely if you're not familiar with uh running open cv3 on Windows 10 go ahead and check this out and I've linked up here uh the YouTube playlist for this repository so uh the first video here covers uh open CV installation and configuration in C++ second video in Python third V uh third video and visual basic.net so definitely uh check that out if you have not already and continuing on with today's project we're going to go to open cv3 k and then character recognition CPP to get started here with our first project of the six and let's take a quick look at the directory contents here if we go to documents and presentation and KNN overview uh this slide is just sort of a real brief overview of the KNN uh algorithm sort of uh the ideas behind it and what it does um in my videos I try to stick to an implementation Focus so I'm not going to get too sidetracked into Theory here but uh for anybody that's interested in a quick overview of the Canon algorithm you can look through this slide and uh you could search on the internet for the various terms on this slide if you were curious as uh further as far as how the Canon algorithm Works behind the scenes uh but for now let's stick to implementation so uh gen data and train and test are the two programs we're going to run as part of this project and gen uh data. CPP is going to generate classifications. XML and images. XML uh you'll see that shortly when we actually run the program I posted the here uh just in case you'd like to compare um yours to the ones I've produced in this video or if you'd like to do a future project you can just download these right off of here uh but in any case this isn't actually strictly necessary to download because we're going to generate these during the uh running the program today and then of course read me. text is that's just this down here so then let's take a look at some of the uh images we have here so training characters.png this is the image that we're going to train on today so in five different fonts here we have images of characters and then capital letters of numbers rather 0 through n and then capital letters a through z and then and that's what we're going to use in gen data. CPP and then test one two and three is what we're going to test on in training test.cpp and this is just simply some basic characters and numbers written out abc123 I think this one's DF 456 and then I think this is XYZ 789 yep there we go so that's what we have planed to for today so let's go ahead and fire up visual studio and while we're waiting for that we're going to go to gen data. CP p and then raw and I'll just be copying and pasting out of this so let's go ahead and close that and then go to file new project and then going to copy the name out of the comments at the top of the uh code listing I showed just a moment ago so visual C++ empty project uh name is Gen data save to your preferred location uncheck those choose okay and when the project comes up for us we're going to add just one CPP file gen dat. CPP so let's go here add new item and gen data. CPP make sure it's a CPP file and now we're going to copy and paste in the entire contents of gen data and we're going to get a number of red underlines because we have to set up our references next and again see the um open cv3 Windows 10 installation tutorial I had mentioned earlier if you're unclear on any of the following steps I explain it in much more detail in that video so uh debug x64 and then we're going to set the include directory so project project properties visual C++ directories include directories and we're going to paste that in and then we're going to paste in the library directory which is right here Library directory and we're going to paste that in and then we're going to go to uh Linker input and additional dependencies and we're going to go ahead and choose edit and paste that in and then choose okay and then apply and then okay and all our red underlines should disappear okay so now the next thing that we need to do is I'm just going to go ahead and open up a second GitHub browser here it's going to make it a little bit easier to work with so open cv3 Canon character recognition CPP so if we go to download do uh download zip rather and then open so if we go in here and then there's our images so now let's go to the project directory next so if we go to uh documents uh Visual Studio 2015 projects and then gen dat this is the project directory we just made so we're going to copy training characters into there and there we go training characters is copied in so now let's go back to here and I believe we're all set to go ahead and run the program and there we go okay so this is that's just a command line This is the uh thresholded image of uh training characters.png so this image thresholded is this image and then uh this is uh training uh characters.png U but in addition we're drawing a red box around the current character that we're about to enter during our training process and then these two images up here uh this character on the left here is a cropout of the current character that we're on and then this character on the right is uh this character on the left resized to a width of 20 pixels and a height of 30 pixels so we're going to go ahead and enter the data here now when you're entering the data to train uh you want to bear in mind that an uppercase and lowercase asy character of course are different asky numbers so for sure when you're entering the capital letters you want to hold shift and then you want to let off of shift when you get to the numbers so holding shift I'll just call them out here uh holding shift uh zebra Tango uh Robert Paul Mary Frank Edward uh Delta Baker Alpha Yankee xray whiskey Victor uniform Sierra Quebec Omega Nancy Lima kilo Juliet Igloo Hector George Charlie now I'm let off of shift 9 8 7 6 5 3 2 0 4 and 1 and now I'm going to fast forward at this point I don't think it's necessary to wait through seeing me type in the rest of these 9 8 6 3 2 1 and zero and there we go window disappeared so now we're going to check uh gen data and sure enough we will find that classifications and images were just generated for us and let's just take a quick look at those so classifications is simply the asky character values of those characters as we were entering them and then images of course is going to be much more voluminous because this is the actual data for each of the images so this is a pretty large file even with just basic characters but uh that's okay we'll be able to read it in in our next program so let's go ahead and get that going so if we drag this back over here and then we go back to here and then now we're going to do train and test. CPP so we'll go to Raw to copy and paste out of and close Visual Studio and then we're going to fire up visual studio again and when it comes up we'll enter the project name train and test and once again we're going to have only one CPP file and that'll be train and test.cpp so close out of that close out of that file new project and visual C++ empty project there's our project name location uncheck those and as soon as that comes up we can create train and test.cpp so add new item and train and test.cpp and then add and now we can copy and paste in the code and then we can add our references here so x64 and then project properties visual C++ directories include directories edit and we're going to copy in the include directory which is going to be that don't get the quote at the end there and then choose okay and then Library directories and then we're going to copy in the library directory which is going to be that and and okay and then we're going to do Linker input and additional dependencies which is going to be that and then we're going to choose okay and apply and okay now let's see we need to put some uh images into our project here so if we go back to our browsing so this was the previous project gen data and then train and test is the one we just made so we need to go into gen data and then we need to grab classifications and images and copy those into train and test okay so now now we have classifications and images and training test but now we also need to get those three images from that download zip earlier so test one two and three so then we're going to go ahead and copy those in there so now we have classifications images and our three test images as well and we can close out of the download zip at this point so here's our project so we should be all set to go ahead and run it here so let's go ahead and run it and there we go so here's our image that we're reading the characters out of let me just stack these a little bit better here so here's our image abc123 and here's the characters that we've read abc123 and about a third of the way or so down the program is where the file name is read in so here we go so if we change this to two we can do contrl F5 again and there's our second image DF 456 and DF 456 so we're all set there and as long as we've come this far might as well do the third one and this is XYZ 789 I believe yes there's our image and there's our text so uh that worked out great for us so in the next video we're basically going to implement the same uh project in Python so see everybody in the next one
Info
Channel: Chris Dahms
Views: 72,076
Rating: undefined out of 5
Keywords: opencv, C++, software, tutorial
Id: CK0OCeCN9zg
Channel Id: undefined
Length: 10min 5sec (605 seconds)
Published: Sat Jan 09 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.