Specify Image Region to Apply Preprocessing Filter
This release of OCR API enable you to apply the preprocessing filters to specific areas of an image.
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));
Detect Images provided as Aspose.Drawing.Color
Array
For the image recognition via API you may provide the image as an array of Aspose.Drawing.Color
objects.
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);
}
Grayscale Image & Color Image Recognition
To detect images, you may provide them for recognition as a flat array of bytes where they represent the amount of each color per pixel for color images or degree of pixel saturation for grayscale images.
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 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);
}
For a complete list of features, enhancements, and bug fixes in this release please visit, Aspose.OCR for .NET 22.8 - Notas de lanzamiento.