Thai Alphabet OCR ในภาษา C#และ.NET

เวอร์ชันอื่น ๆ ของเอกสารนี้:

IronOCR เป็นส่วนประกอบซอฟต์แวร์ C#ที่ช่วยให้ผู้เข้ารหัส. NET สามารถอ่านข้อความจากรูปภาพและเอกสาร PDF ใน 126 ภาษารวมทั้งตัวอักษรภาษาไทย

เป็นทางแยกขั้นสูงของ Tesseract ซึ่งสร้างขึ้นสำหรับนักพัฒนา. NET โดยเฉพาะและมีประสิทธิภาพเหนือกว่าเอ็นจิ้น Tesseract อื่น ๆ เป็นประจำทั้งในด้านความเร็วและความแม่นยำ

เนื้อหาของ IronOcr.Languages.Thai

แพคเกจนี้ประกอบด้วย 96 OCR ภาษาสำหรับ. NET:

  • ไทย
  • ไทยเบสท์
  • ไทยฟาสต์
  • ThaiAlphabet
  • ThaiAlphabetBest
  • ThaiAlphabetFast

ดาวน์โหลด

Thai Alphabet Language Pack [ไทย]
* Download as ซิป
* Install with
https://www.nuget.org/packages/IronOcr.Languages.Thai/'> NuGet

การติดตั้ง

สิ่งแรกที่เราต้องทำคือติดตั้งแพ็คเกจ Thai Alphabet OCR ในโปรเจ็กต์. NET ของคุณ

PM> Install-Package IronOCR.Languages.Thai

ตัวอย่างรหัส

ตัวอย่างรหัส C#นี้อ่านข้อความตัวอักษรภาษาไทยจากเอกสารรูปภาพหรือ PDF

// PM> Install-Package IronOCR.Languages.Thai
using IronOcr;

// Create an OCR object and specify the language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Using an image input for OCR processing
using (var Input = new OcrInput(@"images\Thai.png"))
{
    // Read the input image and obtain the OCR result
    var Result = Ocr.Read(Input);
    // Retrieve all recognized text from the result
    var AllText = Result.Text;
    // Output the text or use it in further processing
    Console.WriteLine(AllText);
}
// PM> Install-Package IronOCR.Languages.Thai
using IronOcr;

// Create an OCR object and specify the language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Using an image input for OCR processing
using (var Input = new OcrInput(@"images\Thai.png"))
{
    // Read the input image and obtain the OCR result
    var Result = Ocr.Read(Input);
    // Retrieve all recognized text from the result
    var AllText = Result.Text;
    // Output the text or use it in further processing
    Console.WriteLine(AllText);
}
' PM> Install-Package IronOCR.Languages.Thai
Imports IronOcr

' Create an OCR object and specify the language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Using an image input for OCR processing
Using Input = New OcrInput("images\Thai.png")
	' Read the input image and obtain the OCR result
	Dim Result = Ocr.Read(Input)
	' Retrieve all recognized text from the result
	Dim AllText = Result.Text
	' Output the text or use it in further processing
	Console.WriteLine(AllText)
End Using
$vbLabelText   $csharpLabel

ทำไมต้องเลือก IronOCR

IronOCR เป็นไลบรารีซอฟต์แวร์. NET ที่ติดตั้งง่ายสมบูรณ์และมีเอกสารอย่างดี

เลือก IronOCR เพื่อให้ได้ ความแม่นยำ 99.8% + OCR โดยไม่ต้องใช้บริการเว็บภายนอกค่าธรรมเนียมต่อเนื่องหรือส่งเอกสารที่เป็นความลับทางอินเทอร์เน็ต

ทำไมนักพัฒนา C#ถึงเลือก IronOCR กับ Vanilla Tesseract:

  • ติดตั้งเป็น DLL เดียวหรือ NuGet
  • รวมถึงเครื่องยนต์ Tesseract 5, 4 และ 3 นอกกรอบ
  • ความแม่นยำ 99.8% เหนือกว่า Tesseract ปกติอย่างเห็นได้ชัด
  • ความเร็วที่เห็นได้ชัดและ MultiThreading
  • รองรับ MVC, WebApp, Desktop, Console & Server Application
  • ไม่มีรหัส Exes หรือ C ++ ที่จะใช้งานได้
  • รองรับ PDF OCR เต็มรูปแบบ
  • ในการดำเนินการ OCR เกือบทุกไฟล์รูปภาพหรือ PDF
  • รองรับ.NET Core, Standard และ FrameWork เต็มรูปแบบ
  • ปรับใช้บน Windows, Mac, Linux, Azure, Docker, Lambda, AWS
  • อ่านบาร์โค้ดและรหัส QR
  • ส่งออก OCR เป็น XHTML
  • ส่งออก OCR ไปยังเอกสาร PDF ที่ค้นหาได้
  • รองรับมัลติเธรด
  • ภาษาสากล 126 ภาษาทั้งหมดจัดการผ่านไฟล์ NuGet หรือ OcrData
  • แยกรูปภาพพิกัดสถิติและแบบอักษร ไม่ใช่แค่ข้อความ
  • สามารถใช้เพื่อแจกจ่าย Tesseract OCR ใหม่ภายในแอปพลิเคชันเชิงพาณิชย์และที่เป็นกรรมสิทธิ์

