OCR Tesseract Image DPI
The OcrInput
class will automatically resolve low-resolution images for IronTesseract
.
Although Tesseract generally requires a 300 DPI input, IronTesseract
has been tuned to work with 99+% accuracy on 225 DPI scans. This can double OCR speed.
Too high a DPI is slow. Too low a DPI causes inaccuracies. If in doubt, do nothing, and Iron Tesseract will preconfigure everything for you.
How to Improve Low-Quality DPI in Tesseract
- Install the OCR library to improve low-quality DPI.
- Construct an
IronTesseract
instance. - Create an
OcrInput
object with the path to the image. - Choose a target DPI value.
- Invoke the
Read
method with theOcrInput
object.
// Import the IronOcr namespace
using IronOcr;
class Program
{
static void Main()
{
// Construct an IronTesseract instance
var Ocr = new IronTesseract();
// Create an OcrInput object and provide the path to the image file
using (var Input = new OcrInput(@"path\to\your\low-resolution-image.png"))
{
// Optionally, set the DPI (Dots Per Inch) if you need to adjust for specific image resolutions.
// OcrInput will handle low-resolution images automatically, so this step can often be skipped.
Input.TargetDPI = 300;
// Perform OCR on the input image, recognizing text
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
}
}
// Import the IronOcr namespace
using IronOcr;
class Program
{
static void Main()
{
// Construct an IronTesseract instance
var Ocr = new IronTesseract();
// Create an OcrInput object and provide the path to the image file
using (var Input = new OcrInput(@"path\to\your\low-resolution-image.png"))
{
// Optionally, set the DPI (Dots Per Inch) if you need to adjust for specific image resolutions.
// OcrInput will handle low-resolution images automatically, so this step can often be skipped.
Input.TargetDPI = 300;
// Perform OCR on the input image, recognizing text
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
}
}
' Import the IronOcr namespace
Imports IronOcr
Friend Class Program
Shared Sub Main()
' Construct an IronTesseract instance
Dim Ocr = New IronTesseract()
' Create an OcrInput object and provide the path to the image file
Using Input = New OcrInput("path\to\your\low-resolution-image.png")
' Optionally, set the DPI (Dots Per Inch) if you need to adjust for specific image resolutions.
' OcrInput will handle low-resolution images automatically, so this step can often be skipped.
Input.TargetDPI = 300
' Perform OCR on the input image, recognizing text
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Using
End Sub
End Class
In the provided C# code:
- We begin by importing the IronOcr library, which is necessary for using its OCR functionalities.
- We instantiate
IronTesseract
to process our images. - We then create an
OcrInput
object with a file path to our low-resolution image. - Optionally, the
TargetDPI
property can be set to adjust the image DPI if necessary. However, IronTesseract is capable of handling low DPI on its own. - Finally, we call the
Read
method on theOcr
object, which processes the input image and extracts the text. The recognized text is output to the console.