Wednesday, 6 February 2013

Terminal Idiot! (I have OCD wrt OCR)

A work-related issue managed to intrude on my Linux conversion studies.  I ended up with a 2003-dated document that needed reformatting and significant updating.  I knew I needed employ Optical Character Recognition to convert the document, or I'd be copy-typing into the early hours (Warning! Education Inbound! It's commonly referred to as OCR - where the system looks at the letters in a printed document and converts them into a computer file).

I ended up booting up my PC in Windows for the first time in ages...  I have to explain that justification for reverting to my old operating system is because I have an HP wireless printer that I have not installed in Ubuntu.  So the only way that I thought I was going to convert the document was with the installed HP drivers I had on Windows.

So I boot up the PC, go to the printer applications... and there's no OCR function!  The first time I use Windows in some time and the application that I took for-granted would be there, wasn't - I even visited the HP site for my printer and couldn't find an application that would do what I wanted.

Having now become an Ubuntu evangelist, I restarted the machine, entered Ubuntu and went to the Software Centre.  There I found XSane, which appeared to do everything I wanted.  With more joy than I can state about my operating system choice than I can mention, I happily installed the app and fired it up.

I was overjoyed that Ubuntu recognised my printer (I had to do a wired connection - I didn't have time to work out how to set it up a wireless).   So I scanned the first page and pressed the OCR button...  And then I encountered an error saying I didn't have 'gocr'.  Now my total ignorance kicked in.  I read that as 'I didn't have "go-cr" installed'.  Having a newbie panic attack, I clicked buttons left, right and Chelsea to no avail.  So if in doubt, Google it!

Did I feel like a total dork when I realised this was a command line application?  (Answer - Yes!)

So here was the first time that I had to enter the Terminal in anger.  I opened the terminal and tentatively typed the letters 'gocr'.  Again, this was a moment of shock at how user-friendly Ubuntu is, even in the Command Line.  It told me that 'gocr' wasn't installed, and then told me how to use the command line to download it!  I faithfully followed the instructions - and BINGO - successful installation of 'gocr'.

Feeling more pride than was right, I revisited XSane and tried to use the OCR.  And it worked...  Sort of...  Well, it worked to the sense that maybe 1 in 4 characters were recognised.  The one page I scanned looked like a cross between a computer crash that had been translated into Arabic with the random English word thrown in.

I was certain that I had some of the scanning settings incorrect, so up'ed the scan resolution, changed the file type, full colour, monochrome... every option that I thought was open to me, I changed...  But I was still presented with total gobbledygook.  Clearly it was time to revisit Google.

Here I found a reference to another command line operation I could use - this time 'tesseract'.  Again, just by typing the command, I was told how to install it.  So I did.  This application enables you to OCR .TIFF documents.

Well, I knew that XSane would scan a page to make a .TIFF, so I could use 'tesseract' to OCR such files.  I also knew from a manual I downloaded to my Kindle (I told you I was a gadget geek) that one of the advantages of using the command line was that you could batch process files (Warning! Education Inbound! To perform actions to multiple files with a single command).  So I scanned the document as separate .TIFF files.

The first problem I encountered was how to change directory in the Terminal...  Remember, the last time I used a command line was in MS-DOS.  I soon learned how to do it, then tried a batch conversion.  So I then typed 'tesseract *.tiff *.txt'... and was told that I had entered the command incorrectly.  I tried a couple of variations of typing the command, but nothing worked.  (Caution! Question Incoming!  If you can tell me what I did wrong, I would love to learn what to do next time.)

So I had to resort to converting each file one at a time... and it worked!  Sure this was not the most efficient way of doing it, but it worked and saved me the hours it would have taken to copy-type the document.

So, I'm no longer scared of playing with the Terminal.  I've learnt I can do it without the PC blowing up.  I can do it, albeit inefficiently, but get my work done faster than I would have done in Windows.  I know that I have more to learn - but then again, name a new Linux user that doesn't.  But again, I encountered a problem and ended up enjoying learning how to fix it - and delivered something to my workplace that would never have happened if I hadn't started this journey.

Sure, at times I feel frustrated - but I'm getting the job done faster than I would have if I hadn't started it.  This is turning into something that is not only teaching me, but it's teaching me there is a far better way to get stuff done - even when you're making novice mistakes that I'm making.

No comments:

Post a Comment