Skip to end of metadata
Go to start of metadata
Contents Summary
  

Performing OCR on an Image

Aspose.OCR for Java provides the OcrEngine class to perform OCR operation on images. The OcrEngine class only requires setting the Image property for the English language as English is the default language. Languages other than English also requires loading the language-specific resource using the LanguageFactory.load method and adding it to the LanguageContainer using the addLanguage method. Please check the detailed article on Working with Different Languages.

Performing OCR on an Image steps

Here are the simple steps to perform the OCR operation.

  1. Create an instance of OcrEngine and initialize it using the default constructor.
  2. Set the image file on which OCR is to be performed using the OcrEngine.Image property.
  3. Call the OcrEngine.process() method to perform OCR on the whole image.
  4. If OcrEngine.process() method returns true, get the recognized text with the OcrEngine.Text property.

Programming Sample

Below provided code snippet demonstrates the usage of OcrEngine class as discussed in above-mentioned steps.

Perform OCR Operation on a Multipage TIFF

Aspose.OCR APIs provide the functionality to perform the OCR operation on a multipage TIFF containing several frames/pages in a single run. This article describes the usage of Aspose.OCR for Java API to accomplish this task with minimum source code statements as demonstrated below.

Performing OCR on a Multipage TIFF steps

Performing the OCR operation on a multipage TIFF image is more or less the same as described in the article Performing OCR on an Image with two main differences as detailed below.

  1. Before calling the OcrEngine.process() method, we need to tell the API to process all the available pages of the input TIFF image by using the OcrEngine.ProcessAllPages property. Setting the aforesaid property to true directs the OcrEngine to process all pages when OcrEngine.process() method is called.
  2. After calling the OcrEngine.process() method, retrieve the Page collection using the OcrEngine.Pages property, where each individual page contains the recognized text from an individual TIFF page/frame.

The OcrEngine.Pages property has to be accessed after calling the OcrEngine.process() method otherwise it will cause the OcrException.

Below provided code snippet demonstrates how to process multipage TIFF using Aspose.OCR for Java API.

Programming sample

Extracting Text from Part of an Image

Aspose.OCR for Java provides OcrConfig class that can be used to extract the text from a specific part of the image document. The OcrEngine class requires setting the OcrEngine.Image property and adding custom recognition blocks to the OcrConfig class.

Languages other than English also requires loading the language-specific resource using the LanguageFactory.load method and adding it to the LanguageContainer using the addLanguage method. Please check the detailed article on Working with Different Languages.

Getting Values to Define Recognition Block

Text Recognition Block can be created using CreateTextBlock method. It takes four parameters namely:

  1. X – Coordinates
  2. Y – Coordinates
  3. The width of the Area
  4. The height of the Area

There are different software that provides the information about the X, Y Coordinates, Width and Height of the area selected on the image. Microsoft Paint and TechSmith Snagit are examples of such software. If we consider MS Paint software then following are the steps to get the above-mentioned information:

  • Open the image in MS Paint
  • Pick the Selection Tool from Home tab on the top.

    This tool will help you to select the part of the image.

  • While using Selection Tool, look at the left down corner on the Status Bar. You will be able to find the X, Y Coordinates.
    The very next will be the Width, Height information of the selected area on the image.

Extracting Text from Custom Recognition Block

To run OCR on an image using the OcrEngine class:

  1. Create an instance of OcrEngine and initialize it using the default constructor.
  2. Set the image file using the OcrEngine.Image property.
  3. Set the start point, width and height of the recognition block using the OcrConfig.addRecognitionBlock method.
  4. Set the OcrConfig.DetectTextRegions property to false so that OcrEngine could ignore everything else on the image.
  5. Call the OcrEngine.process() method to perform OCR operation.
  6. If OcrEngine.process() returns true, get the block information from the OcrEngine.Text.PartsInfo property.

The sample code given below shows how to use the steps discussed above to perform OCR operation on different parts of an image.

Programming Sample

Load Image from URL to Perform OCR

Aspose.OCR for Java provides the OcrEngine class to perform OCR operation on images that may be available locally or remotely. This article will provide information about how an image can be loaded using a URL.

Performing OCR on an Image from URL

Here are the simple steps to perform the OCR operation.

  1. Create an instance of OcrEngine and initialize it using the default constructor.
  2. Set the URL from which image is to be downloaded and OCR is to be performed using the OcrEngine.Image property.
  3. Call the OcrEngine.process() method to perform OCR.
  4. If OcrEngine.process() method returns true, get the recognized text with the OcrEngine.Text property.

Below provided code snippet demonstrates how an image can be loaded from a URL.

Programming Sample

Labels
  • No labels