Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which library to use to extract text from images?

I am writing a program that when given an image of a low level math problem (e.g. 98*13) should be able to output the answer. The numbers would be black, and the background white. Not a captcha, just an image of a math problem.

The math problems would only have two numbers and one operator, and that operator would only be +, -, *, or /.

Obviously, I know how to do the calculating ;) I'm just not sure how to go about getting the text from the image.

A free library would be ideal... although If I have to write the code myself I could probably manage.

like image 864
Entity Avatar asked Feb 28 '11 19:02

Entity


People also ask

Which of the following is used to extract image text?

OCR stands for Optical Character Recognition. It is a technology that recognizes text within a digital image.

Which Google application can extract text from an image?

Google Lens is also available in the camera, where you can extract text right there. When you open the camera on your Android phone, slide the options, go to Modes, and find the Lens in the list. Tapping it will open the Google Lens for you, using which you can take a photo and run the text extracting process.

Can I extract text from a JPEG?

You can capture text from a scanned image, upload your image file from your computer, or take a screenshot on your desktop. Then simply right click on the image, and select Grab Text. The text from your scanned PDF can then be copied and pasted into other programs and applications. How can I copy text from an image?


1 Answers

For extract words from image, I use the most accurate open source OCR engine: Tesseract. Available here or directly in your packages NuGet.

And this is my function in C#, which extract words from image passed in sourceFilePath. Set EngineMode to TesseractAndCube; it detect more word than the other options.

var path = "YourSolutionDirectoryPath";
using (var engine = new TesseractEngine(path + Path.DirectorySeparatorChar + "tessdata", "fra", EngineMode.TesseractAndCube))
{
    using (var img = Pix.LoadFromFile(sourceFilePath))
    {
        using (var page = engine.Process(img))
        {
            var text = page.GetText();
            // text variable contains a string with all words found
        }
    }
}

I hope that helps.

like image 74
Loïc Sombart Avatar answered Oct 09 '22 13:10

Loïc Sombart