Struct OcrQuad
The four corners of a word, in pixels with the origin at the top left of the image, named as the word reads: a word that runs up the page has its TopLeft at the bottom left of its bounds. Rotated and skewed words keep their shape.
public readonly record struct OcrQuad : IEquatable<OcrQuad>
- Implements
- Inherited Members
Examples
// Boxes are quads, corners named as the word reads, so turned and skewed words keep their shape.
OcrQuad upright = OcrQuad.FromBounds(100, 50, 200, 40);
OcrQuad upThePage = OcrQuad.FromBounds(20, 300, 40, 200, angle: 90); // TopLeft is the bottom left of the box
Console.WriteLine($"{upThePage.Angle}° from {upThePage.TopLeft} to {upThePage.TopRight}");
// Map boxes back from an image the engine saw at half size, or into another space.
OcrQuad full = upright.Transform(Matrix3x2.CreateScale(2));
Constructors
OcrQuad(Vector2, Vector2, Vector2, Vector2)
The four corners of a word, in pixels with the origin at the top left of the image, named as the word reads: a word that runs up the page has its TopLeft at the bottom left of its bounds. Rotated and skewed words keep their shape.
public OcrQuad(Vector2 TopLeft, Vector2 TopRight, Vector2 BottomRight, Vector2 BottomLeft)
Parameters
TopLeftVector2The corner where the word starts, at the top of its letters.
TopRightVector2The corner where the word ends, at the top of its letters.
BottomRightVector2The corner where the word ends, at the bottom of its letters.
BottomLeftVector2The corner where the word starts, at the bottom of its letters.
Examples
// Boxes are quads, corners named as the word reads, so turned and skewed words keep their shape.
OcrQuad upright = OcrQuad.FromBounds(100, 50, 200, 40);
OcrQuad upThePage = OcrQuad.FromBounds(20, 300, 40, 200, angle: 90); // TopLeft is the bottom left of the box
Console.WriteLine($"{upThePage.Angle}° from {upThePage.TopLeft} to {upThePage.TopRight}");
// Map boxes back from an image the engine saw at half size, or into another space.
OcrQuad full = upright.Transform(Matrix3x2.CreateScale(2));
Properties
Angle
Gets the direction the word reads in, in degrees counterclockwise as seen on screen, from 0 up to 360: 0 for normal text, 90 for text that runs up the page.
public float Angle { get; }
Property Value
BottomLeft
The corner where the word starts, at the bottom of its letters.
public Vector2 BottomLeft { get; init; }
Property Value
BottomRight
The corner where the word ends, at the bottom of its letters.
public Vector2 BottomRight { get; init; }
Property Value
Bounds
Gets the smallest whole-pixel rectangle that holds the four corners.
public Rect Bounds { get; }
Property Value
TopLeft
The corner where the word starts, at the top of its letters.
public Vector2 TopLeft { get; init; }
Property Value
TopRight
The corner where the word ends, at the top of its letters.
public Vector2 TopRight { get; init; }
Property Value
Methods
FromBounds(float, float, float, float)
Returns the quad of an upright word with these bounds.
public static OcrQuad FromBounds(float x, float y, float width, float height)
Parameters
Returns
- OcrQuad
The quad.
FromBounds(float, float, float, float, int)
Returns the quad of a word with these bounds that reads at a quarter turn: 0 for normal text, 90 for text that runs up the page, 180 for upside-down text and 270 for text that runs down. Other angles give the upright quad.
public static OcrQuad FromBounds(float x, float y, float width, float height, int angle)
Parameters
xfloatThe left edge.
yfloatThe top edge.
widthfloatThe width.
heightfloatThe height.
angleintThe reading direction, in degrees counterclockwise.
Returns
- OcrQuad
The quad.
Transform(Matrix3x2)
Returns the quad with each corner mapped through matrix, such as a scale back from an image the engine
saw smaller, or the move from image pixels to page space.
public OcrQuad Transform(Matrix3x2 matrix)
Parameters
matrixMatrix3x2The transform.
Returns
- OcrQuad
The mapped quad.