Extracting text from pixel array

Contents
[ ]

Aspose.OCR allows you to provide an image for recognition as an array of pixels. This can be useful when working with unsupported image formats and passing the image to a web application as a byte array.

Pixels are listed as a flat array of integers from left to right (by line), and each line is added to the array from top to bottom. Each element of the array represents the amount of each color (in the red -> green -> blue order) per pixel. The amount can range from 0 to 255, where 0 means no that color and 255 is the maximum amount of that color.

Color ordering

To recognize an image represented as an array of pixel colors pass the array, image width and height, color depth (bits per pixel, from 1 to 32), and recognition settings to RecognizePage method of AsposeOCR class:

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());
	System.out.println("Recognition result:\n" + result + "\n\n");
} finally {
	image.dispose(); 
}