Simple OCR in Python with easyocr

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what is going on guys welcome back in this video today we're going to learn a very simple way to do optical character recognition or OCR in Python so let us get right into it [Music] not all right so we're going to learn how to do OCR or optical character recognition in a simple way in Python today and for this we're going to use an external python package called easy OCR so we're going to open up the terminal and we're going to type pip or pip 3 depending on your installation install Easy OCR and this package allows us to do optical character recognition in a very very simple way I'm using it actually in a project right now uh because I have this use case where I have a bunch of images and I need to detect the images that contain text if text is contained in the image I cannot use it or I don't want to use it and I do this with easy OCR but you can also extract the text from the images not just check if it's there so we're going to import easy OCR here and I have prepared four Images two bad examples for obvious reasons the text is quite messy here not clear um yeah because it's yeah skewed and stuff like that um and then we have two good examples here is just some text from Shakespeare and here we have uh three yeah icons or images here off sale and save up to 30 50 and 70% those are two images where this is going to work quite well now keep in mind this is not perfect you're probably going to get better results using something like chat GPT or some Modern uh models this is a very simple way to get the gist of it so you're not going to get perfect text you're not going to uh get great results here but you're going to get very simple way to do that and especially if you just want to check if there is text or how much text is there this is a uh quite a good solution so what we're going to do here is we're going to say first of all that the reader is going to be an easy OCR reader and this reader is going to take as an argument here language a list of languages and I'm going to just pass English here now and then we can read an image so I can say result is equal to reader. read text and then I can specify an image path and the image path in my case let's start with a good example here is going to be images and then uh good one do I think it's jpeg right yeah jpack so this is then the result now I can easily print that result you're going to see what this looks like uh because what eocr does is it gives us the text and it gives us the coordinates of the text that it found so it can find multiple things here um and there you go so you can see individual sentence sections are found at specific points here maybe this is going to be easier to see with good 2.png because there we have less text to be confused by um and then you're going to see here in the output that we get a bunch bunch of coordinates and then we get the individual words sale sale sale and then we get uh save up to 50% save up to 70% and save up to 30% there you go so we can do it like that or we can iterate over the results to get only the text so I can say four uh and then I have to use a triple basically the boundary box the text and uh a third keyword which I actually don't know what it's for I think something like probability not sure uh in result what I can do is I can always just print a text so print all the text sections that you found without giving me the coordinate information very easy there you go so I can get the raw text like this and you know this works as I said also for uh the other image but it's not going to work too well for the two bad examples uh it's going to find something it's just not perfect because the text is skewed and rotated slightly and stuff like that uh yeah you can see for the most part it makes sense but also not always you can see there are quite a bit of mistakes here um but we can go and try to do that here now with bat one. jpack let me just turn down my volume um and then you can see it gets positive even though yeah I mean it's it's not really positive it's like Po and then s and t and V doesn't find the eyes really uh maybe because of the ones down there uh but yeah you can see it somehow works and then I go to bat 2 JPEG and when I run this we're going to see two hour hone and then the welcome is not really parsed yeah because it doesn't look too easy here so that's how you can extract the text somehow what I did now in a project and this again I don't claim this is the perfect way to do it but I wanted to see if a certain piece of text was present um and what I basically did for that is I wrote a function called is text present and you got you got to be a little bit um I don't know if messy is the right word you got to be flexible with that because you basically have to say often times it's going to find something and you need to make sure that uh something that it finds somewhere in the image is not necessarily text and that you have a certain threshold for how much text you need for uh for for the reader to consider it present so we're going to pass an image path here and basically I do the same thing I have this function I basically pass the image path and then uh what I do is I basically say if the length of the result is greater than and then uh or actually we could do that I think makes more sense to maybe do that with a text or actually let's do it like that I can just say if the length of the result is larger than something then it found a couple of segments so I'm considering it a text the easy way is to do just above zero this is a safe one otherwise you can also just extract a text by iterating again and saying okay I need to have at least uh 20 characters for it to be considered text or five characters or something like that but in this case we can just say return true or actually to make it easier just return the truth value of this comparison um and yeah basically then you have this function that when you call it will give you the information if a text is present in an image bad one jpeg for example and in this case it should give me true for all of them but if I have an image that doesn't contain any text it should hopefully give me false and it did that in the project that I'm working on right now so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you on the next video and bye that
Info
Channel: NeuralNine
Views: 11,405
Rating: undefined out of 5
Keywords: ocr, python, python ocr, ocr python, python easyocr, optical character recognition
Id: GboDfGzkRsQ
Channel Id: undefined
Length: 7min 14sec (434 seconds)
Published: Thu Dec 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.