<meta http-equiv="content-language" content="vi" />
# OCR tiếng Việt trong C# và .NET
###### Các phiên bản khác của tài liệu này:
- [Tiếng Anh (This Page in English)](/csharp/ocr/languages/vietnamese/)
- [Thêm Languages](/csharp/ocr/languages/)
IronOCR là một thành phần phần mềm C# cho phép lập trình viên .NET đọc văn bản từ hình ảnh và tài liệu PDF bằng 126 ngôn ngữ, bao gồm cả tiếng Việt.
Nó là một nhánh nâng cao của Tesseract, được xây dựng dành riêng cho các nhà phát triển .NET và thường xuyên vượt trội hơn các công cụ Tesseract khác về cả tốc độ và độ chính xác.
## Nội dung của IronOcr.Languages.Vietnamese
Gói này chứa 132 ngôn ngữ OCR cho .NET:
- Tiếng Việt
- Tiếng Việt
- Tiếng Việt nhanh
- VietnameseAlphabet
- VietnameseAlphabetBest
- VietnameseAlphabetFast
## Tải xuống
Gói ngôn ngữ tiếng Việt [Tiếng Việt]
- Download as [Zip](/csharp/ocr/packages/language-packs/Vietnamese.ocrdata.zip)
- Install with [NuGet](https://www.nuget.org/packages/IronOcr.Languages.Vietnamese/)
## Cài đặt
Việc đầu tiên chúng ta phải làm là cài đặt gói OCR **tiếng Việt** của chúng tôi vào dự án .NET của bạn.
```shell
:InstallCmd Install-Package IronOcr.Languages.Vietnamese
```
## Ví dụ về mã
Ví dụ về mã C# này đọc văn bản tiếng Việt từ tài liệu Hình ảnh hoặc PDF.
```csharp
// PM> Install-Package IronOcr.Languages.Vietnamese
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from an image
using (var Input = new OcrInput(@"images\Vietnamese.png"))
{
// Read text from the input image
var Result = Ocr.Read(Input);
// Store the recognized text
string AllText = Result.Text;
// Output the recognized text
Console.WriteLine(AllText);
}
```
## Tại sao chọn IronOCR?
IronOCR là một thư viện phần mềm .NET dễ cài đặt, đầy đủ và đầy đủ tài liệu.
Chọn IronOCR để đạt **độ chính xác 99,8% + OCR** mà không cần sử dụng bất kỳ dịch vụ web bên ngoài nào, phí liên tục hoặc gửi tài liệu bí mật qua internet.
#### Tại sao các nhà phát triển C# chọn IronOCR thay vì Vanilla Tesseract:
- Cài đặt dưới dạng một DLL hoặc NuGet
- Bao gồm cho các động cơ Tesseract 5, 4 và 3 ra khỏi hộp.
- Độ chính xác **99,8%** vượt trội đáng kể so với Tesseract thông thường.
- Tốc độ cực nhanh và Đa luồng
- Tương thích MVC, WebApp, Desktop, Console & Server Application
- Không có Exes hoặc mã C++ để làm việc
- Hỗ trợ đầy đủ PDF OCR
- Để thực hiện OCR hầu hết mọi tệp Hình ảnh hoặc PDF
- Hỗ trợ đầy đủ .NET Core, Standard và FrameWork
- Triển khai trên Windows, Mac, Linux, Azure, Docker, Lambda, AWS
- Đọc mã vạch và mã QR
- Xuất OCR sang XHTML
- Xuất OCR sang các tài liệu PDF có thể tìm kiếm được
- Hỗ trợ đa luồng
- 126 ngôn ngữ quốc tế đều được quản lý thông qua tệp NuGet hoặc OcrData
- Trích xuất Hình ảnh, Tọa độ, Thống kê và Phông chữ. Không chỉ là văn bản.
- Có thể được sử dụng để phân phối lại Tesseract OCR bên trong các ứng dụng thương mại và độc quyền.
*IronOCR tỏa sáng khi làm việc với hình ảnh trong thế giới thực và các tài liệu không hoàn hảo như ảnh chụp hoặc bản quét có độ phân giải thấp có thể có nhiễu kỹ thuật số hoặc không hoàn hảo.*
Các thư viện [OCR miễn phí](/csharp/ocr/use-case/free-ocr-csharp/) khác cho nền tảng .NET chẳng hạn như các API .NET Tesseract khác và các dịch vụ web không hoạt động quá tốt trên các trường hợp sử dụng trong thế giới thực này.
## OCR với Tesseract 5 - Bắt đầu mã hóa bằng C#
Mẫu mã dưới đây cho thấy việc đọc văn bản từ hình ảnh bằng C# hoặc VB .NET dễ dàng như thế nào.
### Lót
```csharp
using IronOcr;
// Read text directly from an image file
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
// Output the recognized text
Console.WriteLine(Text);
```
### Hello World có thể cấu hình
```csharp
// PM> Install-Package IronOcr.Languages.Vietnamese
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for multiple images
using (var Input = new OcrInput())
{
// Add images to the OCR input
Input.AddImage("images/sample.jpeg");
//... you can add any number of images
// Read text from the input images
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
```
### C# PDF OCR
Cách tiếp cận tương tự cũng có thể được sử dụng để trích xuất văn bản từ bất kỳ tài liệu PDF nào.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a PDF file
using (var Input = new OcrInput())
{
// Add a password-protected PDF document and specify its password
Input.AddPdf("example.pdf", "password");
// We can also select specific PDF pages for OCR
// Read text from the input PDF
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
// Output the number of pages scanned
Console.WriteLine($"{Result.Pages.Count} Pages");
// 1 page for each page of the PDF
}
```
### OCR cho nhiều trang TIFF
OCR Đọc định dạng tệp TIFF bao gồm nhiều tài liệu trang. TIFF cũng có thể được chuyển đổi trực tiếp thành tệp PDF với văn bản có thể tìm kiếm được.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a multi-frame TIFF file
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
// Read text from the input TIFF
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
```
### Mã vạch và QR
Một tính năng độc đáo của IronOCR là nó có thể đọc mã vạch và mã QR từ các tài liệu trong khi nó đang quét văn bản. Các phiên bản của Lớp `OcrResult.OcrBarcode` cung cấp cho nhà phát triển thông tin chi tiết về từng mã vạch được quét.
```csharp
using IronOcr;
// Initialize the OCR engine and configure to read barcodes
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// Create an OCR input for an image file containing barcodes
using (var Input = new OcrInput())
{
Input.AddImage("img/Barcode.png");
// Read text and barcodes from the input image
var Result = Ocr.Read(Input);
// Iterate through scanned barcodes and output their values
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Thuộc tính loại và vị trí cũng được hiển thị
}
}
```
### OCR trên các khu vực cụ thể của hình ảnh
Tất cả các phương pháp quét và đọc của IronOCR đều cung cấp khả năng chỉ định chính xác phần nào của trang hoặc các trang mà chúng tôi muốn đọc văn bản từ đó. Điều này rất hữu ích khi chúng ta đang xem xét các biểu mẫu được tiêu chuẩn hóa và có thể tiết kiệm rất nhiều thời gian cũng như nâng cao hiệu quả.
Để sử dụng các vùng cắt, chúng ta sẽ cần thêm một tham chiếu hệ thống vào `System.Drawing` để chúng ta có thể sử dụng đối tượng `System.Drawing.Rectangle`.
```csharp
using IronOcr;
using System.Drawing;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input specifying a region in the image
using (var Input = new OcrInput())
{
// Define the content area within the image to read text
var ContentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions in px
// Add image with specified content area
Input.Add("document.png", ContentArea);
// Read text from the specified region of the image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
```
### OCR cho bản quét chất lượng thấp
Lớp IronOCR `OcrInput` có thể sửa lỗi quét mà Tesseract bình thường không đọc được.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from a low-quality image file
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
// Apply filters to improve the input image
Input.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew(); // sửa lỗi xoay và phối cảnh
// Read text from the improved image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
```
### Xuất kết quả OCR dưới dạng PDF có thể tìm kiếm
Hình ảnh sang PDF với các chuỗi văn bản có thể sao chép. Có thể được lập chỉ mục bởi các công cụ tìm kiếm và cơ sở dữ liệu.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input and add images
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
// Read text and save as a searchable PDF
var Result = Ocr.Read(Input);
// Save the output as a searchable PDF
Result.SaveAsSearchablePdf("searchable.pdf");
}
```
### TIFF sang chuyển đổi PDF có thể tìm kiếm
Chuyển đổi trực tiếp tài liệu TIFF (hoặc bất kỳ nhóm tệp hình ảnh nào) sang tệp PDF có thể tìm kiếm được, có thể được lập chỉ mục bởi mạng nội bộ, trang web và công cụ tìm kiếm google.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a multi-frame TIFF file
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
// Read text and save as a searchable PDF
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf");
}
```
### Xuất kết quả OCR dưới dạng HTML
Chuyển đổi hình ảnh OCR sang XHTML.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input and add images
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
// Read text and save as an HOCR file
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html");
}
```
## Bộ lọc tăng cường hình ảnh OCR
IronOCR cung cấp các bộ lọc độc đáo cho các đối tượng `OcrInput` để cải thiện hiệu suất OCR.
### Ví dụ về mã tăng cường hình ảnh
Làm cho hình ảnh đầu vào OCR có chất lượng cao hơn để tạo ra kết quả OCR tốt hơn, nhanh hơn.
```csharp
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from a low-quality image file
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
// Apply filters to improve the input image
Input.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew(); // sửa lỗi xoay và phối cảnh
// Read text from the improved image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
```
### Danh sách Bộ lọc Hình ảnh OCR
Các bộ lọc đầu vào để nâng cao hiệu suất OCR được tích hợp trong IronOCR bao gồm:
- **`OcrInput.Rotate(double)`** - Xoay hình ảnh theo một số độ theo chiều kim đồng hồ. Đối với ngược chiều kim đồng hồ, hãy sử dụng số âm.
- **`OcrInput.Binarize()`** - Biến mọi pixel thành màu đen hoặc trắng. Có thể cải thiện hiệu suất OCR trong trường hợp văn bản có độ tương phản rất thấp.
- **`OcrInput.ToGrayScale()`** - Biến mọi pixel thành thang độ xám. Thường cải thiện tốc độ OCR.
- **`OcrInput.Contrast()`** - Tăng độ tương phản. Thường cải thiện tốc độ OCR và độ chính xác.
- **`OcrInput.DeNoise()`** - Loại bỏ nhiễu kỹ thuật số. Chỉ nên sử dụng khi có tiếng ồn.
- **`OcrInput.Invert()`** - Đảo ngược màu sắc, ví dụ: trắng thành đen và ngược lại.
- **`OcrInput.Dilate()`** - Thêm pixel vào ranh giới của đối tượng trong một hình ảnh. Đối lập với xói mòn.
- **`OcrInput.Erode()`** - Xóa pixel tại ranh giới của đối tượng.
- **`OcrInput.Deskew()`** - Xoay hình ảnh để thẳng đứng. Rất hữu ích cho OCR.
- **`OcrInput.DeepCleanBackgroundNoise()`** - Loại bỏ nhiễu nền. Chỉ sử dụng trong trường hợp nhiễu nền quá lớn.
- **OcrInput.EnhanceResolution** - Tăng độ phân giải của hình ảnh chất lượng thấp. Không cần thiết nhiều do `OcrInput.MinimumDPI` và `OcrInput.TargetDPI` tự động chăm sóc.
**CleanBackgroundNoise**: Sửa lỗi kỹ thuật số nhiễu và các điểm không hoàn hảo.
**EnhanceContrast**: Tăng độ tương phản, giúp cải thiện hiệu suất và độ chính xác OCR.
**EnhanceResolution**: Phát hiện và nâng cấp hình ảnh có độ phân giải thấp (dưới 275 dpi).
**Language**: Hỗ trợ 22 gói ngôn ngữ quốc tế. Ngôn ngữ có thể được chọn để áp dụng cho hoạt động OCR.
**Strategy**: Hỗ trợ hai chiến lược quét tài liệu nhanh và một chiến lược nâng cao sử dụng trí tuệ nhân tạo cải thiện độ chính xác của văn bản OCR.
**ColorSpace**: Chọn OCR ở thang độ xám hoặc màu. Thang độ xám là tốt nhất, nhưng đầy đủ màu có lợi khi văn bản và nền có màu tương tự nhưng khác màu.
**DetectWhiteTextOnDarkBackgrounds**: Tự động phát hiện trang ngược và đọc chúng.
**InputImageType**: Xác định liệu thư viện đang xem tài liệu đầy đủ hay một đoạn trích, như ảnh chụp màn hình.
**RotateAndStraighten**: Đọc các tài liệu xoay hoặc có phối cảnh.
**ReadBarcodes**: Tự động đọc mã vạch và mã QR trên trang cùng với văn bản.
**Độ đậm của màu**: Định lượng bit trên mỗi pixel cho độ sâu màu. Độ sâu lớn hơn có thể tăng chất lượng OCR nhưng sẽ tăng thời gian xử lý.
## 126 Gói ngôn ngữ
IronOCR hỗ trợ **126 ngôn ngữ quốc tế** thông qua các gói ngôn ngữ được phân phối dưới dạng DLL, có thể [tải xuống từ trang web này](/csharp/ocr/languages/) hoặc từ [NuGet Package Manager](https://www.nuget.org/packages?q=IronOcr.Languages/).
Các ngôn ngữ bao gồm tiếng Đức, tiếng Pháp, tiếng Anh, tiếng Trung, tiếng Nhật và nhiều ngôn ngữ khác. Các gói ngôn ngữ chuyên biệt cho hộ chiếu MRZ, séc MICR, dữ liệu tài chính, biển số xe, và hơn thế nữa. Bạn cũng có thể sử dụng bất kỳ tệp ".traineddata" Tesseract nào - bao gồm cả những tệp bạn tự tạo.
### Ví dụ về ngôn ngữ
Sử dụng các ngôn ngữ OCR khác.
```csharp
// using IronOcr;
// PM> Install IronOcr.Languages.Arabic
// Initialize the OCR engine for Arabic language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic;
// Create an OCR input for an image file
using (var Input = new OcrInput())
{
Input.AddImage("img/arabic.gif");
// Add image filters if necessary
// Even if the input quality is low
// IronTesseract can read what standard Tesseract might not.
// Read text from the input image
var Result = Ocr.Read(Input);
// Console cannot print Arabic easily on Windows.
// Instead, save to disk.
Result.SaveAsTextFile("arabic.txt");
}
```
### Ví dụ về nhiều ngôn ngữ
Cũng có thể OCR bằng nhiều ngôn ngữ cùng một lúc. Điều này có thể giúp lấy siêu dữ liệu và URL tiếng Anh từ các tài liệu Unicode.
```csharp
// using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
// Initialize the OCR engine for multiple languages
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Vietnamese);
// Add any number of languages
// Create an OCR input for a multi-language PDF
using (var Input = new OcrInput())
{
Input.Add("multi-language.pdf");
// Read text from the input PDF
var Result = Ocr.Read(Input);
// Save the output to a text file
Result.SaveAsTextFile("results.txt");
}
```
## Đối tượng kết quả OCR chi tiết
IronOCR trả về một đối tượng kết quả OCR cho mỗi hoạt động OCR. Nói chung, các nhà phát triển chỉ sử dụng thuộc tính văn bản của đối tượng này để quét văn bản từ hình ảnh. Tuy nhiên, kết quả OCR DOM cao cấp hơn nhiều so với kết quả cơ bản.
```csharp
using IronOcr;
using System.Drawing; // Thêm tham chiếu hội
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;
Ocr.Configuration.ReadBarCodes = true; //!Quan trọng
// Create an OCR input from a TIFF file
using (var Input = new OcrInput(@"images\sample.tiff"))
{
// Read text, barcodes, and other data from the input image
OcrResult Result = Ocr.Read(Input);
// Explore the detailed API:
var Pages = Result.Pages;
var Words = Pages[0].Words;
var Barcodes = Result.Barcodes;
// - Trang, Khối, Paraphaphs, Dòng, Từ, Ký tự
// - Xuất hình ảnh, tọa độ phông chữ, dữ liệu thống kê
}
```
## Hiệu suất
IronOCR hoạt động hiệu quả mà không cần điều chỉnh hiệu suất hoặc sửa đổi nhiều hình ảnh đầu vào.
Tốc độ cực nhanh: IronOCR.2020+ nhanh hơn tới 10 lần và ít lỗi hơn 250% so với các bản dựng trước.
## Tìm hiểu thêm
Để tìm hiểu thêm về OCR trong C#, VB, F# hoặc bất kỳ ngôn ngữ .NET nào khác, vui lòng [đọc hướng dẫn cộng đồng của chúng tôi](/csharp/ocr/tutorials/how-to-read-text-from-an-image-in-csharp-net/), những [hướng dẫn](/csharp/ocr/tutorials/how-to-read-text-from-an-image-in-csharp-net/) này cung cấp các ví dụ thực tế về cách IronOCR có thể được sử dụng và có thể cho thấy các sắc thái về cách tận dụng tối đa thư viện này.
[Tham chiếu đối tượng](/csharp/ocr/object-reference/api/) đầy đủ [cho các nhà phát triển .NET](/csharp/ocr/object-reference/api/) cũng có sẵn.
IronOCR là một thành phần phần mềm C# cho phép lập trình viên .NET đọc văn bản từ hình ảnh và tài liệu PDF bằng 126 ngôn ngữ, bao gồm cả tiếng Việt.
Nó là một nhánh nâng cao của Tesseract, được xây dựng dành riêng cho các nhà phát triển .NET và thường xuyên vượt trội hơn các công cụ Tesseract khác về cả tốc độ và độ chính xác.
Việc đầu tiên chúng ta phải làm là cài đặt gói OCR tiếng Việt của chúng tôi vào dự án .NET của bạn.
PM > Install-Package IronOcr.Languages.Vietnamese
Install-Package IronOcr.Languages.Vietnamese
Ví dụ về mã
Ví dụ về mã C# này đọc văn bản tiếng Việt từ tài liệu Hình ảnh hoặc PDF.
// PM> Install-Package IronOcr.Languages.Vietnameseusing IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input from an imageusing (varInput = new OcrInput(@"images\Vietnamese.png")){ // Read text from the input image varResult = Ocr.Read(Input); // Store the recognized text stringAllText = Result.Text; // Output the recognized textConsole.WriteLine(AllText);}
// PM> Install-Package IronOcr.Languages.Vietnamese
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from an image
using (var Input = new OcrInput(@"images\Vietnamese.png"))
{
// Read text from the input image
var Result = Ocr.Read(Input);
// Store the recognized text
string AllText = Result.Text;
// Output the recognized text
Console.WriteLine(AllText);
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languageDimOcrAs New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input from an imageUsingInputAs New OcrInput("images\Vietnamese.png") ' Read text from the input image DimResult = Ocr.Read(Input) ' Store the recognized text DimAllTextAsString = Result.Text ' Output the recognized textConsole.WriteLine(AllText)EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Dim Ocr As New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input from an image
Using Input As New OcrInput("images\Vietnamese.png")
' Read text from the input image
Dim Result = Ocr.Read(Input)
' Store the recognized text
Dim AllText As String = Result.Text
' Output the recognized text
Console.WriteLine(AllText)
End Using
Tại sao chọn IronOCR?
IronOCR là một thư viện phần mềm .NET dễ cài đặt, đầy đủ và đầy đủ tài liệu.
Chọn IronOCR để đạt độ chính xác 99,8% + OCR mà không cần sử dụng bất kỳ dịch vụ web bên ngoài nào, phí liên tục hoặc gửi tài liệu bí mật qua internet.
Tại sao các nhà phát triển C# chọn IronOCR thay vì Vanilla Tesseract:
Cài đặt dưới dạng một DLL hoặc NuGet
Bao gồm cho các động cơ Tesseract 5, 4 và 3 ra khỏi hộp.
Độ chính xác 99,8% vượt trội đáng kể so với Tesseract thông thường.
Tốc độ cực nhanh và Đa luồng
Tương thích MVC, WebApp, Desktop, Console & Server Application
Không có Exes hoặc mã C++ để làm việc
Hỗ trợ đầy đủ PDF OCR
Để thực hiện OCR hầu hết mọi tệp Hình ảnh hoặc PDF
Hỗ trợ đầy đủ .NET Core, Standard và FrameWork
Triển khai trên Windows, Mac, Linux, Azure, Docker, Lambda, AWS
Đọc mã vạch và mã QR
Xuất OCR sang XHTML
Xuất OCR sang các tài liệu PDF có thể tìm kiếm được
Hỗ trợ đa luồng
126 ngôn ngữ quốc tế đều được quản lý thông qua tệp NuGet hoặc OcrData
Trích xuất Hình ảnh, Tọa độ, Thống kê và Phông chữ. Không chỉ là văn bản.
Có thể được sử dụng để phân phối lại Tesseract OCR bên trong các ứng dụng thương mại và độc quyền.
IronOCR tỏa sáng khi làm việc với hình ảnh trong thế giới thực và các tài liệu không hoàn hảo như ảnh chụp hoặc bản quét có độ phân giải thấp có thể có nhiễu kỹ thuật số hoặc không hoàn hảo.
Các thư viện OCR miễn phí khác cho nền tảng .NET chẳng hạn như các API .NET Tesseract khác và các dịch vụ web không hoạt động quá tốt trên các trường hợp sử dụng trong thế giới thực này.
OCR với Tesseract 5 - Bắt đầu mã hóa bằng C#
Mẫu mã dưới đây cho thấy việc đọc văn bản từ hình ảnh bằng C# hoặc VB .NET dễ dàng như thế nào.
Lót
using IronOcr;// Read text directly from an image filestringText = new IronTesseract().Read(@"img\Screenshot.png").Text;// Output the recognized textConsole.WriteLine(Text);
using IronOcr;
// Read text directly from an image file
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
// Output the recognized text
Console.WriteLine(Text);
ImportsIronOcr' Read text directly from an image filePrivateTextAsString = (New IronTesseract()).Read("img\Screenshot.png").Text' Output the recognized textConsole.WriteLine(Text)
Imports IronOcr
' Read text directly from an image file
Private Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
' Output the recognized text
Console.WriteLine(Text)
Hello World có thể cấu hình
// PM> Install-Package IronOcr.Languages.Vietnameseusing IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input for multiple imagesusing (varInput = new OcrInput()){ // Add images to the OCR inputInput.AddImage("images/sample.jpeg"); //... you can add any number of images // Read text from the input images varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text);}
// PM> Install-Package IronOcr.Languages.Vietnamese
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for multiple images
using (var Input = new OcrInput())
{
// Add images to the OCR input
Input.AddImage("images/sample.jpeg");
//... you can add any number of images
// Read text from the input images
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languageDimOcrAs New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input for multiple imagesUsingInputAs New OcrInput() ' Add images to the OCR inputInput.AddImage("images/sample.jpeg") '... you can add any number of images ' Read text from the input images DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text)EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Dim Ocr As New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input for multiple images
Using Input As New OcrInput()
' Add images to the OCR input
Input.AddImage("images/sample.jpeg")
'... you can add any number of images
' Read text from the input images
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
End Using
C# PDF OCR
Cách tiếp cận tương tự cũng có thể được sử dụng để trích xuất văn bản từ bất kỳ tài liệu PDF nào.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input for a PDF fileusing (varInput = new OcrInput()){ // Add a password-protected PDF document and specify its passwordInput.AddPdf("example.pdf", "password"); // We can also select specific PDF pages for OCR // Read text from the input PDF varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text); // Output the number of pages scannedConsole.WriteLine($"{Result.Pages.Count} Pages"); // 1 page for each page of the PDF}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a PDF file
using (var Input = new OcrInput())
{
// Add a password-protected PDF document and specify its password
Input.AddPdf("example.pdf", "password");
// We can also select specific PDF pages for OCR
// Read text from the input PDF
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
// Output the number of pages scanned
Console.WriteLine($"{Result.Pages.Count} Pages");
// 1 page for each page of the PDF
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input for a PDF fileUsingInput = New OcrInput() ' Add a password-protected PDF document and specify its passwordInput.AddPdf("example.pdf", "password") ' We can also select specific PDF pages for OCR ' Read text from the input PDF DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text) ' Output the number of pages scannedConsole.WriteLine($"{Result.Pages.Count} Pages") ' 1 page for each page of the PDFEndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input for a PDF file
Using Input = New OcrInput()
' Add a password-protected PDF document and specify its password
Input.AddPdf("example.pdf", "password")
' We can also select specific PDF pages for OCR
' Read text from the input PDF
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
' Output the number of pages scanned
Console.WriteLine($"{Result.Pages.Count} Pages")
' 1 page for each page of the PDF
End Using
OCR cho nhiều trang TIFF
OCR Đọc định dạng tệp TIFF bao gồm nhiều tài liệu trang. TIFF cũng có thể được chuyển đổi trực tiếp thành tệp PDF với văn bản có thể tìm kiếm được.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input for a multi-frame TIFF fileusing (varInput = new OcrInput()){Input.AddMultiFrameTiff("multi-frame.tiff"); // Read text from the input TIFF varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text);}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a multi-frame TIFF file
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("multi-frame.tiff");
// Read text from the input TIFF
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input for a multi-frame TIFF fileUsingInput = New OcrInput()Input.AddMultiFrameTiff("multi-frame.tiff") ' Read text from the input TIFF DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text)EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input for a multi-frame TIFF file
Using Input = New OcrInput()
Input.AddMultiFrameTiff("multi-frame.tiff")
' Read text from the input TIFF
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
End Using
Mã vạch và QR
Một tính năng độc đáo của IronOCR là nó có thể đọc mã vạch và mã QR từ các tài liệu trong khi nó đang quét văn bản. Các phiên bản của Lớp OcrResult.OcrBarcode cung cấp cho nhà phát triển thông tin chi tiết về từng mã vạch được quét.
using IronOcr;// Initialize the OCR engine and configure to read barcodesvarOcr = new IronTesseract();Ocr.Configuration.ReadBarCodes = true;// Create an OCR input for an image file containing barcodesusing (varInput = new OcrInput()){Input.AddImage("img/Barcode.png"); // Read text and barcodes from the input image varResult = Ocr.Read(Input); // Iterate through scanned barcodes and output their values foreach (varBarcodeinResult.Barcodes) {Console.WriteLine(Barcode.Value); // Thuộc tính loại và vị trí cũng được hiển thị }}
using IronOcr;
// Initialize the OCR engine and configure to read barcodes
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;
// Create an OCR input for an image file containing barcodes
using (var Input = new OcrInput())
{
Input.AddImage("img/Barcode.png");
// Read text and barcodes from the input image
var Result = Ocr.Read(Input);
// Iterate through scanned barcodes and output their values
foreach (var Barcode in Result.Barcodes)
{
Console.WriteLine(Barcode.Value);
// Thuộc tính loại và vị trí cũng được hiển thị
}
}
ImportsIronOcr' Initialize the OCR engine and configure to read barcodesPrivateOcr = New IronTesseract()Ocr.Configuration.ReadBarCodes = True' Create an OCR input for an image file containing barcodesUsingInput = New OcrInput()Input.AddImage("img/Barcode.png") ' Read text and barcodes from the input image DimResult = Ocr.Read(Input) ' Iterate through scanned barcodes and output their values For EachBarcodeInResult.BarcodesConsole.WriteLine(Barcode.Value) ' Thuộc tính loại và vị trí cũng được hiển thị NextBarcodeEndUsing
Imports IronOcr
' Initialize the OCR engine and configure to read barcodes
Private Ocr = New IronTesseract()
Ocr.Configuration.ReadBarCodes = True
' Create an OCR input for an image file containing barcodes
Using Input = New OcrInput()
Input.AddImage("img/Barcode.png")
' Read text and barcodes from the input image
Dim Result = Ocr.Read(Input)
' Iterate through scanned barcodes and output their values
For Each Barcode In Result.Barcodes
Console.WriteLine(Barcode.Value)
' Thuộc tính loại và vị trí cũng được hiển thị
Next Barcode
End Using
OCR trên các khu vực cụ thể của hình ảnh
Tất cả các phương pháp quét và đọc của IronOCR đều cung cấp khả năng chỉ định chính xác phần nào của trang hoặc các trang mà chúng tôi muốn đọc văn bản từ đó. Điều này rất hữu ích khi chúng ta đang xem xét các biểu mẫu được tiêu chuẩn hóa và có thể tiết kiệm rất nhiều thời gian cũng như nâng cao hiệu quả.
Để sử dụng các vùng cắt, chúng ta sẽ cần thêm một tham chiếu hệ thống vào System.Drawing để chúng ta có thể sử dụng đối tượng System.Drawing.Rectangle.
using IronOcr;using System.Drawing;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input specifying a region in the imageusing (varInput = new OcrInput()){ // Define the content area within the image to read text varContentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 }; // Dimensions in px // Add image with specified content areaInput.Add("document.png", ContentArea); // Read text from the specified region of the image varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text);}
using IronOcr;
using System.Drawing;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input specifying a region in the image
using (var Input = new OcrInput())
{
// Define the content area within the image to read text
var ContentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
// Dimensions in px
// Add image with specified content area
Input.Add("document.png", ContentArea);
// Read text from the specified region of the image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
ImportsIronOcrImportsSystem.Drawing' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input specifying a region in the imageUsingInput = New OcrInput() ' Define the content area within the image to read text DimContentArea = New Rectangle() With { .X = 215, .Y = 1250, .Height = 280, .Width = 1335 } ' Dimensions in px ' Add image with specified content areaInput.Add("document.png", ContentArea) ' Read text from the specified region of the image DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text)EndUsing
Imports IronOcr
Imports System.Drawing
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input specifying a region in the image
Using Input = New OcrInput()
' Define the content area within the image to read text
Dim ContentArea = New Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
' Dimensions in px
' Add image with specified content area
Input.Add("document.png", ContentArea)
' Read text from the specified region of the image
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
End Using
OCR cho bản quét chất lượng thấp
Lớp IronOCR OcrInput có thể sửa lỗi quét mà Tesseract bình thường không đọc được.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input from a low-quality image fileusing (varInput = new OcrInput(@"img\Potter.LowQuality.tiff")){ // Apply filters to improve the input imageInput.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kémInput.Deskew(); // sửa lỗi xoay và phối cảnh // Read text from the improved image varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text);}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from a low-quality image file
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
// Apply filters to improve the input image
Input.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew(); // sửa lỗi xoay và phối cảnh
// Read text from the improved image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input from a low-quality image fileUsingInput = New OcrInput("img\Potter.LowQuality.tiff") ' Apply filters to improve the input imageInput.DeNoise() ' sửa lỗi kỹ thuật số nhiễu và quét kémInput.Deskew() ' sửa lỗi xoay và phối cảnh ' Read text from the improved image DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text)EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input from a low-quality image file
Using Input = New OcrInput("img\Potter.LowQuality.tiff")
' Apply filters to improve the input image
Input.DeNoise() ' sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew() ' sửa lỗi xoay và phối cảnh
' Read text from the improved image
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
End Using
Xuất kết quả OCR dưới dạng PDF có thể tìm kiếm
Hình ảnh sang PDF với các chuỗi văn bản có thể sao chép. Có thể được lập chỉ mục bởi các công cụ tìm kiếm và cơ sở dữ liệu.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input and add imagesusing (varInput = new OcrInput()){Input.Title = "Quarterly Report";Input.AddImage("image1.jpeg");Input.AddImage("image2.png");Input.AddImage("image3.gif"); // Read text and save as a searchable PDF varResult = Ocr.Read(Input); // Save the output as a searchable PDFResult.SaveAsSearchablePdf("searchable.pdf");}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input and add images
using (var Input = new OcrInput())
{
Input.Title = "Quarterly Report";
Input.AddImage("image1.jpeg");
Input.AddImage("image2.png");
Input.AddImage("image3.gif");
// Read text and save as a searchable PDF
var Result = Ocr.Read(Input);
// Save the output as a searchable PDF
Result.SaveAsSearchablePdf("searchable.pdf");
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input and add imagesUsingInput = New OcrInput()Input.Title = "Quarterly Report"Input.AddImage("image1.jpeg")Input.AddImage("image2.png")Input.AddImage("image3.gif") ' Read text and save as a searchable PDF DimResult = Ocr.Read(Input) ' Save the output as a searchable PDFResult.SaveAsSearchablePdf("searchable.pdf")EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input and add images
Using Input = New OcrInput()
Input.Title = "Quarterly Report"
Input.AddImage("image1.jpeg")
Input.AddImage("image2.png")
Input.AddImage("image3.gif")
' Read text and save as a searchable PDF
Dim Result = Ocr.Read(Input)
' Save the output as a searchable PDF
Result.SaveAsSearchablePdf("searchable.pdf")
End Using
TIFF sang chuyển đổi PDF có thể tìm kiếm
Chuyển đổi trực tiếp tài liệu TIFF (hoặc bất kỳ nhóm tệp hình ảnh nào) sang tệp PDF có thể tìm kiếm được, có thể được lập chỉ mục bởi mạng nội bộ, trang web và công cụ tìm kiếm google.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input for a multi-frame TIFF fileusing (varInput = new OcrInput()){Input.AddMultiFrameTiff("example.tiff"); // Read text and save as a searchable PDF varResult = Ocr.Read(Input);Result.SaveAsSearchablePdf("searchable.pdf");}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input for a multi-frame TIFF file
using (var Input = new OcrInput())
{
Input.AddMultiFrameTiff("example.tiff");
// Read text and save as a searchable PDF
var Result = Ocr.Read(Input);
Result.SaveAsSearchablePdf("searchable.pdf");
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input for a multi-frame TIFF fileUsingInput = New OcrInput()Input.AddMultiFrameTiff("example.tiff") ' Read text and save as a searchable PDF DimResult = Ocr.Read(Input)Result.SaveAsSearchablePdf("searchable.pdf")EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input for a multi-frame TIFF file
Using Input = New OcrInput()
Input.AddMultiFrameTiff("example.tiff")
' Read text and save as a searchable PDF
Dim Result = Ocr.Read(Input)
Result.SaveAsSearchablePdf("searchable.pdf")
End Using
Xuất kết quả OCR dưới dạng HTML
Chuyển đổi hình ảnh OCR sang XHTML.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input and add imagesusing (varInput = new OcrInput()){Input.Title = "Html Title";Input.AddImage("image1.jpeg"); // Read text and save as an HOCR file varResult = Ocr.Read(Input);Result.SaveAsHocrFile("results.html");}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input and add images
using (var Input = new OcrInput())
{
Input.Title = "Html Title";
Input.AddImage("image1.jpeg");
// Read text and save as an HOCR file
var Result = Ocr.Read(Input);
Result.SaveAsHocrFile("results.html");
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input and add imagesUsingInput = New OcrInput()Input.Title = "Html Title"Input.AddImage("image1.jpeg") ' Read text and save as an HOCR file DimResult = Ocr.Read(Input)Result.SaveAsHocrFile("results.html")EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input and add images
Using Input = New OcrInput()
Input.Title = "Html Title"
Input.AddImage("image1.jpeg")
' Read text and save as an HOCR file
Dim Result = Ocr.Read(Input)
Result.SaveAsHocrFile("results.html")
End Using
Bộ lọc tăng cường hình ảnh OCR
IronOCR cung cấp các bộ lọc độc đáo cho các đối tượng OcrInput để cải thiện hiệu suất OCR.
Ví dụ về mã tăng cường hình ảnh
Làm cho hình ảnh đầu vào OCR có chất lượng cao hơn để tạo ra kết quả OCR tốt hơn, nhanh hơn.
using IronOcr;// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;// Create an OCR input from a low-quality image fileusing (varInput = new OcrInput(@"LowQuality.jpeg")){ // Apply filters to improve the input imageInput.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kémInput.Deskew(); // sửa lỗi xoay và phối cảnh // Read text from the improved image varResult = Ocr.Read(Input); // Output the recognized textConsole.WriteLine(Result.Text);}
using IronOcr;
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
// Create an OCR input from a low-quality image file
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
// Apply filters to improve the input image
Input.DeNoise(); // sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew(); // sửa lỗi xoay và phối cảnh
// Read text from the improved image
var Result = Ocr.Read(Input);
// Output the recognized text
Console.WriteLine(Result.Text);
}
ImportsIronOcr' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.Vietnamese' Create an OCR input from a low-quality image fileUsingInput = New OcrInput("LowQuality.jpeg") ' Apply filters to improve the input imageInput.DeNoise() ' sửa lỗi kỹ thuật số nhiễu và quét kémInput.Deskew() ' sửa lỗi xoay và phối cảnh ' Read text from the improved image DimResult = Ocr.Read(Input) ' Output the recognized textConsole.WriteLine(Result.Text)EndUsing
Imports IronOcr
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
' Create an OCR input from a low-quality image file
Using Input = New OcrInput("LowQuality.jpeg")
' Apply filters to improve the input image
Input.DeNoise() ' sửa lỗi kỹ thuật số nhiễu và quét kém
Input.Deskew() ' sửa lỗi xoay và phối cảnh
' Read text from the improved image
Dim Result = Ocr.Read(Input)
' Output the recognized text
Console.WriteLine(Result.Text)
End Using
Danh sách Bộ lọc Hình ảnh OCR
Các bộ lọc đầu vào để nâng cao hiệu suất OCR được tích hợp trong IronOCR bao gồm:
OcrInput.Rotate(double) - Xoay hình ảnh theo một số độ theo chiều kim đồng hồ. Đối với ngược chiều kim đồng hồ, hãy sử dụng số âm.
OcrInput.Binarize() - Biến mọi pixel thành màu đen hoặc trắng. Có thể cải thiện hiệu suất OCR trong trường hợp văn bản có độ tương phản rất thấp.
OcrInput.ToGrayScale() - Biến mọi pixel thành thang độ xám. Thường cải thiện tốc độ OCR.
OcrInput.Contrast() - Tăng độ tương phản. Thường cải thiện tốc độ OCR và độ chính xác.
OcrInput.DeNoise() - Loại bỏ nhiễu kỹ thuật số. Chỉ nên sử dụng khi có tiếng ồn.
OcrInput.Invert() - Đảo ngược màu sắc, ví dụ: trắng thành đen và ngược lại.
OcrInput.Dilate() - Thêm pixel vào ranh giới của đối tượng trong một hình ảnh. Đối lập với xói mòn.
OcrInput.Erode() - Xóa pixel tại ranh giới của đối tượng.
OcrInput.Deskew() - Xoay hình ảnh để thẳng đứng. Rất hữu ích cho OCR.
OcrInput.DeepCleanBackgroundNoise() - Loại bỏ nhiễu nền. Chỉ sử dụng trong trường hợp nhiễu nền quá lớn.
OcrInput.EnhanceResolution - Tăng độ phân giải của hình ảnh chất lượng thấp. Không cần thiết nhiều do OcrInput.MinimumDPI và OcrInput.TargetDPI tự động chăm sóc.
CleanBackgroundNoise: Sửa lỗi kỹ thuật số nhiễu và các điểm không hoàn hảo.
EnhanceContrast: Tăng độ tương phản, giúp cải thiện hiệu suất và độ chính xác OCR.
EnhanceResolution: Phát hiện và nâng cấp hình ảnh có độ phân giải thấp (dưới 275 dpi).
Language: Hỗ trợ 22 gói ngôn ngữ quốc tế. Ngôn ngữ có thể được chọn để áp dụng cho hoạt động OCR.
Strategy: Hỗ trợ hai chiến lược quét tài liệu nhanh và một chiến lược nâng cao sử dụng trí tuệ nhân tạo cải thiện độ chính xác của văn bản OCR.
ColorSpace: Chọn OCR ở thang độ xám hoặc màu. Thang độ xám là tốt nhất, nhưng đầy đủ màu có lợi khi văn bản và nền có màu tương tự nhưng khác màu.
DetectWhiteTextOnDarkBackgrounds: Tự động phát hiện trang ngược và đọc chúng.
InputImageType: Xác định liệu thư viện đang xem tài liệu đầy đủ hay một đoạn trích, như ảnh chụp màn hình.
RotateAndStraighten: Đọc các tài liệu xoay hoặc có phối cảnh.
ReadBarcodes: Tự động đọc mã vạch và mã QR trên trang cùng với văn bản.
Độ đậm của màu: Định lượng bit trên mỗi pixel cho độ sâu màu. Độ sâu lớn hơn có thể tăng chất lượng OCR nhưng sẽ tăng thời gian xử lý.
Các ngôn ngữ bao gồm tiếng Đức, tiếng Pháp, tiếng Anh, tiếng Trung, tiếng Nhật và nhiều ngôn ngữ khác. Các gói ngôn ngữ chuyên biệt cho hộ chiếu MRZ, séc MICR, dữ liệu tài chính, biển số xe, và hơn thế nữa. Bạn cũng có thể sử dụng bất kỳ tệp ".traineddata" Tesseract nào - bao gồm cả những tệp bạn tự tạo.
Ví dụ về ngôn ngữ
Sử dụng các ngôn ngữ OCR khác.
// using IronOcr;// PM> Install IronOcr.Languages.Arabic// Initialize the OCR engine for Arabic languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Arabic;// Create an OCR input for an image fileusing (varInput = new OcrInput()){Input.AddImage("img/arabic.gif"); // Add image filters if necessary // Even if the input quality is low // IronTesseract can read what standard Tesseract might not. // Read text from the input image varResult = Ocr.Read(Input); // Console cannot print Arabic easily on Windows. // Instead, save to disk.Result.SaveAsTextFile("arabic.txt");}
// using IronOcr;
// PM> Install IronOcr.Languages.Arabic
// Initialize the OCR engine for Arabic language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic;
// Create an OCR input for an image file
using (var Input = new OcrInput())
{
Input.AddImage("img/arabic.gif");
// Add image filters if necessary
// Even if the input quality is low
// IronTesseract can read what standard Tesseract might not.
// Read text from the input image
var Result = Ocr.Read(Input);
// Console cannot print Arabic easily on Windows.
// Instead, save to disk.
Result.SaveAsTextFile("arabic.txt");
}
' using IronOcr;' PM> Install IronOcr.Languages.Arabic' Initialize the OCR engine for Arabic languageDimOcr = New IronTesseract()Ocr.Language = OcrLanguage.Arabic' Create an OCR input for an image fileUsingInput = New OcrInput()Input.AddImage("img/arabic.gif") ' Add image filters if necessary ' Even if the input quality is low ' IronTesseract can read what standard Tesseract might not. ' Read text from the input image DimResult = Ocr.Read(Input) ' Console cannot print Arabic easily on Windows. ' Instead, save to disk.Result.SaveAsTextFile("arabic.txt")EndUsing
' using IronOcr;
' PM> Install IronOcr.Languages.Arabic
' Initialize the OCR engine for Arabic language
Dim Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Arabic
' Create an OCR input for an image file
Using Input = New OcrInput()
Input.AddImage("img/arabic.gif")
' Add image filters if necessary
' Even if the input quality is low
' IronTesseract can read what standard Tesseract might not.
' Read text from the input image
Dim Result = Ocr.Read(Input)
' Console cannot print Arabic easily on Windows.
' Instead, save to disk.
Result.SaveAsTextFile("arabic.txt")
End Using
Ví dụ về nhiều ngôn ngữ
Cũng có thể OCR bằng nhiều ngôn ngữ cùng một lúc. Điều này có thể giúp lấy siêu dữ liệu và URL tiếng Anh từ các tài liệu Unicode.
// using IronOcr;// PM> Install IronOcr.Languages.ChineseSimplified// Initialize the OCR engine for multiple languagesvarOcr = new IronTesseract();Ocr.Language = OcrLanguage.ChineseSimplified;Ocr.AddSecondaryLanguage(OcrLanguage.Vietnamese);// Add any number of languages// Create an OCR input for a multi-language PDFusing (varInput = new OcrInput()){Input.Add("multi-language.pdf"); // Read text from the input PDF varResult = Ocr.Read(Input); // Save the output to a text fileResult.SaveAsTextFile("results.txt");}
// using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
// Initialize the OCR engine for multiple languages
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Vietnamese);
// Add any number of languages
// Create an OCR input for a multi-language PDF
using (var Input = new OcrInput())
{
Input.Add("multi-language.pdf");
// Read text from the input PDF
var Result = Ocr.Read(Input);
// Save the output to a text file
Result.SaveAsTextFile("results.txt");
}
' using IronOcr;' PM> Install IronOcr.Languages.ChineseSimplified' Initialize the OCR engine for multiple languagesDimOcr = New IronTesseract()Ocr.Language = OcrLanguage.ChineseSimplifiedOcr.AddSecondaryLanguage(OcrLanguage.Vietnamese)' Add any number of languages' Create an OCR input for a multi-language PDFUsingInput = New OcrInput()Input.Add("multi-language.pdf") ' Read text from the input PDF DimResult = Ocr.Read(Input) ' Save the output to a text fileResult.SaveAsTextFile("results.txt")EndUsing
' using IronOcr;
' PM> Install IronOcr.Languages.ChineseSimplified
' Initialize the OCR engine for multiple languages
Dim Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.ChineseSimplified
Ocr.AddSecondaryLanguage(OcrLanguage.Vietnamese)
' Add any number of languages
' Create an OCR input for a multi-language PDF
Using Input = New OcrInput()
Input.Add("multi-language.pdf")
' Read text from the input PDF
Dim Result = Ocr.Read(Input)
' Save the output to a text file
Result.SaveAsTextFile("results.txt")
End Using
Đối tượng kết quả OCR chi tiết
IronOCR trả về một đối tượng kết quả OCR cho mỗi hoạt động OCR. Nói chung, các nhà phát triển chỉ sử dụng thuộc tính văn bản của đối tượng này để quét văn bản từ hình ảnh. Tuy nhiên, kết quả OCR DOM cao cấp hơn nhiều so với kết quả cơ bản.
using IronOcr;using System.Drawing; // Thêm tham chiếu hội// Initialize the OCR engine for Vietnamese languagevarOcr = new IronTesseract();Ocr.Language = OcrLanguage.Vietnamese;Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;Ocr.Configuration.ReadBarCodes = true; //!Quan trọng// Create an OCR input from a TIFF fileusing (varInput = new OcrInput(@"images\sample.tiff")){ // Read text, barcodes, and other data from the input image OcrResultResult = Ocr.Read(Input); // Explore the detailed API: varPages = Result.Pages; varWords = Pages[0].Words; varBarcodes = Result.Barcodes; // - Trang, Khối, Paraphaphs, Dòng, Từ, Ký tự // - Xuất hình ảnh, tọa độ phông chữ, dữ liệu thống kê}
using IronOcr;
using System.Drawing; // Thêm tham chiếu hội
// Initialize the OCR engine for Vietnamese language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Vietnamese;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;
Ocr.Configuration.ReadBarCodes = true; //!Quan trọng
// Create an OCR input from a TIFF file
using (var Input = new OcrInput(@"images\sample.tiff"))
{
// Read text, barcodes, and other data from the input image
OcrResult Result = Ocr.Read(Input);
// Explore the detailed API:
var Pages = Result.Pages;
var Words = Pages[0].Words;
var Barcodes = Result.Barcodes;
// - Trang, Khối, Paraphaphs, Dòng, Từ, Ký tự
// - Xuất hình ảnh, tọa độ phông chữ, dữ liệu thống kê
}
ImportsIronOcrImportsSystem.Drawing' Thêm tham chiếu hội' Initialize the OCR engine for Vietnamese languagePrivateOcr = New IronTesseract()Ocr.Language = OcrLanguage.VietnameseOcr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstmOcr.Configuration.ReadBarCodes = True '!Quan trọng' Create an OCR input from a TIFF fileUsingInput = New OcrInput("images\sample.tiff") ' Read text, barcodes, and other data from the input image DimResultAsOcrResult = Ocr.Read(Input) ' Explore the detailed API: DimPages = Result.Pages DimWords = Pages(0).Words DimBarcodes = Result.Barcodes ' - Trang, Khối, Paraphaphs, Dòng, Từ, Ký tự ' - Xuất hình ảnh, tọa độ phông chữ, dữ liệu thống kêEndUsing
Imports IronOcr
Imports System.Drawing ' Thêm tham chiếu hội
' Initialize the OCR engine for Vietnamese language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Vietnamese
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm
Ocr.Configuration.ReadBarCodes = True '!Quan trọng
' Create an OCR input from a TIFF file
Using Input = New OcrInput("images\sample.tiff")
' Read text, barcodes, and other data from the input image
Dim Result As OcrResult = Ocr.Read(Input)
' Explore the detailed API:
Dim Pages = Result.Pages
Dim Words = Pages(0).Words
Dim Barcodes = Result.Barcodes
' - Trang, Khối, Paraphaphs, Dòng, Từ, Ký tự
' - Xuất hình ảnh, tọa độ phông chữ, dữ liệu thống kê
End Using
Hiệu suất
IronOCR hoạt động hiệu quả mà không cần điều chỉnh hiệu suất hoặc sửa đổi nhiều hình ảnh đầu vào.
Tốc độ cực nhanh: IronOCR.2020+ nhanh hơn tới 10 lần và ít lỗi hơn 250% so với các bản dựng trước.
Tìm hiểu thêm
Để tìm hiểu thêm về OCR trong C#, VB, F# hoặc bất kỳ ngôn ngữ .NET nào khác, vui lòng đọc hướng dẫn cộng đồng của chúng tôi, những hướng dẫn này cung cấp các ví dụ thực tế về cách IronOCR có thể được sử dụng và có thể cho thấy các sắc thái về cách tận dụng tối đa thư viện này.
Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais bem estruturados e visualmente atraentes.