API ref for AI Text Recognition (OCR) in the Windows App SDK
Important
Available in the latest experimental channel release of the Windows App SDK.
The Windows App SDK experimental channel includes APIs and features in early stages of development. All APIs in the experimental channel are subject to extensive revisions and breaking changes and may be removed from subsequent releases at any time. Experimental features are not supported for use in production environments and apps that use them cannot be published to the Microsoft Store.
- Self-contained apps are not supported.
Learn about the Windows App SDK APIs, backed by artificial intelligence (AI), that can detect and extract text (characters, words, lines, polygonal text boundaries, and confidence levels for each match) within images and convert it into machine readable character streams.
For more details, see Get Started with Text Recognition (OCR) in the Windows App SDK.
Tip
Provide feedback on these APIs and their functionality by creating a new Issue in the Windows App SDK GitHub repo (include OCR in the title) or by responding to an existing issue.
Microsoft.Windows.Vision namespace
Provides APIs for machine learning models that analyze the textual content of images.
BoundingBox struct
public struct BoundingBox
A polygon with 4 points used for the boundary of recognized words and lines of text.
Fields
BottomLeft
The bottom left corner of the bounding box.
BottomRight
The bottom right corner of the bounding box.
TopLeft
The top left point of the bounding box.
TopRight
The top right point of the bounding box.
Remarks
When returned as a boundary for a word or line, the TopLeft, TopRight, BottomRight, and BottomLeft points are relative to the rotation and skew of the recognized text in the image. The following diagram shows the point layout for different text rotations where 0 is TopLeft, 1 is TopRight, 2 is BottomRight, and 3 is BottomLeft, all relative to the text.
DetectedLineStyle enum
public enum DetectedLineStyle
Specifies the line styles that can be recognized.
Fields
Handwritten: 0
The line of text is hand written.
Other: 1
The line of text is not hand written.
OrientationDetectionOptions enum
public enum OrientationDetectionOptions
Specifies the text orientations that can be recognized.
Fields
None: 0
Orientation is not recognized.
DetectOrientation: 1
Orientation is recognized.
RecognizedLine class
public sealed class RecognizedLine
Represents a single line of recognized text.
RecognizedLine.BoundingBox property
public Microsoft.Windows.Vision.RecognizedLine.BoundingBox BoundingBox { get; }
Gets the bounding box of the recognized line.
Property value
The bounding box of the recognized line.
Remarks
RecognizedLine.Style property
public Microsoft.Windows.Vision.RecognizedLineStyle Style { get; }
Gets the recognized line style.
Property value
The recognized line style.
Remarks
Includes whether the line of text was handwritten or not and the level of recognition confidence.
RecognizedLine.Text property
public string Text { get; }
Gets the text of the recognized line.
Property value
The text of the recognized line.
Remarks
All words concatenated with spaces.
RecognizedLine.Words property
public Microsoft.Windows.Vision.RecognizedWord[] Words { get; }
The words in the recognized line.
Property value
The words in the recognized line.
RecognizedLineStyle struct
public struct RecognizedLineStyle
Represents the style of the recognized line.
Fields
Confidence
The confidence level of the line style recognition.
Name
The line style name.
RecognizedText class
public sealed class RecognizedText
Represents the result of an image-to-text recognition operation.
RecognizedText.ImageAngle property
public float ImageAngle { get; }
Gets the clockwise rotational angle of the recognized text in degrees.
Property value
The clockwise rotational angle of the recognized text in degrees.
RecognizedText.Lines property
public Microsoft.Windows.Vision.RecognizedLine[] Lines { get; }
Gets the collection of recognized lines.
Property value
The collection of recognized lines.
RecognizedWord class
public sealed class RecognizedWord
Represents a single recognized word.
RecognizedWord.BoundingBox property
public Microsoft.Windows.Vision.BoundingBox BoundingBox { get; }
Gets the quadrilateral boundary of the recognized word.
Property value
The quadrilateral boundary of the recognized word. TopLeft is relative to the word's rotation.
RecognizedWord.Confidence property
public float Confidence { get; }
Gets how likely this word was recognized correctly.
Property value
Wow likely this word was recognized correctly. Value ranges from 0.0 to 1.0, inclusive.
RecognizedWord.Text property
public string Text { get; }
Gets the text of the recognized word.
Property value
The text of the recognized word.
TextRecognizer class
public sealed class TextRecognizer : System.IDisposable
Recognizes words and lines, and their quadrilateral boundaries, in a source image.
TextRecognizer.Close method
Disposes of the object and associated resources.
Remarks
Not implemented in C#.
TextRecognizer.CreateAsync method
public static Windows.Foundation.IAsyncOperation<Microsoft.Windows.Vision.TextRecognizer> CreateAsync ();
Asynchronously creates a new instance of the TextRecognizer class.
Returns
A new instance of the TextRecognizer class.
This will return an error if GetModelReadyStatus is not Ready.
TextRecognizer.IsAvailable method
public static bool IsAvailable ();
Retrieves whether the underlying language model is installed.
Returns
True if the underlying language model is installed. Otherwise, false.
TextRecognizer.MakeAvailableAsync method
public static Windows.Foundation.IAsyncOperationWithProgress<Microsoft.Windows.Management.Deployment.PackageDeploymentResult,
Microsoft.Windows.Management.Deployment.PackageDeploymentProgress> MakeAvailableAsync ();
Ensures the underlying language model is installed and available for use.
Returns
An asynchronous action with progress that returns a PackageDeploymentResult on completion.
TextRecognizer.RecognizeTextFromImage(Microsoft.Graphics.Imaging.ImageBuffer, Microsoft.Windows.Vision.TextRecognizerOptions) method
public Microsoft.Windows.Vision.RecognizedText RecognizeTextFromImage (Microsoft.Graphics.Imaging.ImageBuffer imageBuffer,
Microsoft.Windows.Vision.TextRecognizerOptions options);
Recognize text in the provided image.
Parameters
imageBuffer
An uncompressed bitmap.
options
Options for configuring the text recognition model for the TextRecognizer.
Returns
The recognized text.
TextRecognizer.RecognizeTextFromImage(Microsoft.Graphics.Imaging.ImageBuffer, Microsoft.Windows.Vision.TextRecognizerOptions, Microsoft.Windows.Workloads.WorkloadPriority) method
public Microsoft.Windows.Vision.RecognizedText RecognizeTextFromImage (Microsoft.Graphics.Imaging.ImageBuffer imageBuffer,
Microsoft.Windows.Vision.TextRecognizerOptions options, Microsoft.Windows.Workloads.WorkloadPriority priority);
Recognize text in the provided image.
Parameters
imageBuffer
An uncompressed bitmap.
options
Options for configuring the text recognition model for the TextRecognizer.
priority
Returns
The recognized text.
TextRecognizer.RecognizeTextFromImageAsync(Microsoft.Graphics.Imaging.ImageBuffer, Microsoft.Windows.Vision.TextRecognizerOptions) method
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.Vision.RecognizedText> RecognizeTextFromImageAsync (Microsoft.Graphics.Imaging.ImageBuffer imageBuffer,
Microsoft.Windows.Vision.TextRecognizerOptions options);
Asynchronously recognize text in the provided image.
Parameters
imageBuffer
An uncompressed bitmap.
options
Options for configuring the text recognition model for the TextRecognizer.
Returns
The recognized text.
TextRecognizer.RecognizeTextFromImageAsync(Microsoft.Graphics.Imaging.ImageBuffer, Microsoft.Windows.Vision.TextRecognizerOptions, Microsoft.Windows.Workloads.WorkloadPriority) method
public Windows.Foundation.IAsyncOperation<Microsoft.Windows.Vision.RecognizedText> RecognizeTextFromImageAsync (Microsoft.Graphics.Imaging.ImageBuffer imageBuffer,
Microsoft.Windows.Vision.TextRecognizerOptions options, Microsoft.Windows.Workloads.WorkloadPriority priority);
Asynchronously recognize text in the provided image.
Parameters
imageBuffer
An uncompressed bitmap.
options
Options for configuring the text recognition model for the TextRecognizer.
priority
Returns
The recognized text.
TextRecognizerOptions class
public sealed class TextRecognizerOptions
Provides options to configure the text recognition model for a TextRecognizer.
TextRecognizerOptions.MaxAnalysisSize property
public Windows.Graphics.SizeInt32 MaxAnalysisSize { get; set; }
Gets or sets the maximum image size.
Property value
The maximum image size. Default value is 1152 width and 768 height.
Remarks
This size is a suggestion, and might not always be honored.
If the source image is larger than the maximum size, it will automatically be scaled down to the upper size limits.
TextRecognizerOptions.MaxLineCount property
public uint MaxLineCount { get; set; }
Gets or sets the maximum number of lines to return from the recognition operation.
Property value
The maximum number of lines to return from the recognition operation.
Remarks
Defaults to MaxLineCountSupported. If specified, the maximum lines returned will be the lesser of this value and MaxLineCountSupported.
TextRecognizerOptions.OrientationDetection property
public Microsoft.Windows.Vision.OrientationDetectionOptions OrientationDetection { get; set; }
Gets or sets whether to detect the text orientation.
Property value
Whether to detect the text orientation. Default value is None.
TextRecognizerOptions.#ctor constructor
public TextRecognizerOptions ();
Initializes a new instance of the TextRecognizerOptions class.