Pierwsze kroki z OCR w C# i VB.NET
IronOCR to biblioteka oprogramowania w C# umożliwiająca programistom platformy .NET rozpoznawanie i odczytywanie tekstu z obrazów i dokumentów PDF. Jest to biblioteka OCR oparta wyłącznie na platformie .NET, wykorzystująca najbardziej zaawansowany silnik Tesseract znany na rynku.
Instalacja
Zainstaluj za pomocą menedżera pakietów NuGet
Zainstaluj IronOCR w Visual Studio lub w wierszu polecenia z Menedżerem Pakietów NuGet. W Visual Studio przejdź do konsoli przy użyciu:
- Narzędzia ->
- Menedżer Pakietów NuGet ->
- Konsola Menedżera Pakietów
Aby dowiedzieć się więcej na temat aktualizacji wersji i instalacji, zapoznaj się z IronOCR na NuGet.
Inne Pakiety NuGet IronOCR są dostępne dla różnych platform:
- Windows: https://www.nuget.org/packages/IronOcr
- Linux: https://www.nuget.org/packages/IronOcr.Linux
- MacOS: https://www.nuget.org/packages/IronOcr.MacOs
- MacOS (ARM): https://www.nuget.org/packages/IronOcr.MacOs.ARM
IronOcr.Extensions.AdvancedScan dla Linux i macOS
Ten pakiet jest przeznaczony dla użytkowników, którzy używają Linux i Mac i chcą zaawansowanych funkcji dla IronOCR.
- Linux: https://www.nuget.org/packages/IronOcr.Extensions.AdvancedScan.Linux
- MacOS: https://www.nuget.org/packages/IronOcr.Extensions.AdvancedScan.MacOs
Rozwiązywanie problemów
Z nową aktualizacją tego pakietu, IronOCR łączy zależności OpenCV w pakiecie, aby ułatwić proces, jeśli programiści, którzy aktualnie importują zależności OpenCV, otrzymują następujący błąd.
The type of namespace name `OpenCvSharp` could not be found(are you missing a using directive or an assembly reference)
Możesz bezpiecznie usunąć przestrzenie nazw OpenCV, a problem zostanie rozwiązany.
Pobierz IronOCR w formacie .ZIP
Możesz również pobrać IronOCR za pomocą pliku .ZIP. Kliknij, aby bezpośrednio pobrać plik DLL. Po pobraniu pliku .zip:
Instrukcje dla instalacji .NET Framework 4.0+:
-
Dołącz IronOcr.dll z folderu net40 do swojego projektu
-
A następnie dodaj odwołania do zestawów:
- System.Configuration
- System.Drawing
- System.Web
Instrukcje dla .NET Standard & .NET Core 2.0+, & .NET 5
-
Dołącz IronOcr.dll z folderu netstandard2.0 do swojego projektu
-
A następnie dodaj odwołanie do pakietu NuGet:
- System.Drawing.Common 4.7 lub nowszy
Pobierz Instalator IronOCR (tylko Windows)
Inną opcją jest pobranie naszego instalatora IronOCR, który zainstaluje wszystkie wymagane zasoby dla działania IronOCR od razu. Proszę pamiętać, że ta opcja jest przeznaczona tylko dla systemów Windows. Aby pobrać instalator, kliknij tutaj. Po pobraniu pliku .zip:
Instrukcje dla instalacji .NET Framework 4.0+:
-
Dołącz IronOcr.dll z folderu net40 do swojego projektu
-
A następnie dodaj odwołania do zestawów:
- System.Configuration
- System.Drawing
- System.Web
Instrukcje dla .NET Standard & .NET Core 2.0+, & .NET 5
-
Dołącz IronOcr.dll z folderu netstandard2.0 do swojego projektu
-
A następnie dodaj odwołanie do pakietu NuGet:
- System.Drawing.Common 4.7 lub nowszy
Dlaczego wybrać IronOCR?
IronOCR to łatwa w instalacji, kompletna i dobrze udokumentowana biblioteka oprogramowania .NET.
Wybierz IronOCR, aby uzyskać 99,8%+ dokładność OCR bez korzystania z zewnętrznych usług sieciowych, ciągłych opłat lub wysyłania poufnych dokumentów przez Internet.
Dlaczego programiści C# wybierają IronOCR zamiast zwykłego Tesseract:
- Zainstaluj jako pojedynczy DLL lub NuGet
- Zawiera silniki Tesseract 5, 4 i 3 od razu.
- Dokładność 99,8% znacznie przewyższa zwykły Tesseract.
- Niesamowita prędkość i wielowątkowość
- Kompatybilny z MVC, WebApp, Desktop, Console & Server Applications
- Brak plików .exe lub kodu C++ do pracy
- Pełne wsparcie dla OCR w PDF
- Wykonuj OCR na prawie każdym pliku graficznym lub PDF
- Pełne wsparcie dla .NET Core, Standard i Framework
- Wdrożenia na Windows, Mac, Linux, Azure, Docker, Lambda, AWS
- Odczyt kodów kreskowych i QR
- Eksportuj wyniki OCR jako XHTML
- Eksportuj OCR do przeszukiwalnych dokumentów PDF
- Wsparcie dla wielowątkowości
- 125 języków międzynarodowych, zarządzanych przez NuGet lub pliki OcrData
- Ekstrakcja obrazów, współrzędnych, statystyk i czcionek. Nie tylko tekst.
- Można go użyć do redystrybucji Tesseract OCR w aplikacjach komercyjnych i właścicielskich.
IronOCR wybija się przy pracy z obrazami rzeczywistymi i niedoskonałymi dokumentami, takimi jak zdjęcia, lub skany niskiej rozdzielczości zawierające szumy cyfrowe lub niedoskonałości.
Inne darmowe biblioteki OCR dla platformy .NET, takie jak inne .NET API Tesseract i usługi sieciowe, nie działają tak dobrze przy tych realnych przypadkach użycia.
OCR z Tesseract 5 - zacznij programować w C#
Przykład kodu poniżej pokazuje, jak łatwo jest odczytać tekst z obrazu używając C# lub VB .NET.
Jednoliniowiec
string Text = new IronTesseract().Read(@"img\Screenshot.png").Text;Dim Text As String = (New IronTesseract()).Read("img\Screenshot.png").TextDim Text As String = (New IronTesseract()).Read("img\Screenshot.png").TextKonfigurowalny Hello World
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Add multiple images
input.LoadImage("images/sample.jpeg");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Add multiple images
input.LoadImage("images/sample.jpeg");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Add multiple images
input.LoadImage("images/sample.jpeg")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Add multiple images
input.LoadImage("images/sample.jpeg")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)OCR PDF w C#
Tę samą metodę można podobnie wykorzystać do wydobywania tekstu z dowolnego dokumentu PDF.
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password: "password");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
// 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password: "password");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
// 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password:= "password")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
' 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' We can also select specific PDF page numbers to OCR
input.LoadPdf("example.pdf", Password:= "password")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
' 1 page for every page of the PDF
Console.WriteLine($"{result.Pages.Length} Pages")OCR dla wielostronicowych TIFF-ów
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageindices);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("multi-frame.tiff", pageindices);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("multi-frame.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Kody kreskowe i QR
Unikalną funkcją IronOCR jest możliwość odczytu kodów kreskowych i QR z dokumentów podczas skanowania w poszukiwaniu tekstu. Egzemplarze klasy OcrResult.OcrBarcode dostarczają programiście szczegółowych informacji o każdym zeskanowanym kodzie kreskowym.
using IronOcr;
IronTesseract ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
input.LoadImage("img/Barcode.png");
OcrResult Result = ocr.Read(input);
foreach (var Barcode in Result.Barcodes)
{
// type and location properties also exposed
Console.WriteLine(Barcode.Value);
}using IronOcr;
IronTesseract ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
input.LoadImage("img/Barcode.png");
OcrResult Result = ocr.Read(input);
foreach (var Barcode in Result.Barcodes)
{
// type and location properties also exposed
Console.WriteLine(Barcode.Value);
}Imports IronOcr
Private ocr As New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
input.LoadImage("img/Barcode.png")
Dim Result As OcrResult = ocr.Read(input)
For Each Barcode In Result.Barcodes
' type and location properties also exposed
Console.WriteLine(Barcode.Value)
Next Barcode
End UsingImports IronOcr
Private ocr As New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
input.LoadImage("img/Barcode.png")
Dim Result As OcrResult = ocr.Read(input)
For Each Barcode In Result.Barcodes
' type and location properties also exposed
Console.WriteLine(Barcode.Value)
Next Barcode
End UsingOCR na określonych obszarach obrazów
Wszystkie metody skanowania i odczytu IronOCR umożliwiają dokładne określenie, której części strony lub stron chcemy odczytać tekst. Jest to bardzo przydatne, gdy przeglądamy standardowe formularze, i może zaoszczędzić dużo czasu oraz poprawić wydajność.
Aby użyć obszarów przycięcia, musimy dodać referencję systemową do System.Drawing, aby móc użyć obiektu System.Drawing.Rectangle.
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Dimensions are in pixel
var contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
input.LoadImage("document.png", contentArea);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
// Dimensions are in pixel
var contentArea = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
input.LoadImage("document.png", contentArea);
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Dimensions are in pixel
Private contentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadImage("document.png", contentArea)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
' Dimensions are in pixel
Private contentArea = New System.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadImage("document.png", contentArea)
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)OCR dla skanów niskiej jakości
Klasa OcrInput w IronOCR może naprawić skany, które normalny Tesseract nie może odczytać.
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageindices);
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageindices);
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageindices)
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageindices)
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Eksportuj wyniki OCR jako przeszukiwalny PDF
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Quarterly Report";
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", pageindices);
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Quarterly Report";
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", pageindices);
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Quarterly Report"
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("image3.gif", pageindices)
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Quarterly Report"
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("image3.gif", pageindices)
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")Konwersja TIFF do przeszukiwalnego PDF
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageindices);
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageindices);
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageindices)
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageindices)
ocr.Read(input).SaveAsSearchablePdf("searchable.pdf")Eksportuj wyniki OCR jako HTML
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Html Title";
input.LoadImage("image1.jpeg");
OcrResult Result = ocr.Read(input);
Result.SaveAsHocrFile("results.html");using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.Title = "Html Title";
input.LoadImage("image1.jpeg");
OcrResult Result = ocr.Read(input);
Result.SaveAsHocrFile("results.html");Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Html Title"
input.LoadImage("image1.jpeg")
Dim Result As OcrResult = ocr.Read(input)
Result.SaveAsHocrFile("results.html")Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.Title = "Html Title"
input.LoadImage("image1.jpeg")
Dim Result As OcrResult = ocr.Read(input)
Result.SaveAsHocrFile("results.html")Filtry poprawy obrazu dla OCR
IronOCR zapewnia unikalne filtry do obiektów OcrInput w celu poprawy wydajności OCR.
Przykład kodu poprawy obrazu
using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.LoadImage("LowQuality.jpeg");
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);using IronOcr;
IronTesseract ocr = new IronTesseract();
using OcrInput input = new OcrInput();
input.LoadImage("LowQuality.jpeg");
// fixes digital noise and poor scanning
input.DeNoise();
// fixes rotation and perspective
input.Deskew();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.LoadImage("LowQuality.jpeg")
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Imports IronOcr
Private ocr As New IronTesseract()
Private OcrInput As using
input.LoadImage("LowQuality.jpeg")
' fixes digital noise and poor scanning
input.DeNoise()
' fixes rotation and perspective
input.Deskew()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)Lista filtrów obrazów OCR
Filtry wejściowe poprawiające wydajność OCR, które są wbudowane w IronOCR, obejmują:
OcrInput.Rotate(double degrees)- Obraca obrazy o określoną liczbę stopni zgodnie z ruchem wskazówek zegara. Dla obrotu przeciwnie do ruchu wskazówek zegara należy użyć liczb ujemnych.OcrInput.Binarize()- Ten filtr konwertuje każdy piksel na kolor czarny lub biały bez pośrednich odcieni, potencjalnie poprawiając wydajność OCR w obrazach o bardzo niskim kontraście.OcrInput.ToGrayScale()- Konwertuje każdy piksel na odcień szarości. To może nie poprawić dokładności, ale może poprawić prędkość.OcrInput.Contrast()- Automatycznie zwiększa kontrast, co często poprawia szybkość i dokładność w skanach o niskim kontraście.OcrInput.DeNoise()- Usuwa cyfrowy szum, zalecany tylko w przypadku przewidywanego wystąpienia szumu.OcrInput.Invert()- Odwraca wszelkie kolory (biały staje się czarny i vice versa).OcrInput.Dilate()- Zaawansowana morfologia, dodaje piksele do granic obiektów, przeciwny do Erode.OcrInput.Erode()- Zaawansowana morfologia, usuwa piksele z granic obiektów, przeciwny do Dilate.OcrInput.Deskew()- Obraca obraz, aby poprawnie go zorientować. Użyteczne, ponieważ tolerancja na skręcenie Tesseract jest ograniczona.OcrInput.EnhanceResolution- Poprawia rozdzielczość obrazów niskiej jakości. To ustawienie jest zazwyczaj używane do automatycznego zarządzania danymi wejściowymi o niskiej rozdzielczości (DPI).EnhanceResolutionwykrywa obrazy o niskiej rozdzielczości (poniżej 275 dpi), zwiększa ich skalę i wyostrza tekst, aby poprawić wyniki OCR. Chociaż jest to czasochłonne, często skraca to ogólny czas działania OCR.Language- Wspiera wybór z 22 międzynarodowych pakietów językowych.Strategy- Umożliwia wybór strategii pomiędzy szybkimi, mniej dokładnymi lub zaawansowanymi (z wykorzystaniem AI dla dokładności), w oparciu o statystyczną zależność słów.ColorSpace- Wybierz OCR w odcieniach szarości lub kolorze; Skala szarości jest zazwyczaj optymalna, choć w niektórych sytuacjach wymagających kontrastu lepszym rozwiązaniem może być kolor.DetectWhiteTextOnDarkBackgrounds- Dostosowuje do negatywnych obrazów, automatycznie wykrywając i odczytując biały tekst na ciemnym tle.InputImageType- Prowadzi bibliotekę OCR, określając, czy działa na pełnym dokumencie czy fragmencie.RotateAndStraighten- Umożliwia IronOCR prawidłowe przetwarzanie dokumentów, które są obrócone lub dotknięte zniekształceniami perspektywy.ReadBarcodes- Automatycznie odczytuje kody kreskowe i kody QR jednocześnie ze skanowaniem tekstu bez istotnego dodatkowego czasu.ColorDepth- Określa liczbę bitów na piksel dla głębi koloru w procesie OCR. Większa szczegółowość może podnieść jakość, ale też wydłużyć czas przetwarzania.
125 pakietów językowych
IronOCR obsługuje 125 międzynarodowych języków za pomocą pakietów językowych, które są dystrybuowane jako pliki DLL, dostępne do pobrania z tej strony lub z Menedżera Pakietów NuGet.
Języki obejmują między innymi niemiećki, francuski, angielski, chiński i japoński. Specjalistyczne pakiety językowe istnieją dla MRZ, czeków MICR, danych finansowych, tablic rejestracyjnych itp. Dodatkowo można używać niestandardowych plików Tesseract ".traineddata".
Przykład języka
using IronOcr;
// PM> Install IronOcr.Languages.Arabic
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
OcrResult result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");using IronOcr;
// PM> Install IronOcr.Languages.Arabic
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames("img/arabic.gif", pageindices);
// Add image filters if needed
// In this case, even thought input is very low quality
// IronTesseract can read what conventional Tesseract cannot.
OcrResult result = ocr.Read(input);
// Console can't print Arabic on Windows easily.
// Let's save to disk instead.
result.SaveAsTextFile("arabic.txt");Imports IronOcr
' PM> Install IronOcr.Languages.Arabic
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result As OcrResult = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
End UsingImports IronOcr
' PM> Install IronOcr.Languages.Arabic
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img/arabic.gif", pageindices)
' Add image filters if needed
' In this case, even thought input is very low quality
' IronTesseract can read what conventional Tesseract cannot.
Dim result As OcrResult = ocr.Read(input)
' Console can't print Arabic on Windows easily.
' Let's save to disk instead.
result.SaveAsTextFile("arabic.txt")
End UsingPrzykład wielojęzyczny
Możliwe jest również stosowanie OCR w wielu językach jednocześnie. Może to poprawić rozpoznawanie angielskich metadanych i adresów URL w dokumentach Unicode.
using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
// We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English);
using OcrInput input = new OcrInput();
input.LoadPdf("multi-language.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsTextFile("results.txt");using IronOcr;
// PM> Install IronOcr.Languages.ChineseSimplified
IronTesseract ocr = new IronTesseract();
ocr.Language = OcrLanguage.ChineseSimplified;
// We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English);
using OcrInput input = new OcrInput();
input.LoadPdf("multi-language.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsTextFile("results.txt");Imports IronOcr
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
' We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English)
Using input As New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsTextFile("results.txt")
End UsingImports IronOcr
' PM> Install IronOcr.Languages.ChineseSimplified
Private ocr As New IronTesseract()
ocr.Language = OcrLanguage.ChineseSimplified
' We can add any number of languages
ocr.AddSecondaryLanguage(OcrLanguage.English)
Using input As New OcrInput()
input.LoadPdf("multi-language.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsTextFile("results.txt")
End UsingSzczegółowe wyniki OCR Obiekty
IronOCR zwraca obiekt wyniku OCR dla każdej operacji. Zazwyczaj programiści uzyskują dostęp do właściwości Text, aby otrzymać zeskanowany tekst. Jednak obiekt results zawiera znacznie bardziej szczegółowe informacje.
using IronOcr;
IronTesseract ocr = new IronTesseract();
// Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\sample.tiff", pageindices);
OcrResult result = ocr.Read(input);
var pages = result.Pages;
var words = pages[0].Words;
var barcodes = result.Barcodes;
// Explore here to find a massive, detailed API:
// - Pages, Blocks, Paraphaphs, Lines, Words, Chars
// - Image Export, Fonts Coordinates, Statistical Data, Tablesusing IronOcr;
IronTesseract ocr = new IronTesseract();
// Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = true;
using OcrInput input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\sample.tiff", pageindices);
OcrResult result = ocr.Read(input);
var pages = result.Pages;
var words = pages[0].Words;
var barcodes = result.Barcodes;
// Explore here to find a massive, detailed API:
// - Pages, Blocks, Paraphaphs, Lines, Words, Chars
// - Image Export, Fonts Coordinates, Statistical Data, TablesImports IronOcr
Private ocr As New IronTesseract()
' Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\sample.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Dim pages = result.Pages
Dim words = pages(0).Words
Dim barcodes = result.Barcodes
' Explore here to find a massive, detailed API:
' - Pages, Blocks, Paraphaphs, Lines, Words, Chars
' - Image Export, Fonts Coordinates, Statistical Data, Tables
End UsingImports IronOcr
Private ocr As New IronTesseract()
' Must be set to true to read barcode
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
Dim pageindices = New Integer() { 1, 2 }
input.LoadImageFrames("img\sample.tiff", pageindices)
Dim result As OcrResult = ocr.Read(input)
Dim pages = result.Pages
Dim words = pages(0).Words
Dim barcodes = result.Barcodes
' Explore here to find a massive, detailed API:
' - Pages, Blocks, Paraphaphs, Lines, Words, Chars
' - Image Export, Fonts Coordinates, Statistical Data, Tables
End UsingWydajność
IronOCR działa od razu po uruchomieniu, bez konieczności dostosowywania wydajności lub modyfikacji obrazów.
Prędkość jest oszałamiająca: IronOCR.2020+ jest do 10 razy szybszy i popełnia o ponad 250% mniej błędów niż poprzednie wersje.
Dowiedz się więcej
Aby dowiedzieć się więcej o OCR w C#, VB, F# lub dowolnym innym języku .NET, prosimy przeszukać nasze samouczki społecznościowe, które dostarczają rzeczywistych przykładów użycia IronOCR i pokazują niuanse optymalizacji biblioteki.
Pełna dokumentacja API dla programistów .NET jest również dostępna.
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.