Ocarina - Optical Character Recognition (OCR) for Ruby
A Ruby project that uses machine learning to perform Optical Character Recognition.
I created this project to learn Ruby beyond what you need for Rails, and also just to see if I could actually create an OCR lib. It started as kind of a toy program, but quickly grew into something with a practical purpose (decoding Letterpress gameboards!)
It works fairly well on constrained input, but it's not really intended to be a production-level OCR package.
Ocarina successfully trains and recognizes the 26 letters of the alphabet. Once trained, the network accurately recognizes its training set and also recognizes characters with added noise.
I'm still working on how best to organize the neural network (# of hidden nodes, # of outputs, edge weights) to increase the set size to support the full ASCII (and beyond) alphabet.
I first encountered OCR technology back in 1991 or so, on an Apple Macintosh. It seemed like magic, even though it was a pretty poor implementation by today's standards. Recently I came across the Sudoku Grab app. It does OCR very successfully, albeit on very constrained input images.
This inspired me to try to create my own (simplistic) OCR implementation, and that seemed like a great way to learn Ruby.
Ocarina depends on ImageMagick (and the RMagick gem) to do its graphics processing. On OSX at least, ImageMagick requires X11 and ghostscript. You'll likely need to do the following:
- Download and install X11Quartz
brew install imagemagick
brew install ghostscript
For Linux (I'm on Centos 5.8) I had to build ImageMagick 6.8 from source, install it, install the source into /usr/local/src/ImageMagick-6.8.0-4/magick and then run:
add /usr/local/lib to the system LD_LIBRARY_PATH
gem install rmagick
To train on bitmaps created with ImageMagick:
You can also train a network to recognize Letterpress tiles:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
Copyright 2012 George Armhold
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.