Aspose.OCR for Java 22.8 - Release Notes

What was changed

OCRJAVA-268Added support for text recognition from images provided as an array of bytes.New feature
OCRJAVA-269Preprocessing filters can now be applied to specific areas of an image.New feature
OCRJAVA-267Aspose.OCR for Java is now displayed in the properties of generated PDF documents instead of Aspose.OCR for .NET.Fix
OCRJAVA-266Fixed black page output when recognizing scanned PDF files.Fix

Public API changes and backwards compatibility

This section lists all public API changes introduced in Aspose.OCR for Java 22.8 that may affect the code of existing applications.

Added public APIs:

The following public APIs have been introduced in this release:

Recognize image from byte array

The image for recognition can be provided as a flat byte array representing the amount of each color per pixel or the degree of pixel saturation for grayscale images. The amount can range from 0 to 255, where 0 means no that color and 255 is the maximum amount of that color.

To recognize an image represented as an array of pixel colors, pass the following parameters to RecognizePage method of AsposeOCR class:

  • Byte array representing pixels from left to right (by line), and each line is added to the array from top to bottom.
  • Image width and height.
  • Image color depth (number of bits per pixel).
  • Recognition settings (optional).

Updated public APIs:

The following public APIs have been updated in this release:

Applying preprocessing filters to image regions

The following preprocessing filters can be applied to specific regions of an image:

Multiple preprocessing filters can be applied to different regions of the same image. If the regions intersect each other, filters are applied to the intersection in their chaining order in PreprocessingFilter object.

Applying preprocessing to intersecting regions

To apply a filter to an area, specify its top left corner along with width and height as a Rectangle object. If the region is omitted, the filter is applied to the entire image.

Removed public APIs:

No changes.

Usage examples

The examples below illustrates the changes introduced in this release:

Recognizing an image provided as byte array

// Create instance of OCR API
AsposeOCR api = new AsposeOCR();
// Load image
URL resFile =	getClass().getClassLoader().getResource("source.bmp");
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(resFile.getFile());
// Recognize the image and output text
try {
	com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image;
	int[] pixels = rasterImage.loadArgb32Pixels(rasterImage.getBounds());  
	RecognitionResult res = api.RecognizePage(pixels, rasterImage.getWidth(), rasterImage.getHeight(),
	rasterImage.getBitsPerPixel(), new RecognitionSettings());
} finally {

Applying preprocessing filter to image region

// Create instance of OCR API
AsposeOCR api = new AsposeOCR();
// Invert a region of an image
PreprocessingFilter filters = new PreprocessingFilter();
filters.add(PreprocessingFilter.Invert(new Rectangle(5, 161, 340, 113)));
// Save preprocessed image
BufferedImage img = api.PreprocessImage(file, filters);
File outputSource = new File("preview.png");
ImageIO.write(img, "png", outputSource);