How to Read Screenshots using IronOCR
Screenshots are a quick and easy way to share information and quickly capture vital information to send to colleagues and peers. However, extracting text from screenshots has often proven difficult because of the dimensions and noise involved in taking them. This makes screenshots a less effective medium in the release of OCR.
However, IronOCR resolves that issue by providing specialized methods such as ReadScreenshot
to combat this. ReadScreenshot
is optimized for reading screenshots and extracting information from them; it also accepts common file formats.
In this guide, we'll quickly demonstrate how to use IronOCR for screenshot text recognition, walking through examples and the properties of the result object.
How to Read Screenshots using IronOCR
- Download the C# library for reading screenshots
- Import the screenshot images for processing
- Use the
ReadScreenshot
method to extract text from the image - Retrieve the extracted data using the OcrPhotoResult property for further processing
- Save or export the extracted text as needed
Start using IronOCR in your project today with a free trial.
To use this function, you must also install the IronOcr.Extension.AdvancedScan package.
Read Screenshots Example
To read a screenshot in IronOCR, we have to apply the following steps. We utilize the ReadScreenshot
method, which takes an OcrInput
as a parameter for the input. This method is more optimized for screenshots than the library's standard Read
counterpart.
- The method currently works for languages including English, Chinese, Japanese, Korean, and Latin-based alphabets.
- Using advanced scan on .NET Framework requires the project to run on x64 architecture.
Input
Below is our input for the code example; we'll demonstrate the versatility of this method by mixing different text fonts and sizes.
Code
:path=/static-assets/ocr/content-code-examples/how-to/read-screenshot-read-screenshot.cs
using IronOcr;
using System;
using System.Linq;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputScreenshot = new OcrInput();
inputScreenshot.LoadImage("screenshotOCR.png");
// Perform OCR
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);
// Output screenshot information
Console.WriteLine(result.Text);
Console.WriteLine(result.TextRegions.First().Region.X);
Console.WriteLine(result.TextRegions.Last().Region.Width);
Console.WriteLine(result.Confidence);
Imports IronOcr
Imports System
Imports System.Linq
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputScreenshot = New OcrInput()
inputScreenshot.LoadImage("screenshotOCR.png")
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadScreenShot(inputScreenshot)
' Output screenshot information
Console.WriteLine(result.Text)
Console.WriteLine(result.TextRegions.First().Region.X)
Console.WriteLine(result.TextRegions.Last().Region.Width)
Console.WriteLine(result.Confidence)
Output
As you can see from the console output above, it extracted all instances of text from the screenshot. Let's dive deeper into the properties of OcrPhotoResult
.
Text
: The extracted text from OCR Input.Confidence
: A double property that indicates the statistical accuracy confidence, with a scale from 0 to 1, where 1 is the highest confidence level.TextRegion
: An array ofTextRegion
objects, which hold properties returning the areas where text is found on the screenshot. By default, allTextRegion
is a derivedRectangle
class from the IronOCR models. It includes the x and y coordinates, as well as the height and width of the rectangle.
Frequently Asked Questions
How can I extract text from a screenshot using C#?
You can extract text from a screenshot using IronOCR's ReadScreenshot
method. This method is optimized for screenshots and supports multiple languages. Start by downloading the IronOCR library from NuGet, then import your screenshots and use the ReadScreenshot
function to retrieve text.
What file formats are compatible with the ReadScreenshot method?
The ReadScreenshot
method in IronOCR is designed to accept common image file formats, making it versatile for text extraction from various types of screenshot files.
Why is the ReadScreenshot method preferable for screenshots?
The ReadScreenshot
method is specifically optimized for the dimensions and noise typically present in screenshots, offering more accurate text extraction compared to standard OCR methods.
What languages does IronOCR support for OCR text extraction?
IronOCR supports a variety of languages for OCR text extraction, including English, Chinese, Japanese, Korean, and Latin-based alphabets, making it suitable for diverse applications.
How does the confidence property work in IronOCR?
In IronOCR, the Confidence
property is a double value ranging from 0 to 1 that indicates the likelihood of the accuracy of the extracted text. A value closer to 1 suggests a higher confidence level.
What are TextRegion objects in IronOCR?
TextRegion objects in IronOCR represent the specific areas on a screenshot where text is detected. These objects include coordinates and dimensions, helping users understand the layout of extracted text.
Do I need additional packages to enhance IronOCR's capabilities?
Yes, to utilize advanced scanning features in IronOCR, you should install the IronOcr.Extension.AdvancedScan package from NuGet, which enhances the library's performance and capabilities.
How can I implement IronOCR in my C# project for reading screenshots?
To implement IronOCR in your C# project for reading screenshots, first download the library from NuGet, import your screenshot images, and then use the ReadScreenshot
method to extract text. Finally, process the extracted data using the OcrPhotoResult
property.