Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Created September 23, 2019 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerryNixon/8a7f068c32d1923035c787e047de3095 to your computer and use it in GitHub Desktop.
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.
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