Introduction: ANPR Project Using the Intel Edison
This is an Automatic Number Plate Recogniton Project using openCV and the Intel Edison board.
An Overview:
Capture an Image,pre-process it in opencv then pass it through tesseract OCR to get the characters in the image.Then display the characters on the grove LCD screen.
Steps:
1.Installing OpenCV on Edison
2.Installing Tesseract-OCR on Edison(the optical character recognition engine we're using)
3.Pre-processing plate image on OpenCV
4.Passing Plate image to tesseract OCR engine to obtain characters.
5.Display the plate characters on an LCD using libmraa
Step 1: Installing OpenCV on Edison
Install the latest IoT Developer Kit Libraries
echo "src intel-iotdk http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf
Update the package repository, then upgrade all the packages:
opkg update
opkg upgrade
Add unofficial repository
Access to every package is not available without adding repository locations to the opkg/base-feeds.conf file. By doing this, you’ll add an enormous number of compiled applications, saving you the hassle of compiling from source.
vi /etc/opkg/base-feeds.conf
and paste in
src/gz all http://repo.opkg.net/edison/repo/allsrc/gz edison http://repo.opkg.net/edison/repo/allsrc/gz core2-32 http://repo.opkg.net/edison/repo/allsrc/gz
Then hit your Escape key and type :wq to save and exit from vi
Update the repository index again, since you just added new package locations: opkg update Next, install NumPy, OpenCV, and OpenCV-Python.
opkg install python-numpy opencv python-opencv nano
Step 2: Installing Tesseract OCR on the Edison:
Install python setup tools to get pip,easy_install et al
opkg install python-setup tools
Install PIL(Python Imaging Library)
pip install pil
Install tesseract-OCR and imagemagick
opkg install tesseract-ocr imagemagick
imagemagick is needed for converting the files from .jpg to .tiff format that tesseract can process.
Install pytesser
https://code.google.com/p/pytesser/downloads/detai...
Step 3: Processing the Image
Now in your python file you will just be required to import the required files from PIL and tesseract and you are SET
from PIL import Image
from pytesser.pytesser import *
Pre-Process the image using OPENCV algorithms to make it suitable for tesseract OCR:
A. Resize image so that it doesn't take too much processing power:
original = cv.LoadImageM("plate.jpg") resize = cv.CreateMat(original.rows/ 10, original.cols / 10, original.type) cv.Resize(original, resize)
B. Convert to GRAYSCALE
CvtColor(original,gray,CV_RGB2GRAY)
C.Apply threshold I.e binarize the image resized
cvThreshold(image, binary_image,128,255, CV_THRESH_OTSU)
the above step returns a binary image which is adaptively thresholded. The arguments follow the order:1. Source image, 2. Destination image, 3. Threshold value,4. Resultant value, and 5. Type of threshold. Play around with the threshold and resultant values till you get the right fit.
Step 4: Recognize Characters Using Tesseract Engine:
Pass the image processed from opencv to your tesseract method.
You will have to convert it to a .tiff file first..this is done using PIL:
from PIL import Image img = Image.open('image.jpeg') img.save('image.tiff')
Then pass it through the tesseract ocr engine which will recognoze images and return the characters:
from PIL import Image from pytesser.pytesser import *
img = Image.open('plate.jpeg') img.save('image.tiff') im = Image.open(img) text = image_to_string(im) text = image_file_to_string(image_file) text = image_file_to_string(image_file, graceful_errors=True) print "=====output=======\n"print text
From there on use the libmraa libraries to print the plate character to an LCD screen..Refer to this link to set up the Grove LCD to display the plate characters.