Aspose.OCR for .NET 22.8 - Release Notes

What was changed

Key Summary Category
OCRNET-567 Added support for text recognition from images provided as an array of Aspose.Drawing.Color objects. New feature
OCRNET-565 Added support for text recognition from images provided as an array of bytes. New feature
OCRNET-566 Preprocessing filters can now be applied to specific areas of an image. New feature
n/a Fixed the behavior of Dilate preprocessing filter. Fix

Public API changes and backwards compatibility

This section lists all public API changes introduced in Aspose.OCR for .NET 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 RecognizeImage method of Aspose.OCR.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.
  • Pixel color format provided as a value of Aspose.OCR.PixelType enumeration.
  • Recognition settings (optional).

Recognize image from Aspose.Drawing.Color array

The image for recognition can be provided as an array of Aspose.Drawing.Color objects.

To recognize an image represented as an array of pixel colors, pass the following parameters to RecognizeImage method of Aspose.OCR.AsposeOcr class:

  • An array of Aspose.Drawing.Color objects representing pixels from left to right (by line), and each line is added to the array from top to bottom.
  • Image width and height.
  • 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 Aspose.Drawing.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 color images provided as byte array

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
using(Aspose.Imaging.RasterImage image = (RasterImage)Aspose.Imaging.Image.Load("source.png"))
{
	Color[] c = image.LoadPixels(image.Bounds);
	byte[] arr = new byte[c.Length*3];
	int idx = 0;
	for (int i = 0; i < c.Length*3; i += 3)
	{
		arr[i] = c[idx].R;
		arr[i+1] = c[idx].G;
		arr[i+2] = c[idx].B;
		idx++;
	}
	Aspose.OCR.RecognitionResult recognitionResult = recognitionEngine.RecognizeImage(pixels, image.Width, image.Height, Aspose.OCR.PixelType.RGB);
	Console.WriteLine(recognitionResult.RecognitionText);
}

Recognizing grayscale images provided as byte array

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
using(Aspose.Imaging.RasterImage image = (RasterImage)Aspose.Imaging.Image.Load("source.png"))
{
	Color[] c = image.LoadPixels(image.Bounds);
	byte[] arr = new byte[c.Length*3];
	for (int i = 0; i < c.Length; i++)
	{
		arr[i] = (byte)((c[i].R + c[i].G +c[i].B)/3);
	}
	Aspose.OCR.RecognitionResult recognitionResult = recognitionEngine.RecognizeImage(pixels, image.Width, image.Height, Aspose.OCR.PixelType.BYTE);
	Console.WriteLine(recognitionResult.RecognitionText);
}

Recognizing images provided as Aspose.Drawing.Color array

Aspose.OCR.AsposeOcr recognitionEngine = new Aspose.OCR.AsposeOcr();
using(Aspose.Imaging.RasterImage image = (RasterImage)Aspose.Imaging.Image.Load("source.png"))
{
	Color[] c = image.LoadPixels(image.Bounds);
	Aspose.Drawing.Color[] c1 = new Aspose.Drawing.Color[c.Length];
	for (int i = 0; i < c.Length; i++)
	{
		c1[i] = Aspose.Drawing.Color.FromArgb(c[i].R, c[i].G, c[i].B);
	}
	Aspose.OCR.RecognitionResult recognitionResult = recognitionEngine.RecognizeImage(c1, image.Width, image.Height);
	Console.WriteLine(recognitionResult.RecognitionText);
}

Applying preprocessing filter to image region

Aspose.OCR.Models.PreprocessingFilters.PreprocessingFilter filters = new Aspose.OCR.Models.PreprocessingFilters.PreprocessingFilter();
Aspose.Drawing.Rectangle blackRectangle = new Aspose.Drawing.Rectangle(5, 161, 340, 113);
filters.Add(Aspose.OCR.Models.PreprocessingFilters.PreprocessingFilter.Invert(blackRectangle));