OCR בעברית ב- C# ו- .NET

גרסאות אחרות של מסמך זה:

IronOCR הוא רכיב תוכנה C# המאפשר לקודדי .NET לקרוא טקסט מתמונות ומסמכי PDF בשפה 126, כולל עברית.

זהו מזלג מתקדם של Tesseract, שנבנה באופן בלעדי עבור מפתחי .NET ועולה בקביעות על מנועי Tesseract אחרים במהירות ובדיוק.

תוכן IronOcr.Languages.Hebrew

חבילה זו מכילה 108 שפות OCR עבור .NET:

  • עִברִית
  • עברית הטוב ביותר
  • עברית מהר
  • עברית אלפבית
  • עברית אלפבית הטוב ביותר
  • עברית Alfabet מהיר

הורד

חבילת שפה עברית [עברית]
* Download as רוכסן
* Install with
https://www.nuget.org/packages/IronOcr.Languages.Hebrew/' NuGet

הַתקָנָה

הדבר הראשון שעלינו לעשות הוא להתקין את חבילת ה- OCR העברית שלנו לפרויקט .NET שלך.

PM> Install-Package IronOCR.Languages.Hebrew

דוגמת קוד

דוגמת קוד C# זו קוראת טקסט בעברית ממסמך תמונה או PDF.

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

// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR Language to Hebrew

// Load the image for OCR
using (var Input = new OcrInput(@"images\Hebrew.png"))
{
    // Perform OCR on the image
    var Result = Ocr.Read(Input);
    // Retrieve the extracted text from the result
    var AllText = Result.Text;
    Console.WriteLine(AllText); // Print the extracted text to the console
}
// PM> Install-Package IronOcr.Languages.Hebrew
using IronOcr;

// Create an instance of IronTesseract for OCR processing
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR Language to Hebrew

// Load the image for OCR
using (var Input = new OcrInput(@"images\Hebrew.png"))
{
    // Perform OCR on the image
    var Result = Ocr.Read(Input);
    // Retrieve the extracted text from the result
    var AllText = Result.Text;
    Console.WriteLine(AllText); // Print the extracted text to the console
}
' PM> Install-Package IronOcr.Languages.Hebrew
Imports IronOcr

' Create an instance of IronTesseract for OCR processing
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set OCR Language to Hebrew

' Load the image for OCR
Using Input = New OcrInput("images\Hebrew.png")
	' Perform OCR on the image
	Dim Result = Ocr.Read(Input)
	' Retrieve the extracted text from the result
	Dim AllText = Result.Text
	Console.WriteLine(AllText) ' Print the extracted text to the console
End Using
$vbLabelText   $csharpLabel

מדוע לבחור ב- IronOCR?

IronOCR היא ספריית תוכנת .NET קלה להתקנה, מלאה ומתועדת היטב.

בחר IronOCR כדי להשיג דיוק של 99.8% + OCR מבלי להשתמש בשירותי אינטרנט חיצוניים, בתשלומים שוטפים או בשליחת מסמכים חסויים דרך האינטרנט.

מדוע מפתחי C# בוחרים ב- IronOCR על פני Vanilla Tesseract:

  • התקן כ- DLL יחיד או כ- NuGet
  • כולל עבור מנועי Tesseract 5, 4 ו- 3 מהקופסה.
  • דיוק 99.8% עולה על Tesseract הרגיל באופן משמעותי.
  • מהירות בוהקת ורב-הברגה
  • תואם ל- MVC, WebApp, Desktop, Console & Server
  • אין Exes או C ++ קוד לעבוד איתו
  • תמיכה מלאה ב- PDF ב- OCR
  • כדי לבצע OCR כמעט כל קובץ תמונה או PDF
  • תמיכה מלאה ב-. Core, Standard ו- Framework
  • פרוס ב- Windows, Mac, Linux, Azure, Docker, Lambda, AWS
  • קרא ברקודים וקודי QR
  • ייצא OCR כמו ל- XHTML
  • ייצא OCR למסמכי PDF הניתנים לחיפוש
  • תמיכה בריבוי הליכי משנה
  • 126 שפות בינלאומיות מנוהלות באמצעות קבצי NuGet או OcrData
  • חלץ תמונות, קואורדינטות, סטטיסטיקה וגופנים. לא רק טקסט.
  • ניתן להשתמש בה להפצה מחודשת של Tesseract OCR בתוך יישומים מסחריים וקנייניים.