IronOCR จะส่องสว่างเมื่อทำงานกับภาพในโลกแห่งความเป็นจริงและเอกสารที่ไม่สมบูรณ์เช่นภาพถ่ายหรือการสแกนที่มีความละเอียดต่ำซึ่งอาจมีสัญญาณรบกวนดิจิทัลหรือความไม่สมบูรณ์

ไลบรารี OCR ฟรี อื่น ๆ สำหรับแพลตฟอร์ม. NET เช่น. net tesseract API และบริการเว็บอื่น ๆ จะทำงานได้ไม่ดีนักในกรณีการใช้งานจริงเหล่านี้

OCR พร้อม Tesseract 5 - เริ่มการเข้ารหัสใน C #

ตัวอย่างโค้ดด้านล่างแสดงให้เห็นว่าการอ่านข้อความจากรูปภาพนั้นง่ายเพียงใดโดยใช้ C#หรือ VB .NET

หนึ่งในสายการบิน

// Reading text from an image using default settings
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
Console.WriteLine(Text);
// Reading text from an image using default settings
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
Console.WriteLine(Text);
' Reading text from an image using default settings
Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
Console.WriteLine(Text)
$vbLabelText   $csharpLabel

Hello World ที่กำหนดค่าได้

// PM> Install-Package IronOCR.Languages.Thai
using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Process an image with IronOCR
using (var Input = new OcrInput())
{
    // Add an image file to the OCR input
    Input.AddImage("images/sample.jpeg");
    // You can add more images for multi-page OCR

    var Result = Ocr.Read(Input);
    // Print the recognized text to the console
    Console.WriteLine(Result.Text);
}
// PM> Install-Package IronOCR.Languages.Thai
using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Process an image with IronOCR
using (var Input = new OcrInput())
{
    // Add an image file to the OCR input
    Input.AddImage("images/sample.jpeg");
    // You can add more images for multi-page OCR

    var Result = Ocr.Read(Input);
    // Print the recognized text to the console
    Console.WriteLine(Result.Text);
}
' PM> Install-Package IronOCR.Languages.Thai
Imports IronOcr

' Initialize IronTesseract for OCR
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Process an image with IronOCR
Using Input = New OcrInput()
	' Add an image file to the OCR input
	Input.AddImage("images/sample.jpeg")
	' You can add more images for multi-page OCR

	Dim Result = Ocr.Read(Input)
	' Print the recognized text to the console
	Console.WriteLine(Result.Text)
End Using
$vbLabelText   $csharpLabel

C#PDF OCR

วิธีเดียวกันนี้สามารถใช้ในการแยกข้อความจากเอกสาร PDF ใด ๆ

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Open the PDF document
using (var input = new OcrInput())
{
    input.AddPdf("example.pdf", "password");
    // Optionally select specific pages to OCR

    // Perform the OCR scan
    var Result = Ocr.Read(input);

    // Output the recognized text and page count
    Console.WriteLine(Result.Text);
    Console.WriteLine($"{Result.Pages.Count()} Pages");
    // 1 page for every page in the PDF
}
using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Open the PDF document
using (var input = new OcrInput())
{
    input.AddPdf("example.pdf", "password");
    // Optionally select specific pages to OCR

    // Perform the OCR scan
    var Result = Ocr.Read(input);

    // Output the recognized text and page count
    Console.WriteLine(Result.Text);
    Console.WriteLine($"{Result.Pages.Count()} Pages");
    // 1 page for every page in the PDF
}
Imports IronOcr

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Open the PDF document
Using input = New OcrInput()
	input.AddPdf("example.pdf", "password")
	' Optionally select specific pages to OCR

	' Perform the OCR scan
	Dim Result = Ocr.Read(input)

	' Output the recognized text and page count
	Console.WriteLine(Result.Text)
	Console.WriteLine($"{Result.Pages.Count()} Pages")
	' 1 page for every page in the PDF
End Using
$vbLabelText   $csharpLabel

OCR สำหรับ MultiPage TIFF

