Deskew image
Deskew image
Skew is an artifact that might appear during document scanning process and it consists of getting the document’s text/images be rotated at a slight angle. It can have various causes but the most common are paper getting misplaced during a scan. Therefore, deskew is the process of detecting and fixing this issue on scanned files (ie, bitmap) so deskewed images will have the text/images correctly and horizontally aligned.
import aspose.pycore as aspycore | |
from aspose.imaging import Image, RasterImage, Color | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
data_dir = templates_folder | |
# Get rid of the skewed scan with default parameters | |
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.jpg")), RasterImage) as image: | |
image.normalize_angle(False, Color.light_gray) | |
image.save(os.path.join(data_dir, "result.jpg")) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.jpg")) |