Package: ocr-testbed
# OCR ProjectThe purpose of this repo is to construct an ocr for detecting keywords frompeople's handwriting to make their notes searchable.Whole sentences do not need to be fully extracted, as long as a few uniquekeywords are extracted such that the extracted set of words are seo-able.## EnvironmentThis package was developed in the following environment.- Python 2.7.9- Mac OSX 10.11.4, Ubuntu 14.04- pip 8.1.1## DependenciesThis package is dependant on the packages provided in requirements.txt.- numpy- scipy- matplotlib- cv2Optional development packages to install are provided in dev-requirements.txt.Precompiling the pure code with cython can allow for an extra boost inperformance.### OpenCVThis package is heavily dependant on opencv, so be sure to install it firstbefore installing the cv2 package in requirements.txt.- [Installing on Ubuntu/Debian](http://milq.github.io/install-opencv-ubuntu-debian/)- [Installing on Mac OS](http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/)### Scikit LearnIf using the multilayer perceptron, the latest dev version of scikit learn(0.18.dev0) is required since it already contains an implementation of amultilayer perceptron that this package uses.At the time of writing this, version 0.17.0 is provided on pypi, so this devversion cannot be installed via pip and will have to be installed by cloningthe [repo](https://github.com/scikit-learn/scikit-learn) and just followingthe instructions in the repo for installing it.### TroubleshootingIf you have trouble installing numpy, scipy, or cv2, try installing themindividually instead of together in the requirements.txt.If you have trouble installing them in a virtualenv, try installing them onyour global pip instead.## InstallingAfter cloning the repo, just run the following:```sh$ python setup.py develop  # Create executables```To make the ocr packageglobally availale on your computer via pip:```sh$ python setup.py bdist_wheel  # Create binary distribution$ wheel install dist/ocr-{version}-py{2/3}-none-any.whl  # Install created wheel$ wheel install-scripts ocr  # Enable package scripts````The first command with `develop` essentially does the same as the followingthree commands, but these commands allow for the package to be availableglobally through your computer in pip space like any other package installedvia pip.## UsageThe package can be used to create classifiers and use these classifiers toclassify characters extracted from an image.Before extracting text from an image, you will need to create a classifier to classifyeach character extracted from the image.### K Nearest NeighborsCreate a knn classifier using handwritten training data in the given dir and save itin a file called classifier.p.```sh$ knn-create -t handwritten -d data/training/handwritten -s classifier.p53.2258064516 %  # Success rate on testing data```Extract text from the given image using the classifier we just made. Resize the imageto reduce computation time.```sh$ knn-extract data/test/sample3.jpg -p classifier.p --resize 0.256hhVL tS L mUYh kYttrYYr 6b h qYhcY  # Yeah, this isn't very good output```### Multilayer PerceptronCreate an mlp classifier using shrinked, handwritten training data in the givendir and save it in a file called classifier.p.```sh$ mlp-create -t shrinked -d data/shrinked20x20/ -s classifier.p63.3431085044 %  # Success rate on testing data```Extract text from the given image using the classifier we just made. Resize the imageto reduce computation time.```sh$ mlp-extract data/test/sample3.jpg -p classifier.p --resize 0.25iYYij jY N CjYj iYjV1Y1L 1j Y YYLG1  # Yeah, this isn't very good output```## DevelopmentTo develop/test other classifiers, you would just need to create a classifierwrapper from `ocr.classifiers.base.Classifier` and create an extractionscript that uses this classifier to get text from an image.Example usages of this are in the KNN and MLP Classifiers in ocr/classifiers/and examples of implementing the extraction script are in scripts/.## ResultsThe package functionally works in that it can create and train classifiers, and usethese classifiers to extract text from images, but this package does not work in thatthe correct text is extracted. The following are ways to improve performance:- Better sample data- Better features- Only the individual grayscale pixel values are used as featues. Alternativefeatures that should be experimented with include:- Number of edges on each character- Number of circles on each character- Projecting each character onto the x and y axis and using the distributionsalong each axis as featues.- Smarter character region finding in an image.For now, this package works best as a testbed for experimenting with differentclassifiers and features.## TODO- Update unit tests.- Make presentation.