ברזל OCR זורח בעבודה עם תמונות של העולם האמיתי ומסמכים לא מושלמים כגון תצלומים, או סריקות ברזולוציה נמוכה שעשויות להיות בעלות רעש דיגיטלי או פגמים.

ספריות OCR אחרות בחינם לפלטפורמת .NET כגון ממשקי API אחרים ושירותי אינטרנט מסוג tesseract .net אינם מתפקדים כל כך טוב במקרים אלה של שימוש אמיתי.

OCR עם Tesseract 5 - התחל קידוד ב- C#

דוגמת הקוד שלהלן מראה כמה קל לקרוא טקסט מתמונה באמצעות C# או VB .NET.

OneLiner

// One-liner example for reading text from an image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
Console.WriteLine(Text); // Output the text content to console
// One-liner example for reading text from an image
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;
Console.WriteLine(Text); // Output the text content to console
' One-liner example for reading text from an image
Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").Text
Console.WriteLine(Text) ' Output the text content to console
$vbLabelText   $csharpLabel

העולם הניתן להגדרה

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input object for images
using (var Input = new OcrInput())
{
    // Add an image to the OCR input
    Input.AddImage("images/sample.jpeg");
    //... You can add any number of images

    // Perform OCR and read the text from the input images
    var Result = Ocr.Read(Input);

    // Output the extracted text to the console
    Console.WriteLine(Result.Text);
}
// PM> Install-Package IronOCR.Languages.Hebrew
using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input object for images
using (var Input = new OcrInput())
{
    // Add an image to the OCR input
    Input.AddImage("images/sample.jpeg");
    //... You can add any number of images

    // Perform OCR and read the text from the input images
    var Result = Ocr.Read(Input);

    // Output the extracted text to the console
    Console.WriteLine(Result.Text);
}
' PM> Install-Package IronOCR.Languages.Hebrew
Imports IronOcr

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Create an OCR input object for images
Using Input = New OcrInput()
	' Add an image to the OCR input
	Input.AddImage("images/sample.jpeg")
	'... You can add any number of images

	' Perform OCR and read the text from the input images
	Dim Result = Ocr.Read(Input)

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

C# PDF OCR

באותה גישה ניתן להשתמש כדי לחלץ טקסט מכל מסמך PDF.

using IronOcr;

// Instantiate the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the OCR language to Hebrew

// Create an input object for OCR
using (var input = new OcrInput())
{
    // Add a PDF document to the input with an optional password
    input.AddPdf("example.pdf", "password");
    // We can also specify specific page numbers for OCR

    // Perform OCR to read the text from the PDF
    var Result = Ocr.Read(input);

    // Output the results to the console
    Console.WriteLine(Result.Text);
    Console.WriteLine($"{Result.Pages.Count()} Pages"); // Output the page count
}
using IronOcr;

// Instantiate the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the OCR language to Hebrew

// Create an input object for OCR
using (var input = new OcrInput())
{
    // Add a PDF document to the input with an optional password
    input.AddPdf("example.pdf", "password");
    // We can also specify specific page numbers for OCR

    // Perform OCR to read the text from the PDF
    var Result = Ocr.Read(input);

    // Output the results to the console
    Console.WriteLine(Result.Text);
    Console.WriteLine($"{Result.Pages.Count()} Pages"); // Output the page count
}
Imports IronOcr

' Instantiate the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the OCR language to Hebrew

' Create an input object for OCR
Using input = New OcrInput()
	' Add a PDF document to the input with an optional password
	input.AddPdf("example.pdf", "password")
	' We can also specify specific page numbers for OCR

	' Perform OCR to read the text from the PDF
	Dim Result = Ocr.Read(input)

	' Output the results to the console
	Console.WriteLine(Result.Text)
	Console.WriteLine($"{Result.Pages.Count()} Pages") ' Output the page count
End Using
$vbLabelText   $csharpLabel

OCR עבור TIFFs מרובי-דפים

פורמט קובץ TIFF לקריאת OCR כולל מסמכי עמודים מרובים. ניתן להמיר TIFF גם ישירות לקובץ PDF עם טקסט לחיפוש.

using IronOcr;

// Instantiate the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR language to Hebrew

// Create an input object for TIFF files
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF to the input
    Input.AddMultiFrameTiff("multi-frame.tiff");

    // Perform OCR to read the text from the TIFF
    var Result = Ocr.Read(Input);

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

// Instantiate the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR language to Hebrew

// Create an input object for TIFF files
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF to the input
    Input.AddMultiFrameTiff("multi-frame.tiff");

    // Perform OCR to read the text from the TIFF
    var Result = Ocr.Read(Input);

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

' Instantiate the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set OCR language to Hebrew

' Create an input object for TIFF files
Using Input = New OcrInput()
	' Add a multi-frame TIFF to the input
	Input.AddMultiFrameTiff("multi-frame.tiff")

	' Perform OCR to read the text from the TIFF
	Dim Result = Ocr.Read(Input)

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

ברקודים ו- QR

מאפיין ייחודי של ברזל OCR הוא שהוא יכול לקרוא ברקודים וקודי QR ממסמכים בזמן שהוא סורק לטקסט. מופעים של מחלקת OcrResult.OcrBarcode נותנים למפתח מידע מפורט על כל ברקוד סרוק.

using IronOcr;

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

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

    // Perform OCR to read the barcodes and text from the image
    var Result = Ocr.Read(input);

    // Iterate over each detected barcode in the result
    foreach (var Barcode in Result.Barcodes)
    {
        // Output the barcode value to the console
        Console.WriteLine(Barcode.Value);
        // The type and location properties are also accessible
    }
}
using IronOcr;

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

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

    // Perform OCR to read the barcodes and text from the image
    var Result = Ocr.Read(input);

    // Iterate over each detected barcode in the result
    foreach (var Barcode in Result.Barcodes)
    {
        // Output the barcode value to the console
        Console.WriteLine(Barcode.Value);
        // The type and location properties are also accessible
    }
}
Imports IronOcr

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

' Create an OCR input object
Using input = New OcrInput()
	' Add an image with barcodes to the input
	input.AddImage("img/Barcode.png")

	' Perform OCR to read the barcodes and text from the image
	Dim Result = Ocr.Read(input)

	' Iterate over each detected barcode in the result
	For Each Barcode In Result.Barcodes
		' Output the barcode value to the console
		Console.WriteLine(Barcode.Value)
		' The type and location properties are also accessible
	Next Barcode
End Using
$vbLabelText   $csharpLabel

OCR על אזורים ספציפיים של תמונות

כל שיטות הסריקה והקריאה של IronOCR מספקות את היכולת לציין בדיוק מאיזה חלק בדף או בדפים שאנחנו רוצים לקרוא טקסט. זה מאוד שימושי כשאנחנו בוחנים טפסים סטנדרטיים ויכולים לחסוך הרבה מאוד זמן ולשפר את היעילות.

כדי להשתמש באזורי יבול, נצטרך להוסיף הפניה למערכת ל-System.Drawing כדי שנוכל להשתמש באובייקט System.Drawing.Rectangle.

using IronOcr;
using System.Drawing; // Add reference to System.Drawing for Rectangle

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR language to Hebrew

// Create an OCR input with a specific content area
using (var Input = new OcrInput())
{
    // Define the specific area to perform OCR on (in pixels)
    var ContentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };

    // Add the image file and content area to the input
    Input.Add("document.png", ContentArea);

    // Perform OCR to extract text from the specified area
    var Result = Ocr.Read(Input);

    // Output the extracted text to the console
    Console.WriteLine(Result.Text);
}
using IronOcr;
using System.Drawing; // Add reference to System.Drawing for Rectangle

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set OCR language to Hebrew

// Create an OCR input with a specific content area
using (var Input = new OcrInput())
{
    // Define the specific area to perform OCR on (in pixels)
    var ContentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };

    // Add the image file and content area to the input
    Input.Add("document.png", ContentArea);

    // Perform OCR to extract text from the specified area
    var Result = Ocr.Read(Input);

    // Output the extracted text to the console
    Console.WriteLine(Result.Text);
}
Imports IronOcr
Imports System.Drawing ' Add reference to System.Drawing for Rectangle

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set OCR language to Hebrew

' Create an OCR input with a specific content area
Using Input = New OcrInput()
	' Define the specific area to perform OCR on (in pixels)
	Dim ContentArea = New Rectangle() With {
		.X = 215,
		.Y = 1250,
		.Height = 280,
		.Width = 1335
	}

	' Add the image file and content area to the input
	Input.Add("document.png", ContentArea)

	' Perform OCR to extract text from the specified area
	Dim Result = Ocr.Read(Input)

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

OCR לסריקות באיכות נמוכה

הברזל OCR OcrInput בכיתה יכול לתקן סריקות זה נורמלי Tesseract לא יכול לקרוא.

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Load the low-quality image for OCR
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
    // Apply image preprocessing filters to fix digital noise and poor scanning
    Input.DeNoise(); // Fixes digital noise
    Input.Deskew(); // Fixes rotation and perspective

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

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Load the low-quality image for OCR
using (var Input = new OcrInput(@"img\Potter.LowQuality.tiff"))
{
    // Apply image preprocessing filters to fix digital noise and poor scanning
    Input.DeNoise(); // Fixes digital noise
    Input.Deskew(); // Fixes rotation and perspective

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

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

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Load the low-quality image for OCR
Using Input = New OcrInput("img\Potter.LowQuality.tiff")
	' Apply image preprocessing filters to fix digital noise and poor scanning
	Input.DeNoise() ' Fixes digital noise
	Input.Deskew() ' Fixes rotation and perspective

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

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

ייצא תוצאות OCR כקובץ PDF לחיפוש

תמונה ל- PDF עם מחרוזות טקסט ניתנות להעתקה. ניתן לאינדקס על ידי מנועי חיפוש ומאגרי מידע.

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input object for images
using (var Input = new OcrInput())
{
    // Specify the title for the output PDF
    Input.Title = "Quarterly Report";

    // Add multiple images to the input for OCR
    Input.AddImage("image1.jpeg");
    Input.AddImage("image2.png");
    Input.AddImage("image3.gif");

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input object for images
using (var Input = new OcrInput())
{
    // Specify the title for the output PDF
    Input.Title = "Quarterly Report";

    // Add multiple images to the input for OCR
    Input.AddImage("image1.jpeg");
    Input.AddImage("image2.png");
    Input.AddImage("image3.gif");

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

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Create an OCR input object for images
Using Input = New OcrInput()
	' Specify the title for the output PDF
	Input.Title = "Quarterly Report"

	' Add multiple images to the input for OCR
	Input.AddImage("image1.jpeg")
	Input.AddImage("image2.png")
	Input.AddImage("image3.gif")

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

TIFF להמרת PDF הניתנת לחיפוש

הפוך מסמך TIFF (או כל קבוצה של קבצי תמונה) ישירות למסמך PDF שניתן לחיפוש בו ניתן להוסיף לאינדקס באמצעות מנועי חיפוש באינטרא-נט, באתר ובגוגל.

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input for multi-frame TIFFs
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF to the input
    Input.AddMultiFrameTiff("example.tiff");

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input for multi-frame TIFFs
using (var Input = new OcrInput())
{
    // Add a multi-frame TIFF to the input
    Input.AddMultiFrameTiff("example.tiff");

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

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Create an OCR input for multi-frame TIFFs
Using Input = New OcrInput()
	' Add a multi-frame TIFF to the input
	Input.AddMultiFrameTiff("example.tiff")

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

ייצא תוצאות OCR כ- HTML

המרת תמונה OCR להמרת XHTML.

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input for images
using (var Input = new OcrInput())
{
    // Specify the title for the output HTML
    Input.Title = "Html Title";

    // Add an image to the input
    Input.AddImage("image1.jpeg");

    // Perform OCR and save the results as an HTML file
    var Result = Ocr.Read(Input);
    Result.SaveAsHocrFile("results.html");
}
using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Create an OCR input for images
using (var Input = new OcrInput())
{
    // Specify the title for the output HTML
    Input.Title = "Html Title";

    // Add an image to the input
    Input.AddImage("image1.jpeg");

    // Perform OCR and save the results as an HTML file
    var Result = Ocr.Read(Input);
    Result.SaveAsHocrFile("results.html");
}
Imports IronOcr

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Create an OCR input for images
Using Input = New OcrInput()
	' Specify the title for the output HTML
	Input.Title = "Html Title"

	' Add an image to the input
	Input.AddImage("image1.jpeg")

	' Perform OCR and save the results as an HTML file
	Dim Result = Ocr.Read(Input)
	Result.SaveAsHocrFile("results.html")
End Using
$vbLabelText   $csharpLabel

מסנני שיפור תמונות OCR

IronOCR מספק פילטרים ייחודיים לאובייקטים של OcrInput לשיפור ביצועי ה- OCR.

דוגמת קוד לשיפור תמונה

הופך תמונות קלט OCR לאיכותיות יותר כדי לייצר תוצאות OCR טובות יותר ומהירות יותר.

using IronOcr;

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Load the low-quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
    // Apply image preprocessing filters to fix digital noise and poor scanning
    Input.DeNoise(); // Fixes digital noise
    Input.Deskew(); // Fixes rotation and perspective

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

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew; // Set the language to Hebrew

// Load the low-quality image for OCR
using (var Input = new OcrInput(@"LowQuality.jpeg"))
{
    // Apply image preprocessing filters to fix digital noise and poor scanning
    Input.DeNoise(); // Fixes digital noise
    Input.Deskew(); // Fixes rotation and perspective

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

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

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew ' Set the language to Hebrew

' Load the low-quality image for OCR
Using Input = New OcrInput("LowQuality.jpeg")
	' Apply image preprocessing filters to fix digital noise and poor scanning
	Input.DeNoise() ' Fixes digital noise
	Input.Deskew() ' Fixes rotation and perspective

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

	' Output the extracted text to the console
	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 של מסמכים נקיים והוא יקר מאוד במעבד.
  • OcrInput.EnhanceResolution - משפר את הרזולוציה של תמונות באיכות נמוכה. מסנן זה אינו נדרש לעיתים קרובות מכיוון ש- OcrInput.MinimumDPI ו- OcrInput.TargetDPI יתפסו ויפתרו אוטומטית תשומות ברזולוציה נמוכה.

CleanBackgroundNoise. זו הגדרה שלוקחת זמן רב; עם זאת, היא מאפשרת לספרייה לנקות באופן אוטומטי רעשים דיגיטליים, קמטי נייר ופגמים אחרים בתוך תמונה דיגיטלית, שאם לא כן, היא לא תוכל לקרוא אותה על ידי ספריות OCR אחרות.

EnhanceContrast היא הגדרה שגורמת ל- OCR של ברזל להגדיל באופן אוטומטי את הניגודיות של הטקסט על רקע התמונה, ולהגדיל את הדיוק של ה- OCR ולגדול את הביצועים ואת מהירות ה- OCR.

EnhanceResolution היא הגדרה שתזהה באופן אוטומטי תמונות ברזולוציה נמוכה (שהן מתחת ל -275 dpi) ותעלה את התמונה באופן אוטומטי ואז תחדד את כל הטקסט כך שתוכל לקרוא אותה בצורה מושלמת על ידי ספריית OCR. למרות שפעולה זו כשלעצמה גוזלת זמן, היא בדרך כלל מפחיתה את הזמן הכולל לפעולת OCR בתמונה.

שפת ברזל OCR תומכת ב 22 חבילות שפה בינלאומיות, ובאמצעות הגדרת השפה ניתן לבחור שפה אחת או יותר מרובות שיוחלו על פעולת OCR.

אסטרטגיית ברזל OCR תומכת בשתי אסטרטגיות. אנו עשויים לבחור בסריקה מהירה ופחות מדויקת של המסמך, או להשתמש באסטרטגיה מתקדמת המשתמשת בכמה מודלים של בינה מלאכותית כדי לשפר באופן אוטומטי את הדיוק של טקסט OCR על ידי התבוננות ביחס הסטטיסטי של מילים זה לזה במשפט. .

ColorSpace היא הגדרה לפיה אנו יכולים לבחור OCR בגווני אפור או צבע. באופן כללי, גווני אפור היא האפשרות הטובה ביותר. עם זאת, לפעמים כשיש טקסטים או רקעים בגוון דומה אך צבע שונה מאוד, שטח צבע בצבע מלא יספק תוצאות טובות יותר.

DetectWhiteTextOnDarkBackgrounds. באופן כללי, כל ספריות ה- OCR מצפות לראות טקסט שחור על רקע לבן. הגדרה זו מאפשרת ל- IronOCR לאתר באופן אוטומטי שליליות, או עמודים כהים עם טקסט לבן, ולקרוא אותם.

InputImageType. הגדרה זו מאפשרת למפתח להדריך את ספריית ה- OCR האם הוא מסתכל על מסמך מלא או קטע, כמו צילום מסך.

RotateAndStraighten היא הגדרה מתקדמת המאפשרת ל- IronOCR את היכולת הייחודית לקרוא מסמכים שאינם רק מסובבים, אלא אולי מכילים פרספקטיבה, כגון צילומי מסמכי טקסט.

ReadBarcodes היא תכונה שימושית המאפשרת ל- OCR של ברזל לקרוא ברקודים וקודי QR באופן אוטומטי בעמודים שכן הוא קורא גם טקסט, מבלי להוסיף עומס זמן גדול נוסף.

עומק צבע. הגדרה זו קובעת בכמה ביטים לפיקסל שתשתמש ספריית ה- OCR כדי לקבוע את עומק הצבע. עומק צבע גבוה יותר עשוי להגביר את איכות ה- OCR, אך גם יגדיל את הזמן הדרוש להשלמת פעולת ה- OCR.

126 חבילות שפה

IronOCR תומך ב 126 שפות בינלאומיות באמצעות חבילות שפה המופצות כ- DLL, הניתנות להורדה מאתר זה , או גם ממנהל החבילות של NuGet .

השפות כוללות גרמנית, צרפתית, אנגלית, סינית, יפנית ורבים אחרים. חבילות שפות מומחים קיימות עבור דרכון MRZ, בדיקות MICR, נתונים פיננסיים, לוחיות רישוי ורבים אחרים. אתה יכול גם להשתמש בכל קובץ ".traineddata" קטן יותר - כולל בקבצים שאתה יוצר בעצמך.

דוגמא לשפה

שימוש בשפות OCR אחרות.

using IronOcr;

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

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

// Create an OCR input object
using (var input = new OcrInput())
{
    // Add an Arabic image to the input
    input.AddImage("img/arabic.gif");
    // Add image filters if necessary
    // Even low-quality input can be read by IronTesseract

    // Perform OCR to read the text
    var Result = Ocr.Read(input);

    // Save the extracted text to a file since console may not print Arabic easily
    Result.SaveAsTextFile("arabic.txt");
}
using IronOcr;

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

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

// Create an OCR input object
using (var input = new OcrInput())
{
    // Add an Arabic image to the input
    input.AddImage("img/arabic.gif");
    // Add image filters if necessary
    // Even low-quality input can be read by IronTesseract

    // Perform OCR to read the text
    var Result = Ocr.Read(input);

    // Save the extracted text to a file since console may not print Arabic easily
    Result.SaveAsTextFile("arabic.txt");
}
Imports IronOcr

' PM> Install-Package IronOcr.Languages.Arabic

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

' Create an OCR input object
Using input = New OcrInput()
	' Add an Arabic image to the input
	input.AddImage("img/arabic.gif")
	' Add image filters if necessary
	' Even low-quality input can be read by IronTesseract

	' Perform OCR to read the text
	Dim Result = Ocr.Read(input)

	' Save the extracted text to a file since console may not print Arabic easily
	Result.SaveAsTextFile("arabic.txt")
End Using
$vbLabelText   $csharpLabel

דוגמה לשפה מרובה

אפשר גם OCR באמצעות מספר שפות בו זמנית. זה באמת יכול לעזור להשיג מטא נתונים ושפות URL בשפה האנגלית במסמכי Unicode.

using IronOcr;

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified; // Set primary language
Ocr.AddSecondaryLanguage(OcrLanguage.Hebrew); // Add secondary language

// Create an OCR input object
using (var input = new OcrInput())
{
    // Add a multi-language document to the input
    input.Add("multi-language.pdf");

    // Perform OCR and save the result as a text file
    var Result = Ocr.Read(input);
    Result.SaveAsTextFile("results.txt");
}
using IronOcr;

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

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.ChineseSimplified; // Set primary language
Ocr.AddSecondaryLanguage(OcrLanguage.Hebrew); // Add secondary language

// Create an OCR input object
using (var input = new OcrInput())
{
    // Add a multi-language document to the input
    input.Add("multi-language.pdf");

    // Perform OCR and save the result as a text file
    var Result = Ocr.Read(input);
    Result.SaveAsTextFile("results.txt");
}
Imports IronOcr

' PM> Install-Package IronOcr.Languages.ChineseSimplified

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.ChineseSimplified ' Set primary language
Ocr.AddSecondaryLanguage(OcrLanguage.Hebrew) ' Add secondary language

' Create an OCR input object
Using input = New OcrInput()
	' Add a multi-language document to the input
	input.Add("multi-language.pdf")

	' Perform OCR and save the result as a text file
	Dim Result = Ocr.Read(input)
	Result.SaveAsTextFile("results.txt")
End Using
$vbLabelText   $csharpLabel

אובייקטים מפורטים של תוצאות OCR

ברזל OCR מחזיר אובייקט תוצאה של OCR עבור כל פעולת OCR. באופן כללי, מפתחים משתמשים רק במאפיין הטקסט של אובייקט זה כדי לסרוק את הטקסט מהתמונה. עם זאת, תוצאות ה- DOM של ה- OCR מתקדמות הרבה יותר מזה.

using IronOcr;
using System.Drawing; // Add assembly reference

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Set engine mode
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading

// Load the image input for OCR
using (var Input = new OcrInput(@"images\sample.tiff"))
{
    // Perform OCR and get the result object
    OcrResult Result = Ocr.Read(Input);

    // Access detailed OCR results
    var Pages = Result.Pages; // Get pages from the result
    var Words = Pages[0].Words; // Access the words from the first page
    var Barcodes = Result.Barcodes; // Access scanned barcodes

    // Discover more in the detailed API:
    // - Pages, Blocks, Paragraphs, Lines, Words, Characters
    // - Export Images, Coordinates, Fonts, Statistics
}
using IronOcr;
using System.Drawing; // Add assembly reference

// Initialize the OCR engine
var Ocr = new IronTesseract();
Ocr.Language = OcrLanguage.Hebrew;
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm; // Set engine mode
Ocr.Configuration.ReadBarCodes = true; // Enable barcode reading

// Load the image input for OCR
using (var Input = new OcrInput(@"images\sample.tiff"))
{
    // Perform OCR and get the result object
    OcrResult Result = Ocr.Read(Input);

    // Access detailed OCR results
    var Pages = Result.Pages; // Get pages from the result
    var Words = Pages[0].Words; // Access the words from the first page
    var Barcodes = Result.Barcodes; // Access scanned barcodes

    // Discover more in the detailed API:
    // - Pages, Blocks, Paragraphs, Lines, Words, Characters
    // - Export Images, Coordinates, Fonts, Statistics
}
Imports IronOcr
Imports System.Drawing ' Add assembly reference

' Initialize the OCR engine
Private Ocr = New IronTesseract()
Ocr.Language = OcrLanguage.Hebrew
Ocr.Configuration.EngineMode = TesseractEngineMode.TesseractAndLstm ' Set engine mode
Ocr.Configuration.ReadBarCodes = True ' Enable barcode reading

' Load the image input for OCR
Using Input = New OcrInput("images\sample.tiff")
	' Perform OCR and get the result object
	Dim Result As OcrResult = Ocr.Read(Input)

	' Access detailed OCR results
	Dim Pages = Result.Pages ' Get pages from the result
	Dim Words = Pages(0).Words ' Access the words from the first page
	Dim Barcodes = Result.Barcodes ' Access scanned barcodes

	' Discover more in the detailed API:
	' - Pages, Blocks, Paragraphs, Lines, Words, Characters
	' - Export Images, Coordinates, Fonts, Statistics
End Using
$vbLabelText   $csharpLabel

ביצועים

IronOCR עובד מהקופסה ללא צורך בכוונון ביצועים או בשינוי כבד של תמונות קלט.

המהירות בוערת: IronOcr.2020 + מהיר פי 10 ועושה יותר מ -250% פחות שגיאות בהשוואה לבניות קודמות.

למד עוד

למידע נוסף על OCR ב- C#, VB, F# או כל שפת .NET אחרת, קרא את המדריכים הקהילתיים שלנו, אשר נותנים דוגמאות בעולם האמיתי כיצד ניתן להשתמש ב- OCR של Iron ועשויים להראות את הניואנסים כיצד להפיק את המיטב הספרייה הזו.

יש גם הפניה מלאה לאובייקטים עבור מפתחי .NET .