using IronOcr;using IronSoftware.Drawing;// Instantiate IronTesseractIronTesseract ocrTesseract = new IronTesseract();// Read image file to AnyBitmapAnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");// Import image streamusing var imageInput = new OcrImageInput(anyBitmap.GetStream());// Perform OCROcrResult ocrResult = ocrTesseract.Read(imageInput);
using IronOcr;
using IronSoftware.Drawing;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read image file to AnyBitmap
AnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");
// Import image stream
using var imageInput = new OcrImageInput(anyBitmap.GetStream());
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
ImportsIronOcrImportsIronSoftware.Drawing' Instantiate IronTesseractDim ocrTesseract As New IronTesseract()' Read image file to AnyBitmapDim anyBitmap AsAnyBitmap = AnyBitmap.FromFile("Potter.tiff")' Import image streamUsing imageInput As New OcrImageInput(anyBitmap.GetStream()) ' Perform OCR Dim ocrResult AsOcrResult = ocrTesseract.Read(imageInput)EndUsing
Imports IronOcr
Imports IronSoftware.Drawing
' Instantiate IronTesseract
Dim ocrTesseract As New IronTesseract()
' Read image file to AnyBitmap
Dim anyBitmap As AnyBitmap = AnyBitmap.FromFile("Potter.tiff")
' Import image stream
Using imageInput As New OcrImageInput(anyBitmap.GetStream())
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)
End Using
using IronOcr;using IronSoftware.Drawing;using System;// Instantiate IronTesseractIronTesseract ocrTesseract = new IronTesseract();// Read image file to AnyBitmapAnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");// Specify crop regionRectangle scanRegion = new Rectangle(800, 200, 900, 400);// Add imageusing var imageInput = new OcrImageInput(anyBitmap.GetStream(), ContentArea: scanRegion);// Perform OCROcrResult ocrResult = ocrTesseract.Read(imageInput);// Output the result to consoleConsole.WriteLine(ocrResult.Text);
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read image file to AnyBitmap
AnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");
// Specify crop region
Rectangle scanRegion = new Rectangle(800, 200, 900, 400);
// Add image
using var imageInput = new OcrImageInput(anyBitmap.GetStream(), ContentArea: scanRegion);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Output the result to console
Console.WriteLine(ocrResult.Text);
ImportsIronOcrImportsIronSoftware.DrawingImportsSystem' Instantiate IronTesseractPrivate ocrTesseract As New IronTesseract()' Read image file to AnyBitmapPrivate anyBitmap AsAnyBitmap = AnyBitmap.FromFile("Potter.tiff")' Specify crop regionPrivate scanRegion As New Rectangle(800, 200, 900, 400)' Add imagePrivate imageInput = New OcrImageInput(anyBitmap.GetStream(), ContentArea:= scanRegion)' Perform OCRPrivate ocrResult AsOcrResult = ocrTesseract.Read(imageInput)' Output the result to consoleConsole.WriteLine(ocrResult.Text)
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()
' Read image file to AnyBitmap
Private anyBitmap As AnyBitmap = AnyBitmap.FromFile("Potter.tiff")
' Specify crop region
Private scanRegion As New Rectangle(800, 200, 900, 400)
' Add image
Private imageInput = New OcrImageInput(anyBitmap.GetStream(), ContentArea:= scanRegion)
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Output the result to console
Console.WriteLine(ocrResult.Text)
using IronOcr;using IronSoftware.Drawing;using System.IO;// Process stream with filterspublic stringProcessStreamWithFilters(Stream imageStream){ IronTesseract ocrTesseract = new IronTesseract(); // Configure for better accuracy ocrTesseract.Configuration.BlackListCharacters = "~`$#^*_}{][|\\"; ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd; using var input = new OcrImageInput(imageStream); // Apply preprocessing filters input.Deskew(); input.DeNoise(); input.Sharpen(); var result = ocrTesseract.Read(input); return result.Text;}
using IronOcr;
using IronSoftware.Drawing;
using System.IO;
// Process stream with filters
public string ProcessStreamWithFilters(Stream imageStream)
{
IronTesseract ocrTesseract = new IronTesseract();
// Configure for better accuracy
ocrTesseract.Configuration.BlackListCharacters = "~`$#^*_}{][|\\";
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd;
using var input = new OcrImageInput(imageStream);
// Apply preprocessing filters
input.Deskew();
input.DeNoise();
input.Sharpen();
var result = ocrTesseract.Read(input);
return result.Text;
}
ImportsIronOcrImportsIronSoftware.DrawingImportsSystem.IO' Process stream with filtersPublic Function ProcessStreamWithFilters(imageStream AsStream) AsString Dim ocrTesseract As New IronTesseract() ' Configure for better accuracy ocrTesseract.Configuration.BlackListCharacters = "~`$#^*_}{][|\" ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsdUsing input As New OcrImageInput(imageStream) ' Apply preprocessing filters input.Deskew() input.DeNoise() input.Sharpen() Dim result = ocrTesseract.Read(input) Return result.TextEndUsingEnd Function
Imports IronOcr
Imports IronSoftware.Drawing
Imports System.IO
' Process stream with filters
Public Function ProcessStreamWithFilters(imageStream As Stream) As String
Dim ocrTesseract As New IronTesseract()
' Configure for better accuracy
ocrTesseract.Configuration.BlackListCharacters = "~`$#^*_}{][|\"
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd
Using input As New OcrImageInput(imageStream)
' Apply preprocessing filters
input.Deskew()
input.DeNoise()
input.Sharpen()
Dim result = ocrTesseract.Read(input)
Return result.Text
End Using
End Function
// From MemoryStreambyte[] imageBytes = GetImageBytesFromDatabase();using var memoryStream = new MemoryStream(imageBytes);using var input = new OcrImageInput(memoryStream);// From FileStreamusing var fileStream = new FileStream("document.png", FileMode.Open);using var input2 = new OcrImageInput(fileStream);// From network streamusing var webClient = new WebClient();using var networkStream = webClient.OpenRead("https://example.com/image.jpg");using var input3 = new OcrImageInput(networkStream);
// From MemoryStream
byte[] imageBytes = GetImageBytesFromDatabase();
using var memoryStream = new MemoryStream(imageBytes);
using var input = new OcrImageInput(memoryStream);
// From FileStream
using var fileStream = new FileStream("document.png", FileMode.Open);
using var input2 = new OcrImageInput(fileStream);
// From network stream
using var webClient = new WebClient();
using var networkStream = webClient.OpenRead("https://example.com/image.jpg");
using var input3 = new OcrImageInput(networkStream);
ImportsSystem.IOImportsSystem.Net' From MemoryStreamDim imageBytes AsByte() = GetImageBytesFromDatabase()Using memoryStream As New MemoryStream(imageBytes)Using input As New OcrImageInput(memoryStream) ' Process inputEndUsingEndUsing' From FileStreamUsing fileStream As New FileStream("document.png", FileMode.Open)Using input2 As New OcrImageInput(fileStream) ' Process input2EndUsingEndUsing' From network streamUsing webClient As New WebClient()Using networkStream AsStream = webClient.OpenRead("https://example.com/image.jpg")Using input3 As New OcrImageInput(networkStream) ' Process input3EndUsingEndUsingEndUsing
Imports System.IO
Imports System.Net
' From MemoryStream
Dim imageBytes As Byte() = GetImageBytesFromDatabase()
Using memoryStream As New MemoryStream(imageBytes)
Using input As New OcrImageInput(memoryStream)
' Process input
End Using
End Using
' From FileStream
Using fileStream As New FileStream("document.png", FileMode.Open)
Using input2 As New OcrImageInput(fileStream)
' Process input2
End Using
End Using
' From network stream
Using webClient As New WebClient()
Using networkStream As Stream = webClient.OpenRead("https://example.com/image.jpg")
Using input3 As New OcrImageInput(networkStream)
' Process input3
End Using
End Using
End Using
最快捷的方法是用您的数据流创建一个 OcrInput 对象,然后调用读取方法:"using var input = new IronOcr.OcrInput(stream); var result = new IronOcr.IronTesseract().Read(input); "。这段简短的代码将执行 OCR 并立即返回识别的文本。
What should I consider for optimal performance with stream-based OCR?
For optimal performance, reuse `IronTesseract` instances, implement progress tracking, process in parallel, and optimize image quality before processing. These strategies can enhance throughput and efficiency for high-volume OCR tasks.
What are common troubleshooting tips for using streams in IronOCR?
Common troubleshooting tips include ensuring stream position is reset to `0` before processing, using `using` statements for resource cleanup, and confirming that all supported image formats are correctly handled.
How does IronOCR improve OCR for low-quality streams?
IronOCR offers preprocessing techniques to enhance OCR on low-quality streams. By applying filters and other image optimizations, recognition rates can significantly improve, especially for documents with poor scan quality.
Can IronOCR process multiple page documents using streams?
Yes, IronOCR can efficiently process multiple page documents through stream handling, maintaining a user-friendly API and offering robust performance suitable for PDF streams and other multi-page formats.