OCR อ่านรูปแบบไฟล์ TIFF รวมถึงเอกสารหลายหน้า TIFF ยังสามารถแปลงเป็นไฟล์ PDF ได้โดยตรงพร้อมข้อความที่ค้นหาได้

using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Use an input source with multiple frames
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF file to the input
    input.AddMultiFrameTiff("multi-frame.tiff");

    // Perform the OCR scan
    var Result = Ocr.Read(Input);

    // Output the recognized text to the console
    Console.WriteLine(Result.Text);
}
using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Use an input source with multiple frames
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF file to the input
    input.AddMultiFrameTiff("multi-frame.tiff");

    // Perform the OCR scan
    var Result = Ocr.Read(Input);

    // Output the recognized text to the console
    Console.WriteLine(Result.Text);
}
Imports IronOcr

' Set up the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Use an input source with multiple frames
Using Input = New OcrInput()
	' Add a multi-frame TIFF file to the input
	input.AddMultiFrameTiff("multi-frame.tiff")

	' Perform the OCR scan
	Dim Result = Ocr.Read(Input)

	' Output the recognized text to the console
	Console.WriteLine(Result.Text)
End Using
$vbLabelText   $csharpLabel

บาร์โค้ดและ QR

คุณลักษณะเฉพาะของ IronOCR คือสามารถอ่านบาร์โค้ดและรหัส QR จากเอกสารในขณะที่กำลังสแกนหาข้อความ อินสแตนซ์ของ OcrResult.OcrBarcode Class จะให้ข้อมูลโดยละเอียดแก่นักพัฒนาเกี่ยวกับบาร์โค้ดที่สแกนแต่ละอัน

using IronOcr;

// Initialize the OCR engine with barcode reading
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;

// Provide the input image containing barcodes
using (var input = new OcrInput())
{
    // Add an image file with barcodes to the input
    input.AddImage("img/Barcode.png");

    // Execute the OCR process
    var Result = Ocr.Read(input);

    // Iterate over all detected barcodes and print their values
    foreach (var Barcode in Result.Barcodes)
    {
        Console.WriteLine(Barcode.Value);
        // Additional properties like type and location are available
    }
}
using IronOcr;

// Initialize the OCR engine with barcode reading
var Ocr = new IronTesseract();
Ocr.Configuration.ReadBarCodes = true;

// Provide the input image containing barcodes
using (var input = new OcrInput())
{
    // Add an image file with barcodes to the input
    input.AddImage("img/Barcode.png");

    // Execute the OCR process
    var Result = Ocr.Read(input);

    // Iterate over all detected barcodes and print their values
    foreach (var Barcode in Result.Barcodes)
    {
        Console.WriteLine(Barcode.Value);
        // Additional properties like type and location are available
    }
}
Imports IronOcr

' Initialize the OCR engine with barcode reading
Private Ocr = New IronTesseract()
Ocr.Configuration.ReadBarCodes = True

' Provide the input image containing barcodes
Using input = New OcrInput()
	' Add an image file with barcodes to the input
	input.AddImage("img/Barcode.png")

	' Execute the OCR process
	Dim Result = Ocr.Read(input)

	' Iterate over all detected barcodes and print their values
	For Each Barcode In Result.Barcodes
		Console.WriteLine(Barcode.Value)
		' Additional properties like type and location are available
	Next Barcode
End Using
$vbLabelText   $csharpLabel

OCR ในพื้นที่เฉพาะของภาพ

วิธีการสแกนและการอ่านทั้งหมดของ IronOCR ให้ความสามารถในการระบุว่าส่วนใดของหน้าหรือหน้าที่เราต้องการอ่านข้อความ สิ่งนี้มีประโยชน์มากเมื่อเราดูรูปแบบมาตรฐานและสามารถประหยัดเวลาได้มากและปรับปรุงประสิทธิภาพ

ในการใช้พื้นที่ครอบตัดเราจะต้องเพิ่มการอ้างอิงระบบไปยัง System.Drawing เพื่อให้เราสามารถใช้วัตถุ System.Drawing.Rectangle

