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 Java 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 | 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 | DefectType.LOW_CONTRAST |
Highlights and shadows typically appear on curved pages. |
|
|
Blur | 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 | DefectType.GLARE |
Highlight areas in an image caused by uneven lighting, such as spot lights or flash. |
|
|
All supported defects | 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 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. |
// Initialize Aspose.OCR recognition API
AsposeOCR api = new AsposeOCR();
// Add image to the recognition batch
OcrInput source = new OcrInput(InputType.SingleImage);
source.add("image.png");
// Find shadows and highlights
ArrayList<DefectOutput> defects = api.DetectDefects(input, DefectType.LOW_CONTRAST);
for(DefectOutput d : result) {
for (DefectAreas ar : d.defectAreas) {
System.out.println(ar.defectType);
for (Rectangle r : ar.rectangles) {
System.out.println(r.x + " " + r.y + " " + r.width + " " + r.height);
}
}
}
Live demo
![Low-contrast image](demo.png)