Preparing content for recognition

Aspose.OCR for Java provides a versatile way to prepare your content for OCR. A package of recognized files/directories/URLs, regardless of their number and type, is constructed as an instance of the OcrInput class. With this approach, you can easily process a single image or a large number of images from an auto-feed scanner in a single API call.

The object constructor takes the type of the provided content and optional processing filters that will be applied to all images in a batch.

Supported content types

You can only pack sources of the same type into one instance of the OcrInput class. The type is specified in the constructor and cannot be changed later.

Source content type Supported file formats
InputType.SingleImage One or more GIF, PNG, JPEG, BMP, or single-page TIFF images. The images can be provided by their absolute or relative paths, as BufferedImage objects, or as arrays of pixels.
You can add images of different types in a single batch.
InputType.PDF One or more PDF documents, containing scanned pages. The files can be provided by their absolute or relative paths or as BufferedImage objects.
InputType.TIFF One or more multi-page TIFF images. The files can be provided by their absolute or relative paths or as BufferedImage objects.
InputType.DJVU One or more DjVu files, provided by their absolute or relative paths or as BufferedImage objects.
InputType.URL One or more web links to GIF, PNG, JPEG, BMP, or single-page TIFF images. Aspose.OCR for Java will download them automatically before processing.
**Limitations:**
  • Aspose.OCR for Java does not support authentication and can only work with public URLs.
  • The URL must point directly to the image. Aspose.OCR for Java cannot extract images from HTML pages.
InputType.Directory Absolute or relative paths to one or more directories containing GIF, PNG, JPEG, BMP, or single-page TIFF images. Unless specifically configured, all nested images will be recognized.
Subdirectories and nested archives will not be processed!
InputType.Zip Absolute or relative paths to one or more ZIP archives containing GIF, PNG, JPEG, BMP, or single-page TIFF images. Unless specifically configured, all archived images will be recognized.
Nested archives and directories will not be processed!
InputType.Base64 One or more GIF, PNG, JPEG, BMP, or single-page TIFF images provided as Base64-encoded strings.

Adding source content

To manage a batch of images, scanned PDFs, URLs, directories, and other OCR content, use the following methods of the OcrInput class:

Method Description
add(string) Add an absolute or relative path to a file/directory, or a URL to an image file on the web.
add(string, int, int) Add an absolute or relative path to a multi-page image, PDF document, ZIP archive or directory, specifying the images/pages for recognition.
add(BufferedImage) Add a BufferedImage object, containing a file to be recognized.
add(BufferedImage, int, int) Add a BufferedImage object, containing a milti-page image, PDF document, or ZIP archive, specifying the images/pages for recognition.
add(InputStream) Add a InputStream stream, containing a file to be recognized.
add(InputStream, int, int) Add a InputStream stream, containing a milti-page image, PDF document, or ZIP archive, specifying the images/pages for recognition.
add(int[], int, int, PixelType) Add an image provided as an array of pixels. You must specify the width, height and the color depth (number of bits per pixel).
addBase64(string) Add an image encoded as Base64 string.

To get the number of items in the batch, use size() method of the OcrInput class.

Removing source content

To clear a batch, use clear() method of the OcrInput class.

Applying image processing filters

The accuracy and reliability of text recognition is highly dependent on the quality of the original image. Aspose.OCR for Java offers a large number of fully automated and manual image processing filters that enhance an image before it is sent to the OCR engine.

To apply processing filters to all images in the batch, provide them in the OcrInput object constructor, or later using replaceFilters() method.

To remove all processing filters from a batch, use clearFilters() method of the OcrInput class.

Examples

The following code samples demonstrates how to prepare content for recognition: