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 Python via .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 DefectType.SALT_PEPPER_NOISE Appears as random white and black pixels scattered across the area. Often occurs in digital photographs.
  • Some characters are misidentified
  • Unnecessary dots or commas appear in recognition results
Low contrast between text and background DefectType.LOW_CONTRAST Highlights and shadows typically appear on curved pages.
  • Low recognition accuracy
  • Text not recognized (ignored by OCR engine)
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.
  • Characters are not recognized correctly
  • Text not recognized (ignored by OCR engine)
Glare DefectType.GLARE Highlight areas in an image caused by uneven lighting, such as spot lights or flash.
  • Low recognition accuracy
  • Text not recognized (ignored by OCR engine)
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 detect_defects() method.

The method returns DefectOutput object with the following properties:

Property Description
source The full path to the file or URL, if any.
page The page number for multi-page images and PDFs.
defect_areas The list of image defects and areas where they were found.
# Instantiate Aspose.OCR API
api = AsposeOcr()
# Add image to the recognition batch
input = OcrInput(InputType.SINGLE_IMAGE)
input.add("source.png")
# Find shadows and highlights
defects = api.detect_defects(input, DefectType.LOW_CONTRAST)
print(det[0].source)
print(det[0].defect_areas[0].defect_type)

Live demo

Low-contrast image