Skew correction
When a page is fed to a flatbed scanner (mechanically or manually) or photographed with a smartphone, it is nearly impossible to achieve perfect alignment. As a result, a slight skew (tilt) inevitably occurs in scanned images or photographs.
Skew angle detection and image straightening is critical to the OCR process as it directly affects the reliability and efficiency of segmentation and text extraction. Aspose.OCR offers automated processing algorithms to correct image tilt (deskew) before proceeding to recognition.
Detecting skew angle
To find out the skew angle, use asposeocr_get_skew()
, asposeocr_get_skew_from_raw_bytes()
, or asposeocr_get_skew_from_uri()
functions.
> Skew angle: 5.9°
Automatic skew correction
To automatically straighten skewed image before recognition, run the image through OCR_IMG_PREPROCESS_AUTOSKEW
preprocessing filter.
std::string image_path = "source.png";
custom_preprocessing_filters filters_;
filters_.filter_1 = OCR_IMG_PREPROCESS_AUTOSKEW;
asposeocr_preprocess_page_and_save(image_path.c_str(), "result.png", filters_);
Manual skew correction
In rare cases, automatic skew correction may incorrectly determine the angle of the image. This can happen to poor quality photos with significant perspective distortions.
To deal with such situations, you can rotate the image by the specified degree using OCR_IMG_PREPROCESS_ROTATE
preprocessing filter or manually define the skew angle for such images using the skew
property in recognition settings. The rotation angle is passed in degrees:
-360
to0
: rotate counterclockwise;0
to360
: rotate clockwise.
Usage scenarios
- Automatic skew correction is recommended in almost all cases, except for perfectly straight scans.
- Manual rotation is recommended for:
- photos of low quality;
- images with a significant angle of inclination.