HTML
JPG
OCR
JSON
BMP
OCR
Image preprocessing in C#
Preprocess image before recognition using Aspose.OCR for .NET library.
How to preprocess image before recognition using C#
Aspose.OCR for .NET can preprocess image before recognition and save result as a MemoryStream or in File system.
To run the examples, you just need to download the Aspose.OCR tools with the following links:
Command line tools
RecognizeAndSaveJson project
Run program in Command Prompt
PreprocessImage
or
Run program in Command Prompt if you want to use own image (document)
PreprocessImage folder/image.png
The result png file will be stored in the *out* folder
Recognition result
Method | Return value | Description |
---|---|---|
ImageProcessing.Render | OcrInput | Applies processing filters to all images in a batch and returns a new batch with processed images. This batch can later be submitted for recognition or used for optimization. |
ImageProcessing.Save | OcrInput | Applies processing filters to all images in batch and saves the resulting images in the specified folder. That method also returns a new batch with processed images, that can be later submitted for the recognition. |
This sample code shows how to preprocess image with contrast correction filter and save result in file system
string fileName = args.Length > 0 ? args[0] : "images/test.jpg";
PrintStart(fileName);
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");
// Create OcrInput object to containerize images
// Set:
// 1) path to the image or MemruStream with the image.
// 2) set of filters for preprocessing. You can call any number of filters.
OcrInput input = new OcrInput(InputType.SingleImage, new PreprocessingFilter { PreprocessingFilter.ContrastCorrectionFilter() });
input.Add(fileName);
OcrInput result = ImageProcessing.Render(input);
MemoryStream memoryStream = result[0].Stream;
// Use Stream for further recognition or simply save it on the disk
FileStream fs = new FileStream("out/corrected.jpg", FileMode.OpenOrCreate);
memoryStream.WriteTo(fs);
fs.Close();
memoryStream.Close();
result.Clear();
Other Supported Tools
Using C#, one can easily run our examples.
Recognize image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize PDF (Scanned PDF)
Recognize TIFF (Multipage TIFF)
Preprocess image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize ZIP archive (ZIP)
Get JSON (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Get XLSX (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Detect angle (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize image from URL (URL with GIF, PNG, JPEG, BMP, TIFF, JFIF)
Text areas detection (GIF, PNG, JPEG, BMP, TIFF, JFIF)