using IronOcr;
using System.Drawing; // Add a reference for System.Drawing

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Specify a specific region of the image for OCR
using (var Input = new OcrInput())
{
    var ContentArea = new System.Drawing.Rectangle
    {
        X = 215,
        Y = 1250,
        Height = 280,
        Width = 1335
    };
    // Dimensions are in pixels

    // Add the specific content area of the input image
    Input.Add("document.png", ContentArea);

    // Perform OCR on the specified content area
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
using IronOcr;
using System.Drawing; // Add a reference for System.Drawing

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Specify a specific region of the image for OCR
using (var Input = new OcrInput())
{
    var ContentArea = new System.Drawing.Rectangle
    {
        X = 215,
        Y = 1250,
        Height = 280,
        Width = 1335
    };
    // Dimensions are in pixels

    // Add the specific content area of the input image
    Input.Add("document.png", ContentArea);

    // Perform OCR on the specified content area
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Imports IronOcr
Imports System.Drawing ' Add a reference for System.Drawing

' Set up the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Specify a specific region of the image for OCR
Using Input = New OcrInput()
	Dim ContentArea = New System.Drawing.Rectangle With {
		.X = 215,
		.Y = 1250,
		.Height = 280,
		.Width = 1335
	}
	' Dimensions are in pixels

	' Add the specific content area of the input image
	Input.Add("document.png", ContentArea)

	' Perform OCR on the specified content area
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
End Using
$vbLabelText   $csharpLabel

OCR สำหรับการสแกนคุณภาพต่ำ

คลาส OcrInput IronOCR สามารถแก้ไขการสแกนที่ Tesseract ปกติไม่สามารถอ่านได้

using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Provide a low-quality image input for OCR
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
    // Enhance image quality
    Input.DeNoise(); // Remove digital noise
    Input.Deskew(); // Correct image alignment

    // Execute the OCR process
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Provide a low-quality image input for OCR
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
    // Enhance image quality
    Input.DeNoise(); // Remove digital noise
    Input.Deskew(); // Correct image alignment

    // Execute the OCR process
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Imports IronOcr

' Set up the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Provide a low-quality image input for OCR
Using Input = New OcrInput("img\Potter.LowQuality.tiff")
	' Enhance image quality
	Input.DeNoise() ' Remove digital noise
	Input.Deskew() ' Correct image alignment

	' Execute the OCR process
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
End Using
$vbLabelText   $csharpLabel

ส่งออกผลลัพธ์ OCR เป็น PDF ที่ค้นหาได้

รูปภาพเป็น PDF พร้อมสตริงข้อความที่คัดลอกได้ สามารถจัดทำดัชนีโดยเครื่องมือค้นหาและฐานข้อมูล

using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Input multiple images to create a searchable PDF
using (var Input = new OcrInput())
{
    Input.Title = "Quarterly Report"; // Set PDF title
    Input.AddImage("image1.jpeg");
    Input.AddImage("image2.png");
    Input.AddImage("image3.gif");

    // Perform OCR on input images
    var Result = Ocr.Read(input);

    // Save OCR results as a searchable PDF file
    Result.SaveAsSearchablePdf("searchable.pdf");
}
using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Input multiple images to create a searchable PDF
using (var Input = new OcrInput())
{
    Input.Title = "Quarterly Report"; // Set PDF title
    Input.AddImage("image1.jpeg");
    Input.AddImage("image2.png");
    Input.AddImage("image3.gif");

    // Perform OCR on input images
    var Result = Ocr.Read(input);

    // Save OCR results as a searchable PDF file
    Result.SaveAsSearchablePdf("searchable.pdf");
}
Imports IronOcr

' Initialize IronTesseract for OCR
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Input multiple images to create a searchable PDF
Using Input = New OcrInput()
	Input.Title = "Quarterly Report" ' Set PDF title
	Input.AddImage("image1.jpeg")
	Input.AddImage("image2.png")
	Input.AddImage("image3.gif")

	' Perform OCR on input images
	Dim Result = Ocr.Read(input)

	' Save OCR results as a searchable PDF file
	Result.SaveAsSearchablePdf("searchable.pdf")
End Using
$vbLabelText   $csharpLabel

TIFF เพื่อการแปลง PDF ที่ค้นหาได้

แปลงเอกสาร TIFF (หรือกลุ่มไฟล์ภาพใด ๆ ) ให้เป็น PDF ที่ค้นหาได้โดยตรงซึ่งสามารถสร้างดัชนีได้โดยอินทราเน็ตเว็บไซต์และเครื่องมือค้นหาของ Google

using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Add a multi-frame TIFF for conversion
using (var Input = new OcrInput())
{
    input.AddMultiFrameTiff("example.tiff");

    // Execute the OCR process and save as a searchable PDF
    var Result = Ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");
}
using IronOcr;

// Set up the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Add a multi-frame TIFF for conversion
using (var Input = new OcrInput())
{
    input.AddMultiFrameTiff("example.tiff");

    // Execute the OCR process and save as a searchable PDF
    var Result = Ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");
}
Imports IronOcr

' Set up the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Add a multi-frame TIFF for conversion
Using Input = New OcrInput()
	input.AddMultiFrameTiff("example.tiff")

	' Execute the OCR process and save as a searchable PDF
	Dim Result = Ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")
End Using
$vbLabelText   $csharpLabel

ส่งออกผลลัพธ์ OCR เป็น HTML

การแปลง OCR Image เป็น XHTML

using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Perform OCR on an image and export results as XHTML
using (var Input = new OcrInput())
{
    Input.Title = "Html Title"; // Set HTML title
    Input.AddImage("image1.jpeg");

    // Execute the OCR process
    var Result = Ocr.Read(input);

    // Save results in HTML format
    Result.SaveAsHocrFile("results.html");
}
using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Perform OCR on an image and export results as XHTML
using (var Input = new OcrInput())
{
    Input.Title = "Html Title"; // Set HTML title
    Input.AddImage("image1.jpeg");

    // Execute the OCR process
    var Result = Ocr.Read(input);

    // Save results in HTML format
    Result.SaveAsHocrFile("results.html");
}
Imports IronOcr

' Initialize IronTesseract for OCR
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Perform OCR on an image and export results as XHTML
Using Input = New OcrInput()
	Input.Title = "Html Title" ' Set HTML title
	Input.AddImage("image1.jpeg")

	' Execute the OCR process
	Dim Result = Ocr.Read(input)

	' Save results in HTML format
	Result.SaveAsHocrFile("results.html")
End Using
$vbLabelText   $csharpLabel

ตัวกรองการปรับปรุงภาพ OCR

IronOCR มีตัวกรองเฉพาะสำหรับ OcrInput เพื่อปรับปรุงประสิทธิภาพของ OCR

ตัวอย่างรหัสการปรับปรุงภาพ

ทำให้ภาพอินพุต OCR มีคุณภาพสูงขึ้นเพื่อให้ได้ผลลัพธ์ OCR ที่ดีขึ้นและเร็วขึ้น

using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Enhance and process a low-quality image
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
    Input.DeNoise(); // Remove digital noise
    Input.Deskew(); // Correct image alignment

    // Execute the OCR process
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
using IronOcr;

// Initialize IronTesseract for OCR
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;

// Enhance and process a low-quality image
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
    Input.DeNoise(); // Remove digital noise
    Input.Deskew(); // Correct image alignment

    // Execute the OCR process
    var Result = Ocr.Read(Input);
    Console.WriteLine(Result.Text);
}
Imports IronOcr

' Initialize IronTesseract for OCR
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai

' Enhance and process a low-quality image
Using Input = New OcrInput("LowQuality.jpeg")
	Input.DeNoise() ' Remove digital noise
	Input.Deskew() ' Correct image alignment

	' Execute the OCR process
	Dim Result = Ocr.Read(Input)
	Console.WriteLine(Result.Text)
End Using
$vbLabelText   $csharpLabel

รายการตัวกรองภาพ OCR

ตัวกรองอินพุตเพื่อเพิ่มประสิทธิภาพ OCR ซึ่งติดตั้งไว้ใน IronOCR ได้แก่ :

  • OcrInput.Rotate (องศาสองเท่า) - หมุนภาพตามจำนวนองศาตามเข็มนาฬิกา สำหรับทวนเข็มนาฬิกาให้ใช้จำนวนลบ
  • OcrInput.Binarize () - ฟิลเตอร์ภาพนี้จะเปลี่ยนทุกพิกเซลเป็นสีดำหรือสีขาวโดยไม่มีพื้นกลาง อาจปรับปรุงประสิทธิภาพของ OCR กรณีที่มีความคมชัดของข้อความกับพื้นหลังต่ำมาก
  • OcrInput ToGrayScale () - ฟิลเตอร์ภาพนี้จะเปลี่ยนทุกพิกเซลให้อยู่ในเฉดสีเทา ไม่น่าจะปรับปรุงความแม่นยำของ OCR แต่อาจเพิ่มความเร็วได้
  • OcrInput.Contrast () - เพิ่มคอนทราสต์โดยอัตโนมัติ ตัวกรองนี้มักจะปรับปรุงความเร็วและความแม่นยำของ OCR ในการสแกนคอนทราสต์ต่ำ
  • OcrInput.DeNoise () - ลบสัญญาณรบกวนดิจิตอล ควรใช้ตัวกรองนี้เฉพาะในกรณีที่คาดว่าจะมีเสียงดัง
  • OcrInput.Invert () - สลับสีทุกสี เช่นขาวกลายเป็นดำ: ดำกลายเป็นขาว
  • OcrInput.Dilate () - สัณฐานวิทยาขั้นสูง การขยาย เพิ่มพิกเซลให้กับขอบเขตของวัตถุในภาพ ตรงข้ามเซาะกราว
  • OcrInput.Erode () - สัณฐานวิทยาขั้นสูง การกัดเซาะ จะลบพิกเซลบนขอบเขตวัตถุตรงข้ามกับ Dilate
  • OcrInput.Deskew () - หมุนภาพเพื่อให้อยู่ในตำแหน่งที่ถูกต้องและตั้งฉากกัน สิ่งนี้มีประโยชน์มากสำหรับ OCR เนื่องจากความอดทนของ Tesseract สำหรับการสแกนที่เอียงอาจต่ำถึง 5 องศา
  • OcrInput.DeepCleanBackgroundNoise () - การกำจัดเสียงรบกวนรอบข้างหนัก ใช้ตัวกรองนี้ในกรณีที่ทราบเสียงพื้นหลังของเอกสารมากเท่านั้นเนื่องจากตัวกรองนี้จะเสี่ยงต่อการลดความแม่นยำของ OCR ของเอกสารที่สะอาดและมีราคาแพงมากของ CPU
  • OcrInput.EnhanceResolution - เพิ่มความละเอียดของภาพคุณภาพต่ำ ไม่จำเป็นต้องใช้ตัวกรองนี้บ่อยครั้งเนื่องจาก OcrInput.MinimumDPI และ OcrInput.TargetDPI จะตรวจจับและแก้ไขอินพุตที่มีความละเอียดต่ำโดยอัตโนมัติ

ทำความสะอาดพื้นหลัง นี่คือการตั้งค่าที่ค่อนข้างใช้เวลานาน อย่างไรก็ตามช่วยให้ไลบรารีสามารถล้างสัญญาณรบกวนดิจิทัลรอยย่นของกระดาษและความไม่สมบูรณ์อื่น ๆ ภายในภาพดิจิทัลโดยอัตโนมัติซึ่งจะทำให้ไลบรารี OCR อื่นอ่านไม่ได้

EnhanceContrast คือการตั้งค่าที่ทำให้ IronOCR เพิ่มความคมชัดของข้อความกับพื้นหลังของภาพโดยอัตโนมัติเพิ่มความแม่นยำของ OCR และโดยทั่วไปจะเพิ่มประสิทธิภาพและความเร็วของ OCR

EnhanceResolution คือการตั้งค่าที่จะตรวจจับภาพที่มีความละเอียดต่ำโดยอัตโนมัติ (ซึ่งมีความละเอียดต่ำกว่า 275 dpi) และเพิ่มขนาดภาพโดยอัตโนมัติจากนั้นเพิ่มความคมชัดของข้อความทั้งหมดเพื่อให้สามารถอ่านได้อย่างสมบูรณ์แบบโดยไลบรารี OCR แม้ว่าการดำเนินการนี้จะใช้เวลานาน แต่โดยทั่วไปแล้วจะช่วยลดเวลาโดยรวมสำหรับการดำเนินการ OCR บนรูปภาพ

Language IronOCR รองรับชุดภาษาสากล 22 ชุดและสามารถใช้การตั้งค่าภาษาเพื่อเลือกหนึ่งหรือหลายภาษาที่จะใช้สำหรับการดำเนินการ OCR

Strategy IronOCR รองรับสองกลยุทธ์ เราอาจเลือกที่จะสแกนเอกสารที่รวดเร็วและแม่นยำน้อยกว่าหรือใช้กลยุทธ์ขั้นสูงซึ่งใช้แบบจำลองปัญญาประดิษฐ์เพื่อปรับปรุงความถูกต้องของข้อความ OCR โดยอัตโนมัติโดยดูความสัมพันธ์ทางสถิติของคำที่มีต่อกันในประโยค .

ColorSpace คือการตั้งค่าที่เราสามารถเลือกให้ OCR เป็นโทนสีเทาหรือสี โดยทั่วไปสีเทาเป็นตัวเลือกที่ดีที่สุด อย่างไรก็ตามบางครั้งเมื่อมีข้อความหรือพื้นหลังที่มีสีคล้ายกัน แต่มีสีต่างกันมากพื้นที่สีเต็มจะให้ผลลัพธ์ที่ดีกว่า

DetectWhiteTextOnDarkBackgrounds โดยทั่วไปแล้วไลบรารี OCR ทั้งหมดคาดว่าจะเห็นข้อความสีดำบนพื้นหลังสีขาว การตั้งค่านี้ช่วยให้ IronOCR ตรวจจับเชิงลบโดยอัตโนมัติหรือหน้ามืดที่มีข้อความสีขาวและอ่านได้

InputImageType การตั้งค่านี้ช่วยให้นักพัฒนาสามารถแนะนำไลบรารี OCR ได้ว่ากำลังดูเอกสารฉบับเต็มหรือตัวอย่างข้อมูลเช่นภาพหน้าจอ

RotateAndStraighten เป็นการตั้งค่าขั้นสูงที่ช่วยให้ IronOCR มีความสามารถพิเศษในการอ่านเอกสารที่ไม่เพียง แต่หมุนได้ แต่อาจมีมุมมองเช่นภาพถ่ายของเอกสารข้อความ

ReadBarcodes เป็นคุณสมบัติที่มีประโยชน์ซึ่งช่วยให้ IronOCR สามารถอ่านบาร์โค้ดและรหัส QR บนหน้าได้โดยอัตโนมัติในขณะที่อ่านข้อความโดยไม่ต้องเพิ่มภาระเวลาเพิ่มเติม

ความลึกของสี การตั้งค่านี้กำหนดจำนวนบิตต่อพิกเซลที่ไลบรารี OCR จะใช้เพื่อกำหนดความลึกของสี ความลึกของสีที่สูงขึ้นอาจเพิ่มคุณภาพของ OCR แต่จะเพิ่มเวลาในการดำเนินการ OCR ให้เสร็จสมบูรณ์ด้วย

126 ชุดภาษา

IronOCR รองรับ ภาษาสากล 126 ภาษา ผ่านชุดภาษาซึ่งแจกจ่ายเป็น DLL ซึ่งสามารถ ดาวน์โหลดได้จากเว็บไซต์นี้ หรือจาก NuGet Package Manager

ภาษาต่างๆ ได้แก่ เยอรมันฝรั่งเศสอังกฤษจีนญี่ปุ่นและอื่น ๆ อีกมากมาย มีชุดภาษาผู้เชี่ยวชาญสำหรับหนังสือเดินทาง MRZ, การตรวจสอบ MICR, ข้อมูลทางการเงิน, ป้ายทะเบียนและอื่น ๆ อีกมากมาย คุณยังสามารถใช้ไฟล์ ".traineddata" ของ tesseract รวมทั้งไฟล์ที่คุณสร้างขึ้นเอง

ตัวอย่างภาษา

การใช้ภาษา OCR อื่น ๆ

// using IronOcr;
// PM> Install-Package IronOcr.Languages.Arabic

using IronOcr;

// Initialize the OCR engine for Arabic language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic;

// Provide the input image containing Arabic text
using (var input = new OcrInput())
{
    input.AddImage("img/arabic.gif");

    // Optional: Enhance image if necessary
    // OCR even for low-quality input
    var Result = Ocr.Read(input);

    // Save results as a text file since Console may not display Arabic text correctly
    Result.SaveAsTextFile("arabic.txt");
}
// using IronOcr;
// PM> Install-Package IronOcr.Languages.Arabic

using IronOcr;

// Initialize the OCR engine for Arabic language
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Arabic;

// Provide the input image containing Arabic text
using (var input = new OcrInput())
{
    input.AddImage("img/arabic.gif");

    // Optional: Enhance image if necessary
    // OCR even for low-quality input
    var Result = Ocr.Read(input);

    // Save results as a text file since Console may not display Arabic text correctly
    Result.SaveAsTextFile("arabic.txt");
}
' using IronOcr;
' PM> Install-Package IronOcr.Languages.Arabic

Imports IronOcr

' Initialize the OCR engine for Arabic language
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Arabic

' Provide the input image containing Arabic text
Using input = New OcrInput()
	input.AddImage("img/arabic.gif")

	' Optional: Enhance image if necessary
	' OCR even for low-quality input
	Dim Result = Ocr.Read(input)

	' Save results as a text file since Console may not display Arabic text correctly
	Result.SaveAsTextFile("arabic.txt")
End Using
$vbLabelText   $csharpLabel

ตัวอย่างหลายภาษา

นอกจากนี้ยังสามารถ OCR โดยใช้หลายภาษาในเวลาเดียวกัน สิ่งนี้สามารถช่วยรับข้อมูลเมตาและ URL ภาษาอังกฤษในเอกสาร Unicode ได้จริงๆ

// using IronOcr;
// PM> Install-Package IronOcr.Languages.ChineseSimplified

using IronOcr;

// Initialize the OCR engine with multiple languages
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Thai); // Additional language

// Input a multi-language document
using (var input = new OcrInput())
{
    input.Add("multi-language.pdf");

    // Perform OCR with multiple languages
    var Result = Ocr.Read(input);

    // Save results in a text file
    Result.SaveAsTextFile("results.txt");
}
// using IronOcr;
// PM> Install-Package IronOcr.Languages.ChineseSimplified

using IronOcr;

// Initialize the OCR engine with multiple languages
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified;
Ocr.AddSecondaryLanguage(OcrLanguage.Thai); // Additional language

// Input a multi-language document
using (var input = new OcrInput())
{
    input.Add("multi-language.pdf");

    // Perform OCR with multiple languages
    var Result = Ocr.Read(input);

    // Save results in a text file
    Result.SaveAsTextFile("results.txt");
}
' using IronOcr;
' PM> Install-Package IronOcr.Languages.ChineseSimplified

Imports IronOcr

' Initialize the OCR engine with multiple languages
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.ChineseSimplified
Ocr.AddSecondaryLanguage(OcrLanguage.Thai) ' Additional language

' Input a multi-language document
Using input = New OcrInput()
	input.Add("multi-language.pdf")

	' Perform OCR with multiple languages
	Dim Result = Ocr.Read(input)

	' Save results in a text file
	Result.SaveAsTextFile("results.txt")
End Using
$vbLabelText   $csharpLabel

วัตถุผลลัพธ์ OCR โดยละเอียด

IronOCR ส่งคืนอ็อบเจ็กต์ผลลัพธ์ OCR สำหรับการดำเนินการ OCR แต่ละครั้ง โดยทั่วไปนักพัฒนาจะใช้คุณสมบัติข้อความของวัตถุนี้เพื่อรับข้อความที่สแกนจากรูปภาพเท่านั้น อย่างไรก็ตามผลลัพธ์ของ OCR DOM นั้นก้าวหน้ากว่านี้มาก

using IronOcr;
using System.Drawing; // Add a reference for System.Drawing

// Initialize the OCR engine with necessary configurations
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading

// Perform OCR on the input image
using (var Input = new OcrInput(@"images\sample.tiff"))
{
    OcrResult Result = Ocr.Read(Input);

    // Access detailed OCR results
    var Pages = Result.Pages;
    var Words = Pages[0].Words;
    var Barcodes = Result.Barcodes;

    // Explore here to find the rich detailed API for:
    // - Pages, Blocks, Paragraphs, Lines, Words, Characters
    // - Image exports, Font coordinates, statistical data
}
using IronOcr;
using System.Drawing; // Add a reference for System.Drawing

// Initialize the OCR engine with necessary configurations
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Thai;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm;
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading

// Perform OCR on the input image
using (var Input = new OcrInput(@"images\sample.tiff"))
{
    OcrResult Result = Ocr.Read(Input);

    // Access detailed OCR results
    var Pages = Result.Pages;
    var Words = Pages[0].Words;
    var Barcodes = Result.Barcodes;

    // Explore here to find the rich detailed API for:
    // - Pages, Blocks, Paragraphs, Lines, Words, Characters
    // - Image exports, Font coordinates, statistical data
}
Imports IronOcr
Imports System.Drawing ' Add a reference for System.Drawing

' Initialize the OCR engine with necessary configurations
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Thai
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm
Ocr.Configuration.ReadBarCodes = True ' Enable barcode reading

' Perform OCR on the input image
Using Input = New OcrInput("images\sample.tiff")
	Dim Result As OcrResult = Ocr.Read(Input)

	' Access detailed OCR results
	Dim Pages = Result.Pages
	Dim Words = Pages(0).Words
	Dim Barcodes = Result.Barcodes

	' Explore here to find the rich detailed API for:
	' - Pages, Blocks, Paragraphs, Lines, Words, Characters
	' - Image exports, Font coordinates, statistical data
End Using
$vbLabelText   $csharpLabel

ประสิทธิภาพ

IronOCR ทำงานนอกกรอบโดยไม่จำเป็นต้องปรับแต่งประสิทธิภาพหรือปรับเปลี่ยนภาพอินพุตมากนัก

Speed is Blazing: IronOcr.2020 + เร็วขึ้นสูงสุด 10 เท่าและทำให้เกิดข้อผิดพลาดน้อยกว่ารุ่นก่อนหน้าถึง 250%

เรียนรู้เพิ่มเติม

หากต้องการเรียนรู้เพิ่มเติมเกี่ยวกับ OCR ในภาษา C #, VB, F # หรือภาษา. NET อื่น ๆ โปรด อ่านบทแนะนำชุมชนของเรา ซึ่งให้ตัวอย่างโลกแห่งความเป็นจริงเกี่ยวกับวิธีการใช้งาน IronOCR และอาจแสดงความแตกต่างของวิธีการใช้ประโยชน์สูงสุดจาก ห้องสมุดนี้

นอกจากนี้ยังมี การอ้างอิงออบเจ็กต์ แบบเต็ม สำหรับนักพัฒนา. NET