<meta http-equiv="content-language" content="zh" />
<h1>C#和.NET的中文OCR</h1>
<h6>本文档的其他版本:</h6>
<ul>
<li><a href="../chinese">英語版 (This Page in English)</a></li>
<li><a href="/csharp/ocr/languages/">更多語言</a></li>
</ul>
<p>IronOCR是C#軟體組件,允許.NET編碼人員以126種語言(包括簡體和繁體中文)從圖像和PDF文件中讀取文字。語言包有簡體和繁體中文字元。</p>
<p>它是Tesseract的高級分支,專門爲.NET開發人員構建,在速度和準確性方面均經常優於其他Tesseract引擎。</p>
<h2> IronOCR語言中文的內容</h2>
<p>該軟體包包含352種.NET的OCR語言:</p>
<ul>
<li>簡體中文</li>
<li>簡體中文最佳</li>
<li>簡體中文快速</li>
<li>中文簡體垂直</li>
<li>簡體中文垂直最佳</li>
<li>簡體中文垂直快速</li>
<li>中國傳統的</li>
<li>中國傳統最佳</li>
<li>中國傳統快</li>
<li>中文繁體垂直</li>
<li>中國傳統垂直最佳</li>
<li>中文繁體垂直快速</li>
</ul>
<h2>下载</h2>
<p>中文語言包<span style='white-space:default'>[中文(Zhōngwén)]</span> <br/> * Download as <a class='languages-dll'
href='/csharp/ocr/packages/language-packs/Chinese.ocrdata.zip'>壓縮<i class='fas fa-download'></i><br/> * Install with as
</a><a target='_blank' class='languages-nuget'
href="https://www.nuget.org/packages/IronOcr.Languages.Chinese/">https://www.nuget.org/packages/IronOcr.Languages.Chinese/</a>'>
NuGet<i class='nuget-icon'></i></p>
<h2>安装</h2>
<p>我們要做的第一件事是將我們的<strong>中文</strong>OCR軟體包安裝到您的.NET項目中。</p>
<p> <code>PM> Install-Package IronOcr.Languages.Chinese</code></p>
<h2>程式碼範例</h2>
<p>此C#程式碼範例從Image或PDF文件中讀取簡體中文文字。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Use an OcrInput to load the image
using (var Input = new OcrInput(@"images\Chinese.png"))
{
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Retrieve the recognized text
var AllText = Result.Text;
// Output the recognized text to the console
Console.WriteLine(AllText);
}
```
<h2>爲什麼選擇IronOCR?</h2>
<p> IronOCR是易於安裝,完整且文件證明的.NET軟體庫。</p>
<p>選擇IronOCR可獲得<strong>99.8%+的OCR準確性,</strong>而無需使用任何外部Web服務,持續的費用或通過Internet發送機密文件。</p>
<h4>爲什麼C#開發人員選擇IronOCR而不是Vanilla Tesseract:</h4>
<ul>
<li>作爲單個DLL或Nuget安裝</li>
<li>包括開箱即用的Tesseract 5、4和3發動機。</li>
<li>準確率 99.8% 明顯優於常規Tesseract。</li>
<li>極快的速度和多執行緒支持</li>
<li>相容MVC,WebApp,桌面,控制檯和伺服器應用程式</li>
<li>沒有可以使用的Exes或C ++程式碼</li>
<li>完整的PDF OCR支持</li>
<li>對幾乎所有圖像文件或PDF執行OCR</li>
<li>全面的.NET Core,Standard和FrameWork支持</li>
<li>在Windows,Mac,Linux,Azure,Docker,Lambda,AWS上部署</li>
<li>讀取條形碼和QR碼</li>
<li>將OCR導出爲XHTML</li>
<li>将OCR导出到可搜索的PDF文档</li>
<li>多執行緒支持</li>
<li>通過Nuget或OcrData文件管理的126種國際語言</li>
<li>提取圖像,座標,統計資訊和字體。 不只是文字。</li>
<li>可用於在商業和專有應用程式中重新分發Tesseract OCR。</li>
</ul>
<p><em>當處理真實世界的圖像和不完善的文件(例如照片)或具有數字噪點或不完美的低解析度掃描時,IronOCR會發光。</em></p>
<p> .NET平臺的其他<a href="/csharp/ocr/use-case/free-ocr-csharp/">免費OCR</a>庫(例如其他.NET Tesseract API和Web服務)在這些實際使用案例中的性能不佳。</p>
<h2>帶Tesseract 5的OCR-在C#中開始編碼</h2>
<p>下面的程式碼範例顯示了使用C#或VB .NET從圖像讀取文字是多麼容易。</p>
<h3> OneLiner: 最簡單的一行程式碼</h3>
```csharp
// Quick one-liner to read text from image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
```
<h3>可配置的Hello World</h3>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Create and configure OcrInput
using (var Input = new OcrInput())
{
Input.AddImage("images/sample.jpeg");
// You can add multiple images
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
```
<h3>C#PDF OCR</h3>
<p>可以類似地使用相同的方法從任何PDF文件中提取文字。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from PDF
using (var input = new OcrInput())
{
input.AddPdf("example.pdf", "password");
// Optionally select specific PDF pages for OCR
var Result = Ocr.Read(input);
// Display the recognized text and page count
Console.WriteLine(Result.Text);
Console.WriteLine($"{Result.Pages.Count()} Pages");
// 1 page per PDF page
}
```
<h3>多頁TIFF的OCR</h3>
<p> OCR讀取TIFF文件格式,包括多個頁面文件。 TIFF也可以直接轉換爲帶有可搜索文字的PDF文件。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from multi-frame TIFF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
```
<h3>條碼和QR</h3>
<p> IronOCR的獨特功能是在掃描文字時可以讀取文件中的條形碼和QR碼。 <code>OcrResult.OcrBarcode</code>類的實例爲開發人員提供了有關每個掃描條形碼的詳細資訊。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing with barcode reading enabled
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// OCR with barcode scanning
using (var input = new OcrInput())
{
input.AddImage("img/Barcode.png");
var Result = Ocr.Read(input);
// Output recognized barcodes
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Type and location properties are also exposed
}
}
```
<h3>圖像特定區域的OCR</h3>
<p> IronOCR的所有掃描和讀取方法均提供了準確指定要從中讀取文字的頁面的哪一部分的功能。 當我們查看標準化表格時,這非常有用,可以節省大量時間並提高效率。</p>
<p>要使用裁剪區域,我們將需要新增對<code>System.Drawing</code>的系統引用,以便可以使用<code>System.Drawing.Rectangle</code>物件。</p>
```csharp
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure this assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from a specific area of an image
using (var Input = new OcrInput())
{
var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions are in pixels
Input.Add("document.png", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text); // Output the recognized text
}
```
<h3>OCR用于低质量扫描</h3>
<p>IronOCR <code>OcrInput</code>類可以修復普通Tesseract無法讀取的掃描。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from low quality scan
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
Input.DeNoise(); // Fix digital noise and bad scan quality
Input.Deskew(); // Correct the rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
```
<h3>將OCR結果導出爲可搜索的PDF</h3>
<p>帶有可複製文字字串的圖像到PDF。 可以由搜索引擎和資料庫建立索引。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to a searchable PDF
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf"); // Save results as searchable PDF
}
```
<h3>TIFF到可搜索的PDF轉換</h3>
<p>將TIFF文件(或任何圖像文件組)直接轉換爲可搜索的PDF,可通過Intranet,網站和google搜索引擎對其進行索引。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert TIFF to searchable PDF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf");
}
```
<h3>將OCR結果導出爲HTML</h3>
<p> OCR圖像到XHTML的轉換。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to HTML format
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html"); // Save results as HTML
}
```
<h2>OCR圖像增強濾鏡</h2>
<p>IronOCR爲<code>OcrInput</code>物件提供了獨特的過濾器,以提高OCR性能。</p>
<h3>圖像增強程式碼範例</h3>
<p>使OCR輸入圖像質量更高,以產生更好,更快的OCR結果。</p>
```csharp
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Enhance low quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
Input.DeNoise(); // Fix digital noise
Input.Deskew(); // Correct rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
```
<h3>OCR圖像過濾器列表</h3>
<p>IronOCR內建的用於增強OCR性能的輸入濾波器包括:</p>
<p> <strong>Rotate</strong> -順時針旋轉圖像數度。 對於逆時針,請使用負數。</p>
<p> <strong>Binarize</strong> -此圖像過濾器將每個像素變爲黑色或白色,而沒有中間地線。可能會改善文字與背景對比度非常低的OCR性能。</p>
<p> <strong>ToGrayScale</strong> -此圖像過濾器將每個像素變成灰度陰影。 不太可能提高OCR精度,但可能會提高速度</p>
<p> <strong>Contrast</strong> -自動增加對比度。 在低對比度掃描中,此過濾器通常可以提高OCR速度和準確性。</p>
<p> <strong>DeNoise</strong> -消除數字噪聲。 該濾波器僅應在預期有噪聲的地方使用。</p>
<p> <strong>Invert</strong> -反轉每種顏色。 例如,白色變成黑色:黑色變成白色。</p>
<p> <strong>Dilate</strong> -高級形態。 <em>膨脹</em>將像素新增到圖像中物件的邊界。侵蝕對面</p>
<p> <strong>Erode</strong> -高級形態。 <em>侵蝕</em>去除了物件邊界上的像素</p>
<p> <strong>Deskew</strong> -旋轉圖像,使其朝上且正交。 這對於OCR非常有用,因爲Tesseract對傾斜掃描的公差可以低至5度。</p>
<p> <strong>DeepCleanBackgroundNoise</strong>-消除大量背景噪音。 僅在已知極端文件背景噪音的情況下使用此過濾器,因爲此過濾器還會冒降低乾淨文件的OCR準確性的風險,並且CPU成本很高。</p>
<p> <strong>EnhanceResolution</strong>增強低質量圖像的解析度。 由於<em>OcrInput.MinimumDPI</em>和<em>OcrInput.TargetDPI</em>將自動捕獲並解析低解析度輸入,因此通常不需要此過濾器。</p>
<p> <strong>CleanBackgroundNoise</strong> 這種設置有些耗時。 但是,它允許該庫自動清除數字圖像中的數字噪音,紙屑和其他瑕疵,否則將使其無法被其他OCR庫讀取。</p>
<p> <strong>EnhanceContrast</strong> 是一種設置,可使IronOCR自動增加文字與圖像背景的對比度,從而提高OCR的準確性,並通常提高OCR的性能和速度。</p>
<p> <strong>EnhanceResolution</strong> 是一項設置,它將自動檢測低解析度圖像(低於275dpi),並自動放大圖像,然後對所有文字進行銳化處理,以便可以由OCR庫完美讀取。 儘管此操作本身很耗時,但通常會減少對圖像進行OCR操作的總時間。</p>
<p> 語言 IronOCR支持22種國際語言包,並且語言設置可用於選擇一種或多種要用於OCR操作的多種語言。</p>
<p> 策略 鐵OCR支持兩種策略。 我們可以選擇對文件進行快速而不太準確的掃描,或者使用高級策略,該策略使用一些人工智能模型通過查看句子中單詞彼此之間的統計關係來自動提高OCR文字的準確性。</p>
<p> <strong>ColorSpace</strong>是一種設置,通過該設置,我們可以選擇灰度或彩色OCR。 通常,灰度是最佳選擇。但是,有時當某些文字或背景的色相相似但顏色差異很大時,全色顏色空間會提供更好的效果。</p>
<p> <strong>DetectWhiteTextOnDarkBackgrounds</strong> 通常,所有OCR庫都希望在白色背景上看到黑色文字。 此設置使IronOCR可以自動檢測底片或帶有白色文字的暗頁並進行讀取。</p>
<p> <strong>InputImageType</strong> 通過此設置,開發人員可以指導OCR庫是查看完整文件還是片段(如螢幕截圖)。</p>
<p> <strong>RotateAndStraighten</strong> 是一種高級設置,它使IronOCR具有讀取不僅旋轉而且還包含透視圖的文件的獨特功能,例如文字文件的照片。</p>
<p> <strong>ReadBarcodes</strong> 是一項有用的功能,它允許IronOCR在讀取文字的同時自動讀取頁面上的條形碼和QR碼,而不會增加大量額外的時間負擔。</p>
<p><strong>顏色深度</strong> 此設置確定OCR庫將使用每個像素多少位來確定顏色的深度。較高的色深可能會提高OCR質量,但也會增加OCR操作完成所需的時間。</p>
<h2> 126語言包</h2>
<p>IronOCR通過以DLL形式分發的語言包支持<strong>126種國際語言</strong>,這些語言包可以<a href="/csharp/ocr/languages/">從本網站下載</a>,也可以從<a
href="https://www.nuget.org/packages?q=IronOcr.Languages">NuGet軟體包管理器下載</a>。</p>
<p>語言包括德語,法語,英語,中文,日語等。 存在用於護照MRZ,MICR支票,財務資料,車牌等的專業語言包。 您還可以使用任何Tesseract“ .traineddata”文件-包括您自己建立的文件。</p>
<h3>語言範例</h3>
<p>使用其他OCR語言。</p>
```csharp
// Import the IronOcr library
// Ensure the Arabic language package is installed via NuGet
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic; // Set language to Arabic
// OCR using Arabic language
using (var input = new OcrInput())
{
input.AddImage("img/arabic.gif");
// Add image filters as needed
// This can improve OCR accuracy even with lower quality inputs
var Result = Ocr.Read(input);
// Saving Arabic text to file, console may not display correctly
Result.SaveAsTextFile("arabic.txt");
}
```
<h3>多語言範例</h3>
<p>也可以同時使用多種語言進行OCR。 這確實可以幫助獲取Unicode文件中的英語元資料和URL。</p>
```csharp
// Import the IronOcr library
// Ensure the Chinese Simplified and other required languages are installed via NuGet
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Chinese);
// You can add multiple secondary languages
// OCR multi-language document
using (var input = new OcrInput())
{
input.Add("multi-language.pdf");
var Result = Ocr.Read(input);
Result.SaveAsTextFile("results.txt"); // Save results
}
```
<h2>詳細的OCR結果物件</h2>
<p>IronOCR爲每個OCR操作返回一個OCR結果物件。 通常,開發人員僅使用此物件的text屬性來從圖像中掃描文字。 但是,OCR結果DOM比這要先進得多。</p>
```csharp
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Use both Tesseract and LSTM
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading
// OCR processing
using (var Input = new OcrInput(@"images\sample.tiff"))
{
OcrResult Result = Ocr.Read(Input);
var Pages = Result.Pages;
var Words = Pages[0].Words;
var Barcodes = Result.Barcodes;
// Explore detailed API options here:
// - Pages, Blocks, Paragraphs, Lines, Words, Characters
// - Image Export, Font Coordinates, Statistics
}
```
<h2>性能</h2>
<p>IronOCR開箱即用,無需性能調整或大量修改輸入圖像。</p>
<p>速度飛快:IronOCR.2020 +的速度提高了10倍,並且比以前的版本減少了250%以上的錯誤。</p>
<h2>學到更多</h2>
<p>要了解有關C#,VB,F#或任何其他.NET語言中OCR的更多資訊,請<a
href="/csharp/ocr/tutorials/how-to-read-text-from-an-image-in-csharp-net/">閱讀我們的社區教程</a>,其中提供了有關如何使用Iron
OCR的真實範例,並可能顯示出如何從中獲得最大收益的細微差別。 這個圖書館。</p>
<p>還提供<a href="/csharp/ocr/object-reference/api/">了.NET開發人員的</a>完整<a href="/csharp/ocr/object-reference/api/">物件參考</a>。</p>
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Use an OcrInput to load the imageusing (varInput = new OcrInput(@"images\Chinese.png")){// Perform OCR on the input imagevarResult = Ocr.Read(Input);// Retrieve the recognized textvarAllText = Result.Text;// Output the recognized text to the consoleConsole.WriteLine(AllText);}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Use an OcrInput to load the image
using (var Input = new OcrInput(@"images\Chinese.png"))
{
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Retrieve the recognized text
var AllText = Result.Text;
// Output the recognized text to the console
Console.WriteLine(AllText);
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Use an OcrInput to load the imageUsingInput = New OcrInput("images\Chinese.png")' Perform OCR on the input imageDimResult = Ocr.Read(Input)' Retrieve the recognized textDimAllText = Result.Text' Output the recognized text to the consoleConsole.WriteLine(AllText)EndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Use an OcrInput to load the image
Using Input = New OcrInput("images\Chinese.png")
' Perform OCR on the input image
Dim Result = Ocr.Read(Input)
' Retrieve the recognized text
Dim AllText = Result.Text
' Output the recognized text to the console
Console.WriteLine(AllText)
End Using
// Quick one-liner to read text from imagestringText = new IronTesseract().Read(@"img\Screenshot.png").Text;
// Quick one-liner to read text from image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
' Quick one-liner to read text from imageDimTextAsString = (New IronTesseract()).Read("img\Screenshot.png").Text
' Quick one-liner to read text from image
Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
可配置的Hello World
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Create and configure OcrInputusing (varInput = new OcrInput()){Input.AddImage("images/sample.jpeg");// You can add multiple images// Perform OCR on the inputvarResult = Ocr.Read(Input);// Output the recognized text to the consoleConsole.WriteLine(Result.Text);}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Create and configure OcrInput
using (var Input = new OcrInput())
{
Input.AddImage("images/sample.jpeg");
// You can add multiple images
// Perform OCR on the input
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Create and configure OcrInputUsingInput = New OcrInput()Input.AddImage("images/sample.jpeg")' You can add multiple images' Perform OCR on the inputDimResult = Ocr.Read(Input)' Output the recognized text to the consoleConsole.WriteLine(Result.Text)EndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Create and configure OcrInput
Using Input = New OcrInput()
Input.AddImage("images/sample.jpeg")
' You can add multiple images
' Perform OCR on the input
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Using
C#PDF OCR
可以類似地使用相同的方法從任何PDF文件中提取文字。
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// OCR from PDFusing (var input = new OcrInput()){input.AddPdf("example.pdf", "password");// Optionally select specific PDF pages for OCRvarResult = Ocr.Read(input);// Display the recognized text and page countConsole.WriteLine(Result.Text);Console.WriteLine($"{Result.Pages.Count()} Pages");// 1 page per PDF page}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from PDF
using (var input = new OcrInput())
{
input.AddPdf("example.pdf", "password");
// Optionally select specific PDF pages for OCR
var Result = Ocr.Read(input);
// Display the recognized text and page count
Console.WriteLine(Result.Text);
Console.WriteLine($"{Result.Pages.Count()} Pages");
// 1 page per PDF page
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' OCR from PDFUsing input = New OcrInput()input.AddPdf("example.pdf", "password")' Optionally select specific PDF pages for OCRDimResult = Ocr.Read(input)' Display the recognized text and page countConsole.WriteLine(Result.Text)Console.WriteLine($"{Result.Pages.Count()} Pages")' 1 page per PDF pageEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from PDF
Using input = New OcrInput()
input.AddPdf("example.pdf", "password")
' Optionally select specific PDF pages for OCR
Dim Result = Ocr.Read(input)
' Display the recognized text and page count
Console.WriteLine(Result.Text)
Console.WriteLine($"{Result.Pages.Count()} Pages")
' 1 page per PDF page
End Using
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// OCR from multi-frame TIFFusing (varInput = new OcrInput()){Input.AddMultiFrameTiff("multi-frame.tiff");varResult = Ocr.Read(Input);// Output the recognized text to the consoleConsole.WriteLine(Result.Text);}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from multi-frame TIFF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' OCR from multi-frame TIFFUsingInput = New OcrInput()Input.AddMultiFrameTiff("multi-frame.tiff")DimResult = Ocr.Read(Input)' Output the recognized text to the consoleConsole.WriteLine(Result.Text)EndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from multi-frame TIFF
Using Input = New OcrInput()
Input.AddMultiFrameTiff("multi-frame.tiff")
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Using
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processing with barcode reading enabledvarOcr = new IronTesseract();Ocr.Configuration.ReadBarCodes = true;// OCR with barcode scanningusing (var input = new OcrInput()){input.AddImage("img/Barcode.png");varResult = Ocr.Read(input);// Output recognized barcodesforeach (varBarcodeinResult.Barcodes){Console.WriteLine(Barcode.Value);// Type and location properties are also exposed}}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing with barcode reading enabled
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// OCR with barcode scanning
using (var input = new OcrInput())
{
input.AddImage("img/Barcode.png");
var Result = Ocr.Read(input);
// Output recognized barcodes
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Type and location properties are also exposed
}
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processing with barcode reading enabledPrivateOcr = New IronTesseract()Ocr.Configuration.ReadBarCodes = True' OCR with barcode scanningUsing input = New OcrInput()input.AddImage("img/Barcode.png")DimResult = Ocr.Read(input)' Output recognized barcodesFor EachBarcodeInResult.BarcodesConsole.WriteLine(Barcode.Value)' Type and location properties are also exposedNextBarcodeEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing with barcode reading enabled
Private Ocr = New IronTesseract()
Ocr.Configuration.ReadBarCodes = True
' OCR with barcode scanning
Using input = New OcrInput()
input.AddImage("img/Barcode.png")
Dim Result = Ocr.Read(input)
' Output recognized barcodes
For Each Barcode In Result.Barcodes
Console.WriteLine(Barcode.Value)
' Type and location properties are also exposed
Next Barcode
End Using
// Import the IronOcr libraryusing IronOcr;using System.Drawing; // Ensure this assembly reference is added// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// OCR from a specific area of an imageusing (varInput = new OcrInput()){varContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };// Dimensions are in pixelsInput.Add("document.png", ContentArea);varResult = Ocr.Read(Input);Console.WriteLine(Result.Text); // Output the recognized text}
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure this assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from a specific area of an image
using (var Input = new OcrInput())
{
var ContentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions are in pixels
Input.Add("document.png", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr libraryImportsIronOcrImportsSystem.Drawing' Ensure this assembly reference is added' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' OCR from a specific area of an imageUsingInput = New OcrInput()DimContentArea = New System.Drawing.Rectangle() With { .X = 215, .Y = 1250, .Height = 280, .Width = 1335}' Dimensions are in pixelsInput.Add("document.png", ContentArea)DimResult = Ocr.Read(Input)Console.WriteLine(Result.Text) ' Output the recognized textEndUsing
' Import the IronOcr library
Imports IronOcr
Imports System.Drawing ' Ensure this assembly reference is added
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from a specific area of an image
Using Input = New OcrInput()
Dim ContentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
' Dimensions are in pixels
Input.Add("document.png", ContentArea)
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
OCR用于低质量扫描
IronOCR OcrInput類可以修復普通Tesseract無法讀取的掃描。
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// OCR from low quality scanusing (varInput = new OcrInput(@"img\Potter.LowQuality.tiff")){Input.DeNoise(); // Fix digital noise and bad scan qualityInput.Deskew(); // Correct the rotation and perspectivevarResult = Ocr.Read(Input); // Perform the OCRConsole.WriteLine(Result.Text); // Output the recognized text}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// OCR from low quality scan
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
Input.DeNoise(); // Fix digital noise and bad scan quality
Input.Deskew(); // Correct the rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' OCR from low quality scanUsingInput = New OcrInput("img\Potter.LowQuality.tiff")Input.DeNoise() ' Fix digital noise and bad scan qualityInput.Deskew() ' Correct the rotation and perspectiveDimResult = Ocr.Read(Input) ' Perform the OCRConsole.WriteLine(Result.Text) ' Output the recognized textEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' OCR from low quality scan
Using Input = New OcrInput("img\Potter.LowQuality.tiff")
Input.DeNoise() ' Fix digital noise and bad scan quality
Input.Deskew() ' Correct the rotation and perspective
Dim Result = Ocr.Read(Input) ' Perform the OCR
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
將OCR結果導出爲可搜索的PDF
帶有可複製文字字串的圖像到PDF。 可以由搜索引擎和資料庫建立索引。
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Convert OCR results to a searchable PDFusing (varInput = new OcrInput()){Input.Title = "Quarterly Report";Input.AddImage("image1.jpeg");Input.AddImage("image2.png");Input.AddImage("image3.gif");varResult = Ocr.Read(Input);Result.SaveAsSearchablePdf("searchable.pdf"); // Save results as searchable PDF}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to a searchable PDF
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf"); // Save results as searchable PDF
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Convert OCR results to a searchable PDFUsingInput = New OcrInput()Input.Title = "Quarterly Report"Input.AddImage("image1.jpeg")Input.AddImage("image2.png")Input.AddImage("image3.gif")DimResult = Ocr.Read(Input)Result.SaveAsSearchablePdf("searchable.pdf") ' Save results as searchable PDFEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert OCR results to a searchable PDF
Using Input = New OcrInput()
Input.Title = "Quarterly Report"
Input.AddImage("image1.jpeg")
Input.AddImage("image2.png")
Input.AddImage("image3.gif")
Dim Result = Ocr.Read(Input)
Result.SaveAsSearchablePdf("searchable.pdf") ' Save results as searchable PDF
End Using
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Convert TIFF to searchable PDFusing (varInput = new OcrInput()){Input.AddMultiFrameTiff("example.tiff");Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf");}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert TIFF to searchable PDF
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf");
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Convert TIFF to searchable PDFUsingInput = New OcrInput()Input.AddMultiFrameTiff("example.tiff")Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf")EndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert TIFF to searchable PDF
Using Input = New OcrInput()
Input.AddMultiFrameTiff("example.tiff")
Ocr.Read(Input).SaveAsSearchablePdf("searchable.pdf")
End Using
將OCR結果導出爲HTML
OCR圖像到XHTML的轉換。
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Convert OCR results to HTML formatusing (varInput = new OcrInput()){Input.Title = "Html Title";Input.AddImage("image1.jpeg");varResult = Ocr.Read(Input);Result.SaveAsHocrFile("results.html"); // Save results as HTML}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Convert OCR results to HTML format
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html"); // Save results as HTML
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Convert OCR results to HTML formatUsingInput = New OcrInput()Input.Title = "Html Title"Input.AddImage("image1.jpeg")DimResult = Ocr.Read(Input)Result.SaveAsHocrFile("results.html") ' Save results as HTMLEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Convert OCR results to HTML format
Using Input = New OcrInput()
Input.Title = "Html Title"
Input.AddImage("image1.jpeg")
Dim Result = Ocr.Read(Input)
Result.SaveAsHocrFile("results.html") ' Save results as HTML
End Using
OCR圖像增強濾鏡
IronOCR爲OcrInput物件提供了獨特的過濾器,以提高OCR性能。
圖像增強程式碼範例
使OCR輸入圖像質量更高,以產生更好,更快的OCR結果。
// Import the IronOcr libraryusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese// Enhance low quality image for OCRusing (varInput = new OcrInput(@"LowQuality.jpeg")){Input.DeNoise(); // Fix digital noiseInput.Deskew(); // Correct rotation and perspectivevarResult = Ocr.Read(Input); // Perform the OCRConsole.WriteLine(Result.Text); // Output the recognized text}
// Import the IronOcr library
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
// Enhance low quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
Input.DeNoise(); // Fix digital noise
Input.Deskew(); // Correct rotation and perspective
var Result = Ocr.Read(Input); // Perform the OCR
Console.WriteLine(Result.Text); // Output the recognized text
}
' Import the IronOcr libraryImportsIronOcr' Create an instance of IronTesseract for OCR processingPrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to Chinese' Enhance low quality image for OCRUsingInput = New OcrInput("LowQuality.jpeg")Input.DeNoise() ' Fix digital noiseInput.Deskew() ' Correct rotation and perspectiveDimResult = Ocr.Read(Input) ' Perform the OCRConsole.WriteLine(Result.Text) ' Output the recognized textEndUsing
' Import the IronOcr library
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
' Enhance low quality image for OCR
Using Input = New OcrInput("LowQuality.jpeg")
Input.DeNoise() ' Fix digital noise
Input.Deskew() ' Correct rotation and perspective
Dim Result = Ocr.Read(Input) ' Perform the OCR
Console.WriteLine(Result.Text) ' Output the recognized text
End Using
// Import the IronOcr library// Ensure the Arabic language package is installed via NuGetusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Arabic; // Set language to Arabic// OCR using Arabic languageusing (var input = new OcrInput()){input.AddImage("img/arabic.gif");// Add image filters as needed// This can improve OCR accuracy even with lower quality inputsvarResult = Ocr.Read(input);// Saving Arabic text to file, console may not display correctlyResult.SaveAsTextFile("arabic.txt");}
// Import the IronOcr library
// Ensure the Arabic language package is installed via NuGet
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic; // Set language to Arabic
// OCR using Arabic language
using (var input = new OcrInput())
{
input.AddImage("img/arabic.gif");
// Add image filters as needed
// This can improve OCR accuracy even with lower quality inputs
var Result = Ocr.Read(input);
// Saving Arabic text to file, console may not display correctly
Result.SaveAsTextFile("arabic.txt");
}
' Import the IronOcr library' Ensure the Arabic language package is installed via NuGetImportsIronOcr' Create an instance of IronTesseract for OCR processingDimOcrAs New IronTesseract()Ocr.Language = OcrLanguage.Arabic' Set language to Arabic' OCR using Arabic languageUsing input As New OcrInput() input.AddImage("img/arabic.gif") ' Add image filters as needed ' This can improve OCR accuracy even with lower quality inputs DimResult = Ocr.Read(input) ' Saving Arabic text to file, console may not display correctlyResult.SaveAsTextFile("arabic.txt")EndUsing
' Import the IronOcr library
' Ensure the Arabic language package is installed via NuGet
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Dim Ocr As New IronTesseract()
Ocr.Language = OcrLanguage.Arabic ' Set language to Arabic
' OCR using Arabic language
Using input As New OcrInput()
input.AddImage("img/arabic.gif")
' Add image filters as needed
' This can improve OCR accuracy even with lower quality inputs
Dim Result = Ocr.Read(input)
' Saving Arabic text to file, console may not display correctly
Result.SaveAsTextFile("arabic.txt")
End Using
多語言範例
也可以同時使用多種語言進行OCR。 這確實可以幫助獲取Unicode文件中的英語元資料和URL。
// Import the IronOcr library// Ensure the Chinese Simplified and other required languages are installed via NuGetusing IronOcr;// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.ChineseSimplified;Ocr.AddSecondaryLanguage(OcrLanguage.Chinese);// You can add multiple secondary languages// OCR multi-language documentusing (var input = new OcrInput()){input.Add("multi-language.pdf");varResult = Ocr.Read(input);Result.SaveAsTextFile("results.txt"); // Save results}
// Import the IronOcr library
// Ensure the Chinese Simplified and other required languages are installed via NuGet
using IronOcr;
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Chinese);
// You can add multiple secondary languages
// OCR multi-language document
using (var input = new OcrInput())
{
input.Add("multi-language.pdf");
var Result = Ocr.Read(input);
Result.SaveAsTextFile("results.txt"); // Save results
}
' Import the IronOcr library' Ensure the Chinese Simplified and other required languages are installed via NuGetImportsIronOcr' Create an instance of IronTesseract for OCR processingDimOcrAs New IronTesseract()Ocr.Language = OcrLanguage.ChineseSimplifiedOcr.AddSecondaryLanguage(OcrLanguage.Chinese)' You can add multiple secondary languages' OCR multi-language documentUsing input As New OcrInput() input.Add("multi-language.pdf") DimResult = Ocr.Read(input)Result.SaveAsTextFile("results.txt") ' Save resultsEndUsing
' Import the IronOcr library
' Ensure the Chinese Simplified and other required languages are installed via NuGet
Imports IronOcr
' Create an instance of IronTesseract for OCR processing
Dim Ocr As New IronTesseract()
Ocr.Language = OcrLanguage.ChineseSimplified
Ocr.AddSecondaryLanguage(OcrLanguage.Chinese)
' You can add multiple secondary languages
' OCR multi-language document
Using input As New OcrInput()
input.Add("multi-language.pdf")
Dim Result = Ocr.Read(input)
Result.SaveAsTextFile("results.txt") ' Save results
End Using
// Import the IronOcr libraryusing IronOcr;using System.Drawing; // Ensure assembly reference is added// Create an instance of IronTesseract for OCR processingvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Chinese; // Set language to ChineseOcr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Use both Tesseract and LSTMOcr.Configuration.ReadBarCodes = true; // Enable barcode reading// OCR processingusing (varInput = new OcrInput(@"images\sample.tiff")){OcrResultResult = Ocr.Read(Input);varPages = Result.Pages;varWords = Pages[0].Words;varBarcodes = Result.Barcodes;// Explore detailed API options here:// - Pages, Blocks, Paragraphs, Lines, Words, Characters// - Image Export, Font Coordinates, Statistics}
// Import the IronOcr library
using IronOcr;
using System.Drawing; // Ensure assembly reference is added
// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Chinese; // Set language to Chinese
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Use both Tesseract and LSTM
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading
// OCR processing
using (var Input = new OcrInput(@"images\sample.tiff"))
{
OcrResult Result = Ocr.Read(Input);
var Pages = Result.Pages;
var Words = Pages[0].Words;
var Barcodes = Result.Barcodes;
// Explore detailed API options here:
// - Pages, Blocks, Paragraphs, Lines, Words, Characters
// - Image Export, Font Coordinates, Statistics
}
' Import the IronOcr libraryImportsIronOcrImportsSystem.Drawing' Ensure assembly reference is added' Create an instance of IronTesseract for OCR processingDimOcrAs New IronTesseract()Ocr.Language = OcrLanguage.Chinese' Set language to ChineseOcr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm' Use both Tesseract and LSTMOcr.Configuration.ReadBarCodes = True ' Enable barcode reading' OCR processingUsingInputAs New OcrInput("images\sample.tiff") DimResultAsOcrResult = Ocr.Read(Input) DimPages = Result.Pages DimWords = Pages(0).Words DimBarcodes = Result.Barcodes ' Explore detailed API options here: ' - Pages, Blocks, Paragraphs, Lines, Words, Characters ' - Image Export, Font Coordinates, StatisticsEndUsing
' Import the IronOcr library
Imports IronOcr
Imports System.Drawing ' Ensure assembly reference is added
' Create an instance of IronTesseract for OCR processing
Dim Ocr As New IronTesseract()
Ocr.Language = OcrLanguage.Chinese ' Set language to Chinese
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm ' Use both Tesseract and LSTM
Ocr.Configuration.ReadBarCodes = True ' Enable barcode reading
' OCR processing
Using Input As New OcrInput("images\sample.tiff")
Dim Result As OcrResult = Ocr.Read(Input)
Dim Pages = Result.Pages
Dim Words = Pages(0).Words
Dim Barcodes = Result.Barcodes
' Explore detailed API options here:
' - Pages, Blocks, Paragraphs, Lines, Words, Characters
' - Image Export, Font Coordinates, Statistics
End Using