straightenImage

straightenImage ( string orignalImage , string _destinationImage , double _reduction , string _debugImage , int _lineFactor , int _threshold1 , int _threshold2 ) : void

Straighten a tilted image, for example, a document that has been scanned crooked.

Note: With artificial intelligence image processing functions, be sure to protect your functions from very large images as this processing would then take a long time. To do this use resizeImage.


Example

This example allows you to know the orientation of an image in case it has been scanned upside down (180°):
goodAngle = -1
goodText=null

for(angle in [0,90,180,270])
{
rotateImage(path("desktop")+"origial.png", angle, path("desktop")+"rotated.png") //We turn the page in the 4 possible directions
straightenImage(path("desktop")+"rotated.png", path("desktop")+"straightened.png") //We straighten it, in case the scan was tilted
text = ocr(path("desktop")+"straightened.png", "C:\\Program Files\\ImageMagick-7.1.0-Q16-HDRI\\magick.exe") //We extract the readable text
if(count(goodText) < count(text)) //We see if the text readable in this orientation is longer than in the previous ones
{
goodText = text
goodAngle = angle
}
}

console("Text of the image : "+goodText+" - Orientation : "+goodAngle+"°")


See also

rotateImage

Parameters

orignalImage

Original image to straighten

_destinationImage (optional)

Path where the rectified image should be saved. Leave blank to replace the original image with the rectified image.

_reduction (optional)

Between 0 and 1. Default: 0.1. Since the operations on this function are done at the pixel level, it is more economical in terms of resources to work on a rasterized image. You can indicate the reduction factor here.

_debugImage (optional)

This file is used to debug the function. When you ask for the output, the lines of interest of the document will be drawn. The more lines that characterize the orientation of the document, the more reliable the function will be. If you do not specify anything, no file will be produced.

_lineFactor (optional)

Default:150. The higher this parameter is, the more lines are detected. With pale images we recommend 80. Accumulator threshold parameter. Only those lines are returned that get enoughvotes. Must be positive.

_threshold1 (optional)

Default:100. Conditions the number of salient points that serve as landmarks for line construction (rarely useful). First threshold for the hysteresis procedure. Must be positive.

_threshold2 (optional)

Default:200. Conditions the number of salient points that serve as landmarks for line construction (rarely useful). Second threshold for the hysteresis procedure. Must be positive.