stringText = new IronTesseract().Read(@"img\Screenshot.png").Text;
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
DimTextAsString = (New IronTesseract()).Read("img\Screenshot.png").Text
Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
可配置的 Hello World.
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();// Add multiple imagesinput.LoadImage("images/sample.jpeg");OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Add multiple images
input.LoadImage("images/sample.jpeg");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusing' Add multiple imagesinput.LoadImage("images/sample.jpeg")Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Add multiple images
input.LoadImage("images/sample.jpeg")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
C# PDF OCR
相同的方法也可以用来从任何PDF文档中提取文本。
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();// We can also select specific PDF page numbers to OCRinput.LoadPdf("example.pdf", Password: "password");OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);// 1 page for every page of the PDFConsole.WriteLine($"{result.Pages.Length} Pages");
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password: "password");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
// 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages");
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusing' We can also select specific PDF page numbers to OCRinput.LoadPdf("example.pdf", Password:= "password")Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)' 1 page for every page of the PDFConsole.WriteLine($"{result.Pages.Length} Pages")
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password:= "password")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
' 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages")
用于多页 TIFF 的OCR
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames("multi-frame.tiff", pageindices);OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageindices);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusingPrivate pageindices = New Integer() { 1, 2 }input.LoadImageFrames("multi-frame.tiff", pageindices)Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
using IronOcr;IronTesseract ocr = new IronTesseract();ocr.Configuration.ReadBarCodes = true;using OcrInput input = new OcrInput();input.LoadImage("img/Barcode.png");OcrResultResult = ocr.Read(input);foreach (varBarcodeinResult.Barcodes){ // type and location properties also exposedConsole.WriteLine(Barcode.Value);}
using IronOcr;
IronTesseract ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
input.LoadImage("img/Barcode.png");
OcrResult Result = ocr.Read(input);
foreach (var Barcode in Result.Barcodes)
{
// type and location properties also exposed
Console.WriteLine(Barcode.Value);
}
ImportsIronOcrPrivate ocr As New IronTesseract()ocr.Configuration.ReadBarCodes = TrueUsing input As New OcrInput() input.LoadImage("img/Barcode.png") DimResultAsOcrResult = ocr.Read(input) For EachBarcodeInResult.Barcodes ' type and location properties also exposedConsole.WriteLine(Barcode.Value) NextBarcodeEndUsing
Imports IronOcr
Private ocr As New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
input.LoadImage("img/Barcode.png")
Dim Result As OcrResult = ocr.Read(input)
For Each Barcode In Result.Barcodes
' type and location properties also exposed
Console.WriteLine(Barcode.Value)
Next Barcode
End Using
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();// Dimensions are in pixelvar contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };input.LoadImage("document.png", contentArea);OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Dimensions are in pixel
var contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
input.LoadImage("document.png", contentArea);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusing' Dimensions are in pixelPrivate contentArea = New System.Drawing.Rectangle() With { .X = 215, .Y = 1250, .Height = 280, .Width = 1335}input.LoadImage("document.png", contentArea)Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Dimensions are in pixel
Private contentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadImage("document.png", contentArea)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
用于低质量扫描的OCR
IronOCR OcrInput类可以修复正常Tesseract无法读取的扫描。
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames(@"img\Potter.tiff", pageindices);// fixes digital noise and poor scanninginput.DeNoise();// fixes rotation and perspectiveinput.Deskew();OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageindices);
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusingPrivate pageindices = New Integer() { 1, 2 }input.LoadImageFrames("img\Potter.tiff", pageindices)' fixes digital noise and poor scanninginput.DeNoise()' fixes rotation and perspectiveinput.Deskew()Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageindices)
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
将 OCR 结果导出为可搜索的 PDF 文件
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();input.Title = "Quarterly Report";input.LoadImage("image1.jpeg");input.LoadImage("image2.png");var pageindices = new int[] { 1, 2 };input.LoadImageFrames("image3.gif", pageindices);OcrResult result = ocr.Read(input);result.SaveAsSearchablePdf("searchable.pdf");
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Quarterly Report";
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", pageindices);
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusinginput.Title = "Quarterly Report"input.LoadImage("image1.jpeg")input.LoadImage("image2.png")Dim pageindices = New Integer() { 1, 2 }input.LoadImageFrames("image3.gif", pageindices)Dim result AsOcrResult = ocr.Read(input)result.SaveAsSearchablePdf("searchable.pdf")
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Quarterly Report"
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("image3.gif", pageindices)
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")
TIFF转可搜索PDF转换
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames("example.tiff", pageindices);ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageindices);
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusingPrivate pageindices = New Integer() { 1, 2 }input.LoadImageFrames("example.tiff", pageindices)ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageindices)
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")
将 OCR 结果导出为 HTML.
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();input.Title = "Html Title";input.LoadImage("image1.jpeg");OcrResultResult = ocr.Read(input);Result.SaveAsHocrFile("results.html");
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Html Title";
input.LoadImage("image1.jpeg");
OcrResult Result = ocr.Read(input);
Result.SaveAsHocrFile("results.html");
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusinginput.Title = "Html Title"input.LoadImage("image1.jpeg")DimResultAsOcrResult = ocr.Read(input)Result.SaveAsHocrFile("results.html")
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Html Title"
input.LoadImage("image1.jpeg")
Dim Result As OcrResult = ocr.Read(input)
Result.SaveAsHocrFile("results.html")
OCR 图像增强过滤器
IronOCR为OcrInput对象提供独特的过滤器,以提高OCR性能。
图像增强代码示例
using IronOcr;IronTesseract ocr = new IronTesseract();using OcrInput input = new OcrInput();input.LoadImage("LowQuality.jpeg");// fixes digital noise and poor scanninginput.DeNoise();// fixes rotation and perspectiveinput.Deskew();OcrResult result = ocr.Read(input);Console.WriteLine(result.Text);
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.LoadImage("LowQuality.jpeg");
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
ImportsIronOcrPrivate ocr As New IronTesseract()PrivateOcrInputAsusinginput.LoadImage("LowQuality.jpeg")' fixes digital noise and poor scanninginput.DeNoise()' fixes rotation and perspectiveinput.Deskew()Dim result AsOcrResult = ocr.Read(input)Console.WriteLine(result.Text)
Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.LoadImage("LowQuality.jpeg")
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
using IronOcr;// PM> Install IronOcr.Languages.ArabicIronTesseract ocr = new IronTesseract();ocr.Language = OcrLanguage.Arabic;using OcrInput input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames("img/arabic.gif", pageindices);// Add image filters if needed// In this case, even thought input is very low quality// IronTesseract can read what conventional Tesseract cannot.OcrResult result = ocr.Read(input);// Console can't print Arabic on Windows easily.// Let's save to disk instead.result.SaveAsTextFile("arabic.txt");
using IronOcr;
// PM> Install IronOcr.Languages.Arabic
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
OcrResult result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");
ImportsIronOcr' PM> Install IronOcr.Languages.ArabicPrivate ocr As New IronTesseract()ocr.Language = OcrLanguage.ArabicUsing input As New OcrInput() Dim pageindices = New Integer() { 1, 2 } input.LoadImageFrames("img/arabic.gif", pageindices) ' Add image filters if needed ' In this case, even thought input is very low quality ' IronTesseract can read what conventional Tesseract cannot. Dim result AsOcrResult = ocr.Read(input) ' Console can't print Arabic on Windows easily. ' Let's save to disk instead. result.SaveAsTextFile("arabic.txt")EndUsing
Imports IronOcr
' PM> Install IronOcr.Languages.Arabic
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result As OcrResult = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
End Using
using IronOcr;// PM> Install IronOcr.Languages.ChineseSimplifiedIronTesseract ocr = new IronTesseract();ocr.Language = OcrLanguage.ChineseSimplified;// We can add any number of languagesocr.AddSecondaryLanguage(OcrLanguage.English);using OcrInput input = new OcrInput();input.LoadPdf("multi-language.pdf");OcrResult result = ocr.Read(input);result.SaveAsTextFile("results.txt");
using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
// We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English);
using OcrInput input = new OcrInput();
input.LoadPdf("multi-language.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsTextFile("results.txt");
ImportsIronOcr' PM> Install IronOcr.Languages.ChineseSimplifiedPrivate ocr As New IronTesseract()ocr.Language = OcrLanguage.ChineseSimplified' We can add any number of languagesocr.AddSecondaryLanguage(OcrLanguage.English)Using input As New OcrInput() input.LoadPdf("multi-language.pdf") Dim result AsOcrResult = ocr.Read(input) result.SaveAsTextFile("results.txt")EndUsing
Imports IronOcr
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
' We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English)
Using input As New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsTextFile("results.txt")
End Using
using IronOcr;IronTesseract ocr = new IronTesseract();// Must be set to true to read barcodeocr.Configuration.ReadBarCodes = true;using OcrInput input = new OcrInput();var pageindices = new int[] { 1, 2 };input.LoadImageFrames(@"img\sample.tiff", pageindices);OcrResult result = ocr.Read(input);var pages = result.Pages;var words = pages[0].Words;var barcodes = result.Barcodes;// Explore here to find a massive, detailed API:// - Pages, Blocks, Paraphaphs, Lines, Words, Chars// - Image Export, Fonts Coordinates, Statistical Data, Tables
using IronOcr;
IronTesseract ocr = new IronTesseract();
// Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\sample.tiff", pageindices);
OcrResult result = ocr.Read(input);
var pages = result.Pages;
var words = pages[0].Words;
var barcodes = result.Barcodes;
// Explore here to find a massive, detailed API:
// - Pages, Blocks, Paraphaphs, Lines, Words, Chars
// - Image Export, Fonts Coordinates, Statistical Data, Tables
ImportsIronOcrPrivate ocr As New IronTesseract()' Must be set to true to read barcodeocr.Configuration.ReadBarCodes = TrueUsing input As New OcrInput() Dim pageindices = New Integer() { 1, 2 } input.LoadImageFrames("img\sample.tiff", pageindices) Dim result AsOcrResult = ocr.Read(input) Dim pages = result.Pages Dim words = pages(0).Words Dim barcodes = result.Barcodes ' Explore here to find a massive, detailed API: ' - Pages, Blocks, Paraphaphs, Lines, Words, Chars ' - Image Export, Fonts Coordinates, Statistical Data, TablesEndUsing
Imports IronOcr
Private ocr As New IronTesseract()
' Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\sample.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Dim pages = result.Pages
Dim words = pages(0).Words
Dim barcodes = result.Barcodes
' Explore here to find a massive, detailed API:
' - Pages, Blocks, Paraphaphs, Lines, Words, Chars
' - Image Export, Fonts Coordinates, Statistical Data, Tables
End Using