Invoking Shell commands from Python – SyedTips – 6

While building an ALPR (Automatic License Plate Recognition) System on a Raspberry Pi in 2013, I came across tesseract  which is a very powerful OCR (Optical Character Recognition) tool.

Tesseract is a command line tool which means it has to be invoked as a command from the shell/terminal (and it works on both Windows and *nix):

tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfiles...]

Since my main image capture and trim script was based on Python (triggered from a WebPage), I had to find a way to invoke tesseract from within Python. At first, I looked out for python libraries and wrappers of tesseract and had a hard time getting them to run on the Raspberry Pi.

Eventually, I wondered if there was a way to invoke shell commands from Python; and yeah!

Using subprocess, you can do just that:

import subprocess
subprocess.call(["tesseract", "/home/pi/syed/Image.png", "/home/pi/OpenCV/OCR_Data"])

Pass each argument to the invoked command separated with , in “”

Thanks.

Learning Python the Hard Way :)

After getting the RasPi, I was all the more excited to learn Python. I started it from this link
http://learnpythonthehardway.org/book/

I’m currently in Exercise 22 which asks us to rewind what we’ve learned so far. So I made these notes and will post here for my quick reference.

# Ex 22

Asks to go back and revist all the symbols and words and understand what they all do..

I’m’ gonna begin from ex1

Continue reading “Learning Python the Hard Way :)”