I'm trying to write a C# console application that takes an image with text in it and rotate it so the text is as close to horizontal as possible so that OCR is more accurate.
Using AWS Rekognition I can get a bounding box with corner points which provide a guide as to the rotation needed however I don't have the maths ability to work out what sort of algorithm would work best.
As an example, AWS will provide these relative coordinates:
"X": 0.6669167280197144, "Y": 0.6940382719039917
"X": 0.759939968585968, "Y": 0.681664764881134
"X": 0.7622751593589783, "Y": 0.7211361527442932
"X": 0.6692519187927246, "Y": 0.7335096001625061
So far, I've tried using either the top or bottom "Y" coordinates to create a ratio and then multiplying that by either 6 or -6.
This is the code I've tried.
var rotationAngle = (int)Math.Round(coordRatio * 6 * rotationDirection);
OR
var rotationAngle = Math.Sin(Math.Cos(coordRatio * Math.PI)) * 10 * rotationDirection;