Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python OCR : Converting Scanned Image Into Text For Processing

I am trying to create an answer paper marking (multiple choice question) python application. The answer sheet will be scanned into image file (gif,png,jpg,whichever format is needed).

My App has access to the database where all the answers are stored.

So,all it need is some kind of data from scanned image so that it can compare the answer and calculate the marks.

The answer sheet has fixed dimensions with the table format like this ( Answers will be marked by 'X' by the candidate to indicate their answers):

enter image description here

After searching through the internet, i found that there are a few OCR APIs available.

First one is Pytesser . It is very easy to use and the results are quite okay. But it only work for the images with just pure texts. So, i think it is not suitable.

The second one i found is Ocropus. It seems powerful but in it's documentation

Windows

OCRopus relies a lot on POSIX path names and file systems. You may be able to install OCRopus on Windows using . An easier way is to install VirtualBox and run OCRopus in Ubuntu under VirtualBox.

So i think it is mostly for linux. I could not find a detail installation guide for window platform. ( I am a beginner, so i could be wrong)

The third one i found is python-tesseract , a wrapper for Tesseract OCR. In their page, the installation guide was provided. Basically, i need,

  1. python-tesseract-win32.deb
  2. python-opencv
  3. numpy

but i have no clue on how to install .deb files on window. I have the opencv and nampy already installed.

So the following are my questions:

(1) In which way can i convert the table image into processable data(is it even possible?)?

(2) Is there any other useful OCR APIs that i have not mentioned here that could be helpful?

(3) Finally, (my silly idea) Is it possible to split the image into small chucks(based on the size of the table cells - since the table dimensions are known) using PIL and then use pytesser to convert each small images into text, thereafter process the data accordingly?

FYI: I only need it for Windows Platform, possibly for windows xp 32 bits. I am using python 2.7.5.

like image 961
Chris Aung Avatar asked Nov 20 '13 12:11

Chris Aung


People also ask

How do you extract text from an image using Tesseract OCR engine and python?

Create a Python tesseract script Create a project folder and add a new main.py file inside that folder. Once the application gives access to PDF files, its content will be extracted in the form of images. These images will then be processed to extract the text.

Is Tesseract good for OCR?

Tesseract does various image processing operations internally (using the Leptonica library) before doing the actual OCR. It generally does a very good job of this, but there will inevitably be cases where it isn't good enough, which can result in a significant reduction in accuracy.


1 Answers

Answers correspond to your numbers

1) OCR is in general very hard, but (good news for you) for test score processing, I think it is nearly a solved problem. In this vein there are tried and true solutions for such problems. School systems have been doing this to automate grading 'scantron' tests for years, so if you have access to such resources going that route might be your best bet. At least you should check how they do it

2) I am sure there are others, but those are the main free ones I know of

3)a I think if you are trying to do this on a budget and time is less an issue, your 'silly' idea is actually not silly at all. It might be the best way to do it, and it is likely that the scantron test graders use a similar method. You know the exact dimensions of the test form. You can know the direct pixel mapping of where to look. You could use pytesser very easily. Keep in mind that pytesser sometimes needs you to resize the image (sometimes up, sometimes down) to get the best accuracy.

3)b You might want to consider rolling your own solution. You could use the concept of morphological operations (numpy and other image libraries can do this nearly out of the box). You might not even need these operators and simply do a binary threshold of the table rows (assuming you have already cut the image into table rows) and simply look for blobs and mark the score as coming from the column with the most blob values.

like image 157
Paul Avatar answered Sep 26 '22 01:09

Paul