Making an OCR with no dependencies in PHP

6

I have a project where people do schedule quotes for Tumblr. Today it works from the Kindle and I'm already seeing the Kobo files. But today I ask for help for the third part: I would like to add an OCR reader , so that the person could upload a photo, the reader would extract the phrase and the person could add in the sentence publishing queue .

I'm pretty much a beginner in PHP and I suffer a bit, and researching was not very successful. I found a plugin that identifies only letter by letter or a plugin that needs to run exec , which is not interesting because the person may not have the program installed and for obvious security reasons.

Should I try to do this with another language? I'm betting on PHP first because I have a base, then because the project is done in php, my hosting is php and because I know it has a library to handle images, so I assumed OCR would not be that far.

Do you have any plugins or tutorials to indicate?

    
asked by anonymous 20.08.2014 / 19:19

3 answers

5

If you have the possibility to install it on your server, Tesseract is an opensource OCR engine made available by Google . It has a wrapper for PHP .

Otherwise, you can try webservices like Google Docs OCR .

    
20.08.2014 / 19:25
2

You can use the php OCR class. which makes learning and recognizing text in images completely in PHP, so you do not have to install anything on your server.

    
21.08.2014 / 06:37
2

Hmm without having an image processing module for PHP installed on the server you will suffer a little, take a look if the place you host has the module ImageMagick , create a phpinfo(); just to check what modules have installed for your PHP. If ImageMagick is available things improve but they do not get any less complicated.

I can only guide you with the necessary steps, I do not know if something is ready, the challenge seems to be more interesting than simply copying something from someone, you will need some mathematical knowledge, linear algebra and if you want a really close algorithm of perfection will need neural networks.

Let's start with the most basic method possible:

  • Create vectors with the patterns of all letters and numbers, you'll need to cut out each letter and number, extract the pixels of each, use ImageMagick if available, store as you see fit (txt, mysql).
  • Now you already have the basis for comparison, you will want to compare sentences / texts / words with the extracted patterns, once again use ImageMagick to cut out each letter of your texts, computationally speaking you will be comparing each pixel horizontally until we find the beginning and end of each letter, we are talking about something basic here, so 99% of the texts are in black with white background, so walk until the white pixel finish mark the position and walk until the black pixel finish mark the position, this will tell you where to cut each letter or number (start and end).
  • Perfect trimmed the letter of the text, now extract the pixels of it, as well as the first step to build your bank.
  • Now compare what was extracted from the text with your database, in linear algebra has a concept called espaço linear in this case we will have which pixels appear more frequently, it is a simple way that can be used to mensural which is the most similar letter.
  • Assemble each word based on this rank (the higher the cosine returned by the better linear space)
Well here's a basic way to build an OCR with your own hands, without relying on third-party modules (except for ImageMagick, used here to crop and extract pixels).

    
21.08.2014 / 16:51