Defect detection
Image defects can significantly impact the accuracy of OCR. They can be caused by the quality of the image acquisition process, environmental conditions, and the hardware used to capture the image. To improve recognition accuracy, it is essential to preprocess and enhance images to mitigate these defects whenever possible.
Aspose.OCR for .NET can automatically find potentially problematic areas of image and return the information on the type of defect and its coordinates. The following types of defects can be found:
Defect | Enumeration | Description | Impact | How to mitigate |
---|---|---|---|---|
Salt-and-pepper noise | Aspose.OCR.DefectType.SALT_PEPPER_NOISE |
Appears as random white and black pixels scattered across the area. Often occurs in digital photographs. |
|
|
Low contrast between text and background | Aspose.OCR.DefectType.LOW_CONTRAST |
Highlights and shadows typically appear on curved pages. |
|
|
Blur | Aspose.OCR.DefectType.BLUR |
The entire image or some of its areas are out of focus. Important: This detection algorithm can only identify the entire image as blurry. Specific areas cannot be detected. |
|
|
Glare | Aspose.OCR.DefectType.GLARE |
Highlight areas in an image caused by uneven lighting, such as spot lights or flash. |
|
|
All supported defects | Aspose.OCR.DefectType.ALL |
All above-mentioned defects. | See the corresponding defect for details. | See the corresponding defect for details. |
You can highlight problem areas when previewing an image and even OCR them using alternative recognition settings to get a better result.
Detecting defects
To find defects on images, provide the collection of images and specify the type of defect to Aspose.OCR.AsposeOcr.DetectDefects()
method.
The method returns DefectOutput
object with the following properties:
Property | Type | Description |
---|---|---|
Source |
string |
Image path. |
Page |
int |
Page number of multi-page images. |
defectAreas |
List<DefectAreas> |
The list of defects and areas of an image where they were found. |
var api = new Aspose.OCR.AsposeOcr();
var input = new OcrInput(InputType.SingleImage);
input.Add("source.png");
// Find shadows and highlights
var defects = api.DetectDefects(input, DefectType.LOW_CONTRAST);
foreach (var defect in defects)
{
Console.WriteLine($"Image path: {defect.Source} | Page: {defect.Page}");
foreach (var areas in defect.defectAreas)
{
Console.WriteLine($"Number of low-contrast areas: {areas.rectangles.Count()}");
}
}