Created
September 23, 2019 04:17
-
-
Save JerryNixon/8a7f068c32d1923035c787e047de3095 to your computer and use it in GitHub Desktop.
Making sense of Azure's Recognize Text computer vision cognitive service Line and Word BoundingBox array of longs property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void GetBoxCoordinates(long[] longs, out (Point TopLeft, Point TopRight, Point BottomRight, Point BottomLeft) corners, out Size size, out double angle) | |
{ | |
if (longs.Length != 8) | |
{ | |
throw new ArgumentOutOfRangeException(nameof(longs)); | |
} | |
corners = ( | |
new Point((int)longs[0], (int)longs[1]), | |
new Point((int)longs[2], (int)longs[3]), | |
new Point((int)longs[4], (int)longs[5]), | |
new Point((int)longs[6], (int)longs[7])); | |
var width = Math.Abs(corners.TopRight.X - corners.TopLeft.X); | |
var height = Math.Abs(corners.BottomLeft.Y - corners.TopLeft.Y); | |
size = new Size(width, height); | |
var sign = corners.TopLeft.Y > corners.TopRight.Y ? -1 : 1; | |
angle = sign * Math.Atan2(size.Height, size.Width) * (180 / Math.PI); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment