 Today we're going to be looking at the command line and we're going to be looking at OCR applications. OCR, I believe, stands for Optical Character Recognition. Basically this allows you to take images that have text in them and convert them to actual text that you can highlight, copy and search through. That's not a perfect solution because there's so many different fonts out there and text can be so artistic in some ways with the different fonts. But if you have a very simple text you can get a halfway decent output with some of these programs. We're going to look at three of them today. I'll look at ways of getting better results out of them and then pick one that I think is best and from what I've read people seem to like the best. All three are open source and all three are in the repositories for probably all Debian based distros. Right now I'm working in Linux Mint, an older version. I can't remember if I'm on 10 or 11 right now so I'm a little bit behind in updating my desktop but I've already got them installed. Just use your package manager to install them if you have not already installed them. First what we'll look at is G OCR and I believe there is also a graphical interface for this one. Let's have a quick look at the man file for this. Just glance at it real quick. This one right here says that files should be in a PNM format but it also says depending on your system. Actually it works with PNM, PGM, PBM, PPM and PCX. These are formats I'm not too familiar with but luckily with image magic which is installed on most Linux distros by default and if not it's definitely in the repositories for almost all. You can convert to those formats but it also says this program if you have the right dependencies installed you can also work with more common formats such as GIF, JPEG, TIFF and bitmap, PNG, so forth so on. Just looking at this quick little synopsis here. We got the name of the program, any options you want, dash i for input and then the input file. Let's go ahead and give that a trial quick. First off I'm going to show you the image I have. It's a not very high resolution actually rather low. A little advertisement I got off Facebook for free Sundays over at Chick-fil-A which are delicious. So we're going to see what we can get out of this image here. It's called JPEG one in this case. Let's go G-O-C-R and we'll say dash i for input and the image and there we go we've got not too good of results. Okay not great. Completely unreadable. But in a minute we'll look at things after we look at the other two at increasing our output accuracy. Next one we'll look at is OCRAD. I'm not sure how you pronounce that. OCRAD maybe? Or maybe you just read out the letters. I don't know. Anyway let's look at the man file for that. So basically we got the program, any options and the file name. Looking through here it says it only reads PNM files. So let's go ahead and use convert which is part of the image magic package. So if you don't already have it installed just install image magic but you probably already have it installed. We'll say the original file and then we'll say the output file will be one dot PNM I think we said it was. NM I think. And if we display that out you'll see that the image pretty much looks the same. It's just now in a format that this program can read. So we'll just do that and we'll say one dot PNM hit enter and we still get rather poor results. Next one is called Tesserac and it's Tesserac dash OCR I think in the repositories once you install it's just Tesserac. Let's look at the man file for that. This one says it works with TIFF files which is more common format but probably not as common as PNG or JPEG. So we're still probably going to be converting most of the time. And as it says here and also we'll look at this little page on Google codes here is that it was a proprietary program back in the mid 90s and rated as in the top three engines back in 95 for doing this converting images to text. Since then it kind of its development kind of slowed down when open source and kind of became live again. That happens quite often look at Blender. Blender was a proprietary program that was dead. I forget what it was originally called I believe it was owned by NeoGeo when open source and now it's growing like crazy. So let's see what results we can get from this. So first also on this page here I just want to mention somewhere somewhere. Let's go format. Right here it says it can read a wide variety of image formats and convert them to text. The version I have I believe only reads TIFF. That's what the man file says and I think I've tried other ones that didn't work. But once again not a problem we'll just convert our original JPEG image to a TIFF format. Once again we could display that out you'll see that it looks pretty much the same as it did before but we'll use Tesserac and I think it's well look at the man file if I get this wrong but I think it's the input file and I'm not sure if there's a way to put this to standard output but I'll just put output as an output and hit enter here and now let's cat out they put it into this file and we got hmm okay we got some readable words here free but mmm Sunday when you say 61 semi phrase so we got a little bit better results with this already but still not really usable. So what can we do about this well I found that if you simply which this doesn't make too much sense to me you increase the resolution of the image you get better results even though you're working you're just taking a lower quality and increasing the resolution I don't see why that makes a difference but it seems to and of course we can use convert for this too. So let's go convert and we'll give it the original file of uh j one dot jpeg and we'll say resize that's dash resize and we'll just give it 1000 to start off so we're just making uh increasing its size which I'm not sure what the size is but not 100 it's probably like 200 or 300 as far as the width and height um and uh and giving it just one number will increase the size without distorting the aspect ratio of it and we'll just give it an output of one dot tiff automatically overwrite the last one which means we can run the same uh output again so tesseract one dot tiff output and then we can cat out our output file and you can see hey we're getting some better results so here it was at the original resolution somewhat getting some words there and here it is at the higher resolution free brownie sunday when you say the still getting a little something oh secret phrase i think it's a new line there you do get some excess characters here and these are from non-text things in the image um secret phase uh phrase and then also here we almost have top all sundays they put in a zero there instead of an o and then we kind of lose it here a little bit so let's let's try it again let's um increase the resolution to 5000 a little bit longer to convert there we'll now run the output again and we will cat it out oh good we're getting it top oh we got top correct here top all sundays start from the brownie up one person from three to seven p.m so let's uh display our original image again and lo and behold besides the extra little things in here that are because it's trying to read things that aren't text in here we got pretty decent results there you can now script through this and remove anything that aren't actual words um you can also crop the excess stuff out of the image but depending on what you're doing that may defy the whole purpose of this point of this so now that we've increased the resolution let's try that with the other applications and see if we get as good a results as tesseract so what i'll do here is i'll say convert one dot jpeg um dash resize 5000 and i'll make a two dot jpeg and then let's go to um g o c r okay run same commanding sword or sorry i said j g o c r and dash i and we'll give it the new jpeg image yeah see still not as great of results okay so let's do this again we'll convert the original and this time we'll put two dot uh p n m and we will o c r a d and this time we'll give it the new higher resolution see how that outputs slightly better results than we originally with that program but as you can see so far tesseract seems to be the best as far as accuracy by far so i recommend checking this out it is open source um i want to say it's under the apache license not gpl oh no no wait yeah no that's a different program it's mentioning there uh yes it's under the apache to license so it's open source not gpl but still good thing check it out and as i showed you increasing the resolution using convert which you're probably converting if it only takes tiffs which it seems to um gives you great results so if you have any other open source ocr programs because i think there's a few other but those are the top three i came across uh go ahead and uh post your response in the comments also uh you know if you have any other ideas of using image magic or something for the command line that you can automate this and get better results that be great but uh right now i think that's the way i'm doing it i'm getting all the words just with some excess as far as the rest of the image so definitely could take a whole library full of images and do a word search through them so i hope you found this tutorial useful if you were looking for something like this i recommend you give all three programs look at but for me test rack and from what i've read is usually the best out of the three uh i thank you for watching please visit my website it's filmsbychrist.com that's chris of the k should be a link in the description there you can find uh videos uh scripts and programs and music by me um also some funny images there under photos um also if you have any comments feel free to comment below if you have any questions uh don't put them in the comments below because or at least i won't be answering them maybe someone else will answer you go to filmsbychrist.com forward slash irc or if you just go to filmsbychrist.com on our main page there's a help button that will take you to the irc channel there's a great place to ask me and other people questions don't come in there ask a question and expect to answer right away sometimes it takes a little bit for one of us to answer so don't come in and exit come in stay around while ask some questions um and uh also if you like my videos if you enjoy them and you like my site and everything i have up on there uh help support the site there is a donate button on my website thank you for watching and i hope that you have a great day