Table of Contents

Struct OcrQuad

Namespace
Egami.Ocr
Assembly
Egami.dll

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

TopLeft Vector2

The corner where the word starts, at the top of its letters.

TopRight Vector2

The corner where the word ends, at the top of its letters.

BottomRight Vector2

The corner where the word ends, at the bottom of its letters.

BottomLeft Vector2

The 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

float

BottomLeft

The corner where the word starts, at the bottom of its letters.

public Vector2 BottomLeft { get; init; }

Property Value

Vector2

BottomRight

The corner where the word ends, at the bottom of its letters.

public Vector2 BottomRight { get; init; }

Property Value

Vector2

Bounds

Gets the smallest whole-pixel rectangle that holds the four corners.

public Rect Bounds { get; }

Property Value

Rect

TopLeft

The corner where the word starts, at the top of its letters.

public Vector2 TopLeft { get; init; }

Property Value

Vector2

TopRight

The corner where the word ends, at the top of its letters.

public Vector2 TopRight { get; init; }

Property Value

Vector2

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

x float

The left edge.

y float

The top edge.

width float

The width.

height float

The height.

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

x float

The left edge.

y float

The top edge.

width float

The width.

height float

The height.

angle int

The 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

matrix Matrix3x2

The transform.

Returns

OcrQuad

The mapped quad.