Dewarping
Geometric distortions is a very common case when dealing with photos of books, magazines, multi-page documents, and similar content. They can be caused by physical page curvature or camera lens distortion (ultra-wide and fisheye lenses, as well as entry-level smartphone lenses).
Warped images are very hard to be processed by most OCR algorithms. Thus, image straightening and distortion removal is critical to the recognition process as it directly affects the reliability and efficiency of segmentation and text extraction. Aspose.OCR implements a preprocessing filter for automated correction of geometric distortions before proceeding to recognition.
Important considerations
We recommend using it for pinpoint processing of individual images that cannot be recognized otherwise.
- Dewarping one image may take more than a minute.
- Due to the high complexity of the underlying neural network, dewarping is extremely resource-intensive (CPU and RAM).
- After removing the image curvature, text lines will have some wave-like distortion. Thus, it is highly recommended to use
DetectAreasMode.CURVED_TEXT
areas detection mode to extract text from the dewarped image. Other area detection modes may produce inaccurate results. - Dewarping also corrects image tilt. We recommend disabling automatic skew correction - it will have no effect and may even result in severe image distortion.
Dewarping
To straighten the curved image, run it through AutoDewarping()
preprocessing filter.
AsposeOCR api = new AsposeOCR();
RecognitionSettings settings = new RecognitionSettings();
// Apply dewarping filter
PreprocessingFilter filters = new PreprocessingFilter();
filters.add(PreprocessingFilter.AutoDewarping());
settings.setPreprocessingFilters(filters);
// Save dewarped image to file
BufferedImage image = api.PreprocessImage(file, filters);
File outputSource = new File("result.png");
ImageIO.write(image, "png", outputSource);
// Extract text from image
RecognitionResult result = api.RecognizePage(file, settings);
System.out.println(result);
Usage scenarios
Automatic dewarping is recommended for:
- Photos of book pages, magazines.
- Curved paper.
- Ultra wide-angle and fisheye photos.