跳至頁尾內容
與其他組件的比較

IronOCR與Dynamsoft OCR的比較

光學文字識別,或OCR,是一種涉及識別及數位化文字(手寫和印刷)的資料輸入過程。 這是一種型別的電腦技術,使用影像分析將印刷文字的數位照片轉換成可供其他程式(如字處理器)使用的字母和數字。 文字被轉換為字元程式碼,這樣它就可以在電腦上搜尋和更改。

過去是所有文件都是實體的世界,未來可能是一個所有文件都是數位的社會,而當下則處於變動之中。 在這種過渡狀態中,實體和數位文件共存——因此像OCR這樣的技術對於來回轉換至關重要。

文件恢復、資料輸入和可存取性只是OCR的幾個應用範例。 大多數OCR應用來自掃描文件,雖然有時也使用照片。 OCR是一個有價值的時效節省方法,因為重新輸入材料通常是唯一的其他選擇。 以下是一些OCR的使用例子:

  • 可編輯的文字文件可以從掃描的文件中恢復,包括傳真。
  • 使用書籍掃描來建立可搜索和編輯的電子書。
  • 使用截圖照片以搜尋和更改文字。
  • 使用文字轉語音技術來為視障人士朗讀書籍。

雖然這只是OCR應用的一小部分,它們展示了技術在多個產業中的多功能性。 幾乎所有公司裡的員工日常都大力依賴文件,因此商業用途是OCR系統開發中的一個關鍵考量。

在這篇文章中,我們將比較兩個最強大的OCR讀者:

  • IronOCR
  • Dynamsoft OCR

IronOCR和Dynamsoft OCR是兩個.NET OCR程式庫,支持掃描圖像的轉換和PDF文件的OCR處理。 您可以僅用幾行程式碼將圖像轉為可搜尋的文字。 您還可以檢索到個別的單詞、字母和段落。

IronOCR —— 突出的特點

IronOCR提供了一種獨特的能力,能夠檢測、讀取和解釋未經精確掃描的圖片和PDF文件中的文字。 IronOCR提供了從文件和照片中提取文字的最簡單方法,即便不總是最快,因為它會自動銳化和校正劣質掃描,減少偏斜、失真、背景噪音和透視問題,同時提高解析度和對比度。

IronOCR允許開發者將單頁或多頁掃描的圖像發送給它,然後它將返回所有的文字、條碼和QR資訊。 OCR程式庫中的一組類為基於Web、桌面或控制台程式增加了OCR功能。 Tesseract OCR C#,以及JPG、PNG、TIFF、PDF、GIF和BMP的淨應用只是一些可以用作輸入的格式。

IronOCR的光學字元識別(OCR)引擎可以讀取使用多種常見字體、斜體、字重和下劃線製作的文字。 裁剪類可以讓OCR快速且準確地工作。 在處理多頁文件時,IronOCR的多執行緒引擎加快了OCR。

IronOCR功能

在管理Tesseract時,我們使用IronOCR,因為它在以下方面是獨特的:

  • 在純.NET中開箱即用
  • 不需要在您的機器上安裝Tesseract
  • 運行最新的引擎:Tesseract 5(以及Tesseract 4 & 3)
  • 可用於任何.NET項目:.NET Framework 4.5 +,.NET Standard 2 + 和.NET Core 2, 3 & .NET 5
  • 比傳統Tesseract有更高的準確性和速度
  • 支持Xamarin、Mono、Azure和Docker
  • 它使用NuGet包管理複雜的Tesseract字典系統
  • 支持PDF、多框TIFF和所有主要圖像格式而無需配置
  • 可以校正低品質和偏斜的掃描,以便從Tesseract獲得最佳結果。

Dynamsoft OCR —— 特點

Dynamsoft.NET OCR程式庫是一個.NET組件,提供快速可靠的光學字元識別。 它用於在C#或VB.NET建立.NET桌面應用。 您可以輕鬆建立程式碼來將PDF或照片中的無用文字轉換為數位文字,以便編輯、搜尋、存檔等,使用簡單的OCR API。

來自掃描儀和其他TWAIN相容裝置的圖像可以通過以下方式獲取:

  • 支持本地、快取記憶體和磁碟文件圖像傳輸機制。
  • 使用自動文件進紙器可進行批量掃描(ADF)。
  • TWAIN屬性可以用來修改常用裝置功能。
  • IfAutoFeed、IfAutoScan、解析度、位深、亮度、對比、單位、雙面及其他功能均可更改。
  • 支持空頁檢測。
  • 允許您更改和保存掃描儀配置檔。

從符合UVC和WIA的網路攝像頭抓取圖像:

  • 在從選擇的網路攝像頭捕獲照片時顯示直播影片。
  • 自訂相機的設定:亮度、對比度、色相、飽和度、銳度、伽瑪、白平衡、背光補償、增益、顏色使能、變焦、對焦、曝光、光圈、平移、傾斜、旋轉。

穩固的圖像載入/查看

  • BMP、JPEG、PNG、TIFF和多頁TIFF格式的圖像可以載入。
  • 支持照片的放大和縮小。
  • 圖像可以從本地磁碟、FTP伺服器、HTTP伺服器或資料庫中檢索。
  • BMP、JPEG、PNG和TIFF的圖像解碼使用其中最全面的一套.NET成像組件。

保存和上傳/下載

  • 允許您通過文件流讀取和寫入照片。
  • 支持將捕獲的照片保存為BMP、JPEG、PNG、TIFF或多頁TIFF到本地磁碟、Web伺服器或資料庫。
  • 支持RLE、G3/G4、LZW、PackBits和TIFF壓縮。
  • 支持HTTPS上傳和下載。
  • 其中最全面的一套.NET成像組件支持BMP、JPEG、PNG和TIFF圖像編碼。
  • 允許您將新獲得的照片附加到現有TIFF文件。

從掃描的PDF或其他圖片中讀取文字在ASP.NET中的(光學字元識別)

在當今快節奏的世界中,客戶希望工作能夠快速完成。 有緊急項目的客戶經常聯絡我們。 如果項目涉及掃描包含圖片的文件,我們的技術可以輕鬆地識別圖片內容並將其轉換為文字。 光學字元識別(OCR)節省了您公司的時間和金錢,並且還減少了資料輸入錯誤。

使用IronOCR

IronOCR利用IronOcr.IronTesseract類來執行其OCR轉換。

在這個基本範例中,我們使用IronOcr.IronTesseract類來讀取圖像中的文字,並自動返回它的結果為字串。

// PM> Install-Package IronOcr
using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        // Create a new instance of the IronTesseract class
        var ironOcr = new IronTesseract();

        // Read the text from the image
        var result = ironOcr.Read(@"img\Screenshot.png");

        // Output the text to the console
        Console.WriteLine(result.Text);
    }
}
// PM> Install-Package IronOcr
using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        // Create a new instance of the IronTesseract class
        var ironOcr = new IronTesseract();

        // Read the text from the image
        var result = ironOcr.Read(@"img\Screenshot.png");

        // Output the text to the console
        Console.WriteLine(result.Text);
    }
}
' PM> Install-Package IronOcr
Imports IronOcr

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create a new instance of the IronTesseract class
		Dim ironOcr = New IronTesseract()

		' Read the text from the image
		Dim result = ironOcr.Read("img\Screenshot.png")

		' Output the text to the console
		Console.WriteLine(result.Text)
	End Sub
End Class
$vbLabelText   $csharpLabel

因此,以下段落的準確性為100%:

IronOCR簡單示例

在此簡單示例中,我們將測試我們的C# OCR程式庫以從PNG讀取文本的準確性
圖片。 這是一個非常基本的測試,但隨著教學課程的發展,事情將變得更為複雜。

身手矯捷的棕色狐狸跳過懶狗

雖然在表面上看起來很簡單,但在表面下面有複雜的行為:掃描圖像的對齊、質量和解析度,查看其屬性,優化OCR引擎,最後以接近人類的方式讀取文字。

對於機器來說,OCR是一項困難的任務,讀取速度可能與人類相當。 換句話說,OCR不是一個快速的程式。 然而,在這種情況下,它絕對是正確的。

C# OCR調用應用的結果準確性

在大多數現實世界的場景中,開發者會希望他們的項目運行得盡可能快。 在這種情況下,我們建議您改用IronOCR附加命名空間的OcrInput和IronTesseract類。

借助OcrInput,您可以設置OCR任務的具體功能,如:

  • JPEG、TIFF、GIF、BMP和PNG只是可以使用的圖像格式的一部分
  • 完整或部分導入PDF文件
  • 提高圖像的對比度、解析度和大小
  • 旋轉、掃描噪音、數位噪音、傾斜和負像校正

IronTesseract

選擇數百種預打包的語言和方言

  • 即刻使用Tesseract 5、4或3 OCR引擎
  • 如果我們在查看截圖、片段或整個文件,指定文件型別
  • 認識條碼
  • 搜索PDF、Hocr HTML、DOM和字串都是OCR結果的選項
using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        // Use the OcrInput class to read from an image file
        using (var input = new OcrInput(@"img\Potter.tiff"))
        {
            // Perform the OCR operation
            var result = ocr.Read(input);

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

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        // Use the OcrInput class to read from an image file
        using (var input = new OcrInput(@"img\Potter.tiff"))
        {
            // Perform the OCR operation
            var result = ocr.Read(input);

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

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create an instance of IronTesseract
		Dim ocr = New IronTesseract()

		' Use the OcrInput class to read from an image file
		Using input = New OcrInput("img\Potter.tiff")
			' Perform the OCR operation
			Dim result = ocr.Read(input)

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

即便是中等品質的掃描,我們也能100%精確使用這個功能。

C# OCR從Tiff範例進行掃描

正如您所見,從掃描的圖像如TIFF中讀取文字(如果需要,也可以是條碼)相當簡單。 這次OCR任務的準確性為100%。

接下來,我們將嘗試對同一頁面進行的低質量掃描,DPI低且具有大量失真和數位噪音,原始文件還有損壞。

C# OCR低解析度掃描,帶數位噪音

這是IronOCR與其他OCR程式庫(如Tesseract)相比真正突出的地方,我們將發現其他的OCR項目避免討論在真實世界的掃描文件而不是不切實際地於數位方式建立的'完美'測試案例上使用OCR以實現100%OCR準確性。

using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        // Use the OcrInput class to read from a low-quality image file
        using (var input = new OcrInput(@"img\Potter.LowQuality.tiff"))
        {
            // Deskew the image to improve accuracy
            input.Deskew();

            // Perform the OCR operation
            var result = ocr.Read(input);

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

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        // Use the OcrInput class to read from a low-quality image file
        using (var input = new OcrInput(@"img\Potter.LowQuality.tiff"))
        {
            // Deskew the image to improve accuracy
            input.Deskew();

            // Perform the OCR operation
            var result = ocr.Read(input);

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

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create an instance of IronTesseract
		Dim ocr = New IronTesseract()

		' Use the OcrInput class to read from a low-quality image file
		Using input = New OcrInput("img\Potter.LowQuality.tiff")
			' Deskew the image to improve accuracy
			input.Deskew()

			' Perform the OCR operation
			Dim result = ocr.Read(input)

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

如果不加入 Input.Deskew() 來矯正圖像,我們會得到 52.5%的準確度。 這是不夠好的。

加入 Input.Deskew(),我們達到了99.8%的準確度,幾乎和高品質掃描的OCR一樣精確。

使用Dynamsoft OCR

我們將提供一些程式碼片段,供使用Dynamic Web TWAIN進行TWAIN掃描和在JavaScript中進行客戶端OCR。

掃描圖像

您可以通過Dynamic Web TWAIN的簡單API更改掃描設置並從TWAIN掃描儀中獲取照片。

function acquireImage() {
    // Select an available TWAIN scanner
    DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex);

    // Set scanning settings like pixel type, resolution, ADF, etc.
    DWObject.IfShowUI = false; // Do not show the user interface of the scanner
    DWObject.PixelType = 1; // Scan in grayscale
    DWObject.Resolution = 300;
    DWObject.IfFeederEnabled = true; // Scan from auto feeder
    DWObject.IfDuplexEnabled = false;
    DWObject.IfDisableSourceAfterAcquire = true;

    // Acquire images from scanners
    DWObject.AcquireImage();
}
function acquireImage() {
    // Select an available TWAIN scanner
    DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex);

    // Set scanning settings like pixel type, resolution, ADF, etc.
    DWObject.IfShowUI = false; // Do not show the user interface of the scanner
    DWObject.PixelType = 1; // Scan in grayscale
    DWObject.Resolution = 300;
    DWObject.IfFeederEnabled = true; // Scan from auto feeder
    DWObject.IfDuplexEnabled = false;
    DWObject.IfDisableSourceAfterAcquire = true;

    // Acquire images from scanners
    DWObject.AcquireImage();
}
JAVASCRIPT

下載OCR專業模組

要使用OCR專業模組進行客戶端OCR,您需要在頭部包含 ocrpro.js,還要下載OCR Pro DLL。

<script type="text/javascript" src="Resources/addon/dynamsoft.webtwain.addon.ocrpro.js"></script>
<script type="text/javascript" src="Resources/addon/dynamsoft.webtwain.addon.ocrpro.js"></script>
HTML

對.js文件進行編輯:

// Define base path
var CurrentPathName = unescape(location.pathname);
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);

// Download the OCR Pro add-on
DWObject.Addon.OCRPro.Download(CurrentPath + "Resources/addon/OCRPro.zip", OnSuccess, OnFailure);
// Define base path
var CurrentPathName = unescape(location.pathname);
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);

// Download the OCR Pro add-on
DWObject.Addon.OCRPro.Download(CurrentPath + "Resources/addon/OCRPro.zip", OnSuccess, OnFailure);
JAVASCRIPT

使用OCR識別文字

使用JS OCR識別API從掃描的圖像中提取文字就像插入下面的程式碼一樣簡單。

// Recognize text from the image at index 0
DWObject.Addon.OCRPro.Recognize(0, GetOCRProInfo, GetErrorInfo); // 0 is the index of the image
// Recognize text from the image at index 0
DWObject.Addon.OCRPro.Recognize(0, GetOCRProInfo, GetErrorInfo); // 0 is the index of the image
JAVASCRIPT

讀取圖片裁剪區域

這兩套軟體都提供了對裁剪圖像進行OCR的方案。

使用IronOCR讀取裁剪區域

Iron的Tesseract OCR分支擅長於讀取圖片的特定區域,如以下程式碼範例所示。

我們使用System.Drawing.Rectangle來描述需要讀取的圖像的確切區域(以像素表示)。

當處理一個標準化的表格並且只有部分內容會在不同案例中發生變化時,這會非常便利。

掃描頁面的一部分: 我們使用 System.Drawing.Rectangle來指定要從文件中讀取的區域,提高速度和準確性。

C# OCR從Tiff範例進行掃描
C# OCR從Tiff範例進行掃描
using IronOcr;
using System.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        using (var input = new OcrInput())
        {
            // Define content area of interest
            var contentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };

            // Add the specific region to the input
            input.AddImage("img/ComSci.png", contentArea);

            // Perform OCR operation
            var result = ocr.Read(input);

            // Output recognized text to console
            Console.WriteLine(result.Text);
        }
    }
}
using IronOcr;
using System.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // Create an instance of IronTesseract
        var ocr = new IronTesseract();

        using (var input = new OcrInput())
        {
            // Define content area of interest
            var contentArea = new Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };

            // Add the specific region to the input
            input.AddImage("img/ComSci.png", contentArea);

            // Perform OCR operation
            var result = ocr.Read(input);

            // Output recognized text to console
            Console.WriteLine(result.Text);
        }
    }
}
Imports IronOcr
Imports System.Drawing

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		' Create an instance of IronTesseract
		Dim ocr = New IronTesseract()

		Using input = New OcrInput()
			' Define content area of interest
			Dim contentArea = New Rectangle() With {
				.X = 215,
				.Y = 1250,
				.Height = 280,
				.Width = 1335
			}

			' Add the specific region to the input
			input.AddImage("img/ComSci.png", contentArea)

			' Perform OCR operation
			Dim result = ocr.Read(input)

			' Output recognized text to console
			Console.WriteLine(result.Text)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

這提升了41%的速度,同時也能讓我們有更多的具體。 這對於.NET OCR應用涉及的相似和一致的文件,包括發票、收據、支票、表格、費用申請等非常寶貴。

在讀取PDF文件時,也支持ContentAreas(OCR裁剪)。

使用Dynamsoft OCR讀取裁剪區域

首先,啟動Visual Studio並建立一個新的C# Windows窗體應用,或者打開一個現有的。 我們將需要包括DynamicOCR.dll和相應的語言包。

1.導航到工具->選擇工具箱項,然後到.NET Framework組件選項卡,點擊瀏覽按鈕,然後定位到DynamicDotNetTWAIN.dll

2.在解決方案資源管理器中右擊工程文件,然後選擇新增->現有項目... 然後從OCR資源目錄中新增必要的項目。

這是單擊LoadImage按鈕的程式碼:

private void button1_Click(object sender, EventArgs e) 
{
    OpenFileDialog filedlg = new OpenFileDialog(); 
    if (filedlg.ShowDialog() == DialogResult.OK) 
    { 
        dynamicDotNetTwain1.LoadImage(filedlg.FileName);
        // Choose an image from your local disk and load it into Dynamic .NET TWAIN
    } 
}

private void dynamicDotNetTwain1_OnImageAreaSelected(short sImageIndex, int left, int top, int right, int bottom) 
{
    dynamicDotNetTwain1.OCRTessDataPath = "../../"; 
    dynamicDotNetTwain1.OCRLanguage = "eng";
    OcrResultFormat ocrResultFormat = Dynamsoft.DotNet.TWAIN.OCR.ResultFormat.Text;

    byte [] sbytes = dynamicDotNetTwain1.OCR(dynamicDotNetTwain1.CurrentImageIndexInBuffer, left, top, right, bottom);
    // OCR the selected area of the image

    if (sbytes != null) 
    { 
        SaveFileDialog filedlg = new SaveFileDialog(); 
        filedlg.Filter = "Text File(*.txt)| *.txt"; 
        if (filedlg.ShowDialog() == DialogResult.OK) 
        {
            FileStream fs = File.OpenWrite(filedlg.FileName); 
            fs.Write(sbytes, 0, sbytes.Length);
            // Save the OCR result as a text file
            fs.Close(); 
        }
        MessageBox.Show("OCR successful");
    } 
    else 
    {
        MessageBox.Show(dynamicDotNetTwain1.ErrorString); 
    }
}
private void button1_Click(object sender, EventArgs e) 
{
    OpenFileDialog filedlg = new OpenFileDialog(); 
    if (filedlg.ShowDialog() == DialogResult.OK) 
    { 
        dynamicDotNetTwain1.LoadImage(filedlg.FileName);
        // Choose an image from your local disk and load it into Dynamic .NET TWAIN
    } 
}

private void dynamicDotNetTwain1_OnImageAreaSelected(short sImageIndex, int left, int top, int right, int bottom) 
{
    dynamicDotNetTwain1.OCRTessDataPath = "../../"; 
    dynamicDotNetTwain1.OCRLanguage = "eng";
    OcrResultFormat ocrResultFormat = Dynamsoft.DotNet.TWAIN.OCR.ResultFormat.Text;

    byte [] sbytes = dynamicDotNetTwain1.OCR(dynamicDotNetTwain1.CurrentImageIndexInBuffer, left, top, right, bottom);
    // OCR the selected area of the image

    if (sbytes != null) 
    { 
        SaveFileDialog filedlg = new SaveFileDialog(); 
        filedlg.Filter = "Text File(*.txt)| *.txt"; 
        if (filedlg.ShowDialog() == DialogResult.OK) 
        {
            FileStream fs = File.OpenWrite(filedlg.FileName); 
            fs.Write(sbytes, 0, sbytes.Length);
            // Save the OCR result as a text file
            fs.Close(); 
        }
        MessageBox.Show("OCR successful");
    } 
    else 
    {
        MessageBox.Show(dynamicDotNetTwain1.ErrorString); 
    }
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
	Dim filedlg As New OpenFileDialog()
	If filedlg.ShowDialog() = DialogResult.OK Then
		dynamicDotNetTwain1.LoadImage(filedlg.FileName)
		' Choose an image from your local disk and load it into Dynamic .NET TWAIN
	End If
End Sub

Private Sub dynamicDotNetTwain1_OnImageAreaSelected(ByVal sImageIndex As Short, ByVal left As Integer, ByVal top As Integer, ByVal right As Integer, ByVal bottom As Integer)
	dynamicDotNetTwain1.OCRTessDataPath = "../../"
	dynamicDotNetTwain1.OCRLanguage = "eng"
	Dim ocrResultFormat As OcrResultFormat = Dynamsoft.DotNet.TWAIN.OCR.ResultFormat.Text

	Dim sbytes() As Byte = dynamicDotNetTwain1.OCR(dynamicDotNetTwain1.CurrentImageIndexInBuffer, left, top, right, bottom)
	' OCR the selected area of the image

	If sbytes IsNot Nothing Then
		Dim filedlg As New SaveFileDialog()
		filedlg.Filter = "Text File(*.txt)| *.txt"
		If filedlg.ShowDialog() = DialogResult.OK Then
			Dim fs As FileStream = File.OpenWrite(filedlg.FileName)
			fs.Write(sbytes, 0, sbytes.Length)
			' Save the OCR result as a text file
			fs.Close()
		End If
		MessageBox.Show("OCR successful")
	Else
		MessageBox.Show(dynamicDotNetTwain1.ErrorString)
	End If
End Sub
$vbLabelText   $csharpLabel

這是應用程式的外觀:

使用Dynamic .NET TWAIN OCR SDK的區域OCR演示應用

圖像性能調整

輸入圖像的質量是OCR任務速度的最關鍵決定因素。 背景噪音越小,DPI越高,目標值約為200DPI,OCR輸出的速度和準確性就越高。

Dynamsoft OCR的圖像處理技術

我們需要在多種情況下使用OCR,如使用手機掃描信用卡號,或從紙質文件中提取文字。 OCR能力包括在Dynamsoft Label Recognition(DLR)和Dynamic Web TWAIN(DWT)中。

雖然它們一般都能很好地完成工作,但我們可以通過使用各種圖像處理技術來提高結果。

亮化/去除陰影

光線不足可能會影響OCR結果。 為了改善結果,我們可以增白照片或消除照片中的陰影。

反轉

因為OCR引擎通常是針對深色文字訓練的,淺色文字可能較難發現和識別。

淺色文字

如果我們反轉其顏色,將更容易識別

淺色文字反轉

為了進行反轉,我們可以在DLR中使用GrayscaleTransformationModes參數。

以下是JSON設置:

"GrayscaleTransformationModes": [
    {
        "Mode": "DLR_GTM_INVERTED"
    }
]

DLR .NET的讀取結果:

淺色文字結果

重新縮放

如果字母高度太低,OCR引擎可能不會產生良好的結果。 一般來說,圖像應該有至少300的DPI。

DLR 1.1中有一個ScaleUpModes參數,允許您放大字母。 當然,我們可以自行調整圖像的大小。

直接讀取圖像會得到錯誤的結果:

1x圖像

將圖像放大為x2後,結果正確:

2x圖像

去扭曲

如果文字只是有點變形,這是可以的。 然而,如果過度傾斜,結果將被不利地改變。 為了改善結果,我們需要裁剪圖像。

要完成這個,我們可以使用OpenCV和Python中的Hough Line Transform。

這是上面去扭曲圖像的程式碼:

import cv2
import numpy as np
import math
from PIL import Image

def deskew():
    src = cv2.imread("neg.jpg", cv2.IMREAD_COLOR)
    gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    kernel = np.ones((5,5), np.uint8)
    erode_img = cv2.erode(gray, kernel)
    eroDil = cv2.dilate(erode_img, kernel)
    show_and_wait_key("eroDil", eroDil)

    canny = cv2.Canny(eroDil, 50, 150)
    show_and_wait_key("canny", canny)

    lines = cv2.HoughLinesP(canny, 0.8, np.pi / 180, 90, minLineLength=100, maxLineGap=10)
    drawing = np.zeros(src.shape[:], dtype=np.uint8)

    maxY = 0
    degree_of_bottomline = 0
    index = 0
    for line in lines:
        x1, y1, x2, y2 = line[0]
        cv2.line(drawing, (x1, y1), (x2, y2), (0, 255, 0), 1, lineType=cv2.LINE_AA)
        k = float(y1-y2)/(x1-x2)
        degree = np.degrees(math.atan(k))
        if index == 0:
            maxY = y1
            degree_of_bottomline = degree
        else:        
            if y1 > maxY:
                maxY = y1
                degree_of_bottomline = degree
        index += 1
    show_and_wait_key("houghP", drawing)

    img = 圖片。fromarray(src)
    rotate_img = img.rotate(degree_of_bottomline)
    rotate_img_cv = np.array(rotate_img)
    cv2.imshow("rotateImg", rotate_img_cv)
    cv2.imwrite("deskewed.jpg", rotate_img_cv)
    cv2.waitKey()

def show_and_wait_key(win_name, img):
    cv2.imshow(win_name, img)
    cv2.waitKey()

if __name__ == "__main__":
    deskew()
import cv2
import numpy as np
import math
from PIL import Image

def deskew():
    src = cv2.imread("neg.jpg", cv2.IMREAD_COLOR)
    gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
    kernel = np.ones((5,5), np.uint8)
    erode_img = cv2.erode(gray, kernel)
    eroDil = cv2.dilate(erode_img, kernel)
    show_and_wait_key("eroDil", eroDil)

    canny = cv2.Canny(eroDil, 50, 150)
    show_and_wait_key("canny", canny)

    lines = cv2.HoughLinesP(canny, 0.8, np.pi / 180, 90, minLineLength=100, maxLineGap=10)
    drawing = np.zeros(src.shape[:], dtype=np.uint8)

    maxY = 0
    degree_of_bottomline = 0
    index = 0
    for line in lines:
        x1, y1, x2, y2 = line[0]
        cv2.line(drawing, (x1, y1), (x2, y2), (0, 255, 0), 1, lineType=cv2.LINE_AA)
        k = float(y1-y2)/(x1-x2)
        degree = np.degrees(math.atan(k))
        if index == 0:
            maxY = y1
            degree_of_bottomline = degree
        else:        
            if y1 > maxY:
                maxY = y1
                degree_of_bottomline = degree
        index += 1
    show_and_wait_key("houghP", drawing)

    img = 圖片。fromarray(src)
    rotate_img = img.rotate(degree_of_bottomline)
    rotate_img_cv = np.array(rotate_img)
    cv2.imshow("rotateImg", rotate_img_cv)
    cv2.imwrite("deskewed.jpg", rotate_img_cv)
    cv2.waitKey()

def show_and_wait_key(win_name, img):
    cv2.imshow(win_name, img)
    cv2.waitKey()

if __name__ == "__main__":
    deskew()
PYTHON

檢測到的線:

檢測到的線

已去扭曲:

去扭曲後的圖像

IronOCR的圖像處理技術

這裡輸入圖像的質量不重要,因為IronOCR擅長修復有缺陷的文件(雖然這很耗時,會使OCR作業使用更多的CPU週期)。

選擇數字噪音較少的輸入圖像格式,如TIFF或PNG,還可以比有損圖像格式(如JPEG)帶來更快的結果。

以下列出的圖像過濾器可以顯著提高性能:

  • OcrInput.Rotate(double degrees) — 按指定的度數順時針旋轉圖像。 負整數用於逆時針旋轉。
  • OcrInput.Binarize() — 使每個像素不是黑色就是白色,中間值沒。 在文字到背景對比非常低的情況下,可能會提高OCR性能。
  • OcrInput.ToGrayScale() — 此圖像過濾器將每個像素轉換為一個灰階。 不太可能提高OCR的準確性,但可能增加速度。
  • OcrInput.Contrast() — 自動增加對比度。在低對比度掃描中,此過濾器經常提高OCR速度和準確性。
  • OcrInput.DeNoise() — 只有在預計存在噪音時才應用此過濾器。
  • OcrInput.Invert() — 反轉所有顏色。 例如,白色變成黑色:黑色變成白色。
  • OcrInput.Dilate() — 高階形態學。 膨脹是在圖像中對像邊緣新增像素的過程。 (Inverse of Erode)
  • OcrInput.Erode() — 一個高階形態學功能。 侵蝕是從對像邊緣移除像素的過程。 (Inverse of Dilate)
  • OcrInput.Deskew() — 旋轉圖像,使其垂直並且方向正確。由於Tesseract對偏斜掃描的容忍度可以低至5度,這對於OCR非常有用。
  • DeepCleanBackgroundNoise() — 去除大量背景噪音。如果知道文件中存在大量背景噪音,才使用此過濾器,因為它可能會降低清晰文件的OCR準確性,且相當耗費CPU。
  • OcrInput.EnhanceResolution — 改進低解析度照片的解析度。 由於OcrInput,此過濾器使用率很低。 OcrInput將自動偵測和解決低解析度。

我們可能會想使用IronTesseract來加速高質量掃描的OCR。 如果我們正在追求速度,我們可能從這裡開始,然後逐漸打開功能,直到達到正確的平衡。

using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        var ocr = new IronTesseract();

// Configuration for speed tuning
        ocr.Configuration.BlackListCharacters = "~`$#^*_}{][|\\";
        ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
        ocr.Configuration.EngineMode = TesseractEngineMode.LstmOnly;
        ocr.Language = OcrLanguage.EnglishFast;

        using (var input = new OcrInput(@"img\Potter.tiff"))
        {
            var result = ocr.Read(input);
            Console.WriteLine(result.Text);
        }
    }
}
using IronOcr;

class Program
{
    static void Main(string[] args)
    {
        var ocr = new IronTesseract();

// Configuration for speed tuning
        ocr.Configuration.BlackListCharacters = "~`$#^*_}{][|\\";
        ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
        ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
        ocr.Configuration.EngineMode = TesseractEngineMode.LstmOnly;
        ocr.Language = OcrLanguage.EnglishFast;

        using (var input = new OcrInput(@"img\Potter.tiff"))
        {
            var result = ocr.Read(input);
            Console.WriteLine(result.Text);
        }
    }
}
Imports IronOcr

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim ocr = New IronTesseract()

' Configuration for speed tuning
		ocr.Configuration.BlackListCharacters = "~`$#^*_}{][|\"
		ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto
		ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5
		ocr.Configuration.EngineMode = TesseractEngineMode.LstmOnly
		ocr.Language = OcrLanguage.EnglishFast

		Using input = New OcrInput("img\Potter.tiff")
			Dim result = ocr.Read(input)
			Console.WriteLine(result.Text)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

該結果與基線100%相比準確99.8%——但快35%。

授權和定價

Dynamsoft授權和定價

按年授權。 所有價格包含一年維護,包括免費的軟體升級和高級支援。

Dynamsoft提供兩種型別的授權:

每客戶端裝置授權

"一個客戶端裝置授權"為同源應用(同協定、同主機名、同端口)提供來自單一客戶端裝置使用軟體功能的存取。一個閒置的客戶端裝置是指未能在連續90天內存取任何軟體功能的裝置。 一個閒置的客戶端裝置的授權位將立即釋放並可由任何其他活躍的客戶端裝置使用。當您達到允許的最大授權位數時,Dynamsoft會為您提供額外10%的客戶端裝置配額以應急使用。 一旦額外的客戶端裝置配額已用完,沒有新增客戶端裝置可以存取和使用軟體,直到有可用的授權位。 請注意,超過客戶端裝置配額不會影響任何已經獲得授權的客戶端裝置。

每伺服器授權

要部署應用於單一伺服器,需要"一個伺服器授權"。 伺服器既指實體伺服器,也包括虛擬伺服器,包括但不限於生產伺服器、切換伺服器、開發伺服器(也用於測試)、質量保證伺服器、測試伺服器和階段伺服器,所有這些都需要授權。 連續整合伺服器(建置伺服器)或本地開發伺服器不需要額外授權。 每伺服器授權僅對於機房伺服器裝置有效,而不適用於雲端部署。

Dynamsoft OCR的定價每年起價為1249美元。

IronOCR授權和定價

作為開發者,我們都希望盡量節省資金和資源來完成項目——預算至關重要。 查看圖表以確定哪種授權最適合您的需求和預算。

IronOCR提供具有可自定義開發人數、專案數量和地域數量的授權,讓您在僅支付所需覆蓋範圍的同時滿足項目的需求。

IronOCR授權金鑰使您能夠在不帶水印的情況下發行產品。

授權從$999起,並包括一年的支援和升級。

您還可以使用試用授權金鑰免費試用IronOCR。

結論

Mac、Windows、Linux、Azure OCR和Docker上的Tesseract OCR均可通過IronOCR for C#獲得。 .NET Framework 4.0或以上的要求,.NET Standard 2.0+,.NET Core 2.0+,.NET 5,Mono for macOS和Linux,以及Xamarin for macOS都是跨平台開發的例子。 IronOCR也使用最新的Tesseract 5引擎從所有主要圖像和PDF格式中讀取文字、條碼和QR碼。 在幾分鐘內,這個程式庫能為您的桌面、控制台或Web應用增加OCR功能!OCR還可以讀取PDF和多頁TIFF,並且可以保存為可搜索的PDF文件或XHTML於任意OCR掃描中。 純文字、條碼資料和包含段落、行、單詞和字元的OCR結果類是其中的資料輸出選擇。 它有125種語言版本,包含阿拉伯語、中文、英語、芬蘭語、法語、德語、希伯來語、義大利語、日語、韓語、葡萄牙語、俄語和西班牙語,但請注意可以生成自定義語言包。

Dynamic .NET TWAIN OCR附加是一個快速可靠的.NET組件,用於光學字元識別,您可以在C#或VB .NET編寫的WinForms和WPF應用中使用。 您可以使用Dynamic .NET TWAIN的圖像捕捉模塊從網路攝像頭中掃描文件或捕捉照片,然後對圖像進行OCR將圖像中文字轉換為文字、可搜索PDF文件或字串。 除英文外,還提供多種亞洲語言以及阿拉伯語。

IronOCR的授權比Dynamsoft OCR更好; IronOCR起價$999,並提供一年免費,而Dynamsoft起價1249美元,並提供免費試用。 IronOCR也提供多使用者授權,而Dynamsoft則僅提供每使用者一個授權。

雖然兩套軟體都致力於提供OCR的最佳效果,包括條碼、圖像至文字和圖像到文字的閱讀,但IronOCR以即使在相當糟糕的圖像中仍能發揮優勢而脫穎而出。 它會自動啟用其先進的調整方法以提供最佳的OCR結果。 IronOCR還利用Tesseract以提供最佳結果,几乎無誤。

Iron Software還為其客戶和使用者提供獲取其整套軟體的選擇,只需兩次點擊。 這意味着,目前以Iron Software其中兩個元件的價格,您可以獲得所有五個元件以及不間斷的技術支持。

請注意Dynamsoft OCR是其各自所有者的註冊商標。 此站點與Dynamsoft OCR無關,也未得到其支持或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊用途,並反映撰寫時獲得的公開資訊。

常見問題

如何使用 C# 將文字圖像轉換為數位格式?

您可以在 C# 中使用 IronOCR 將文字圖像轉換為數位格式。IronOCR 提供的方法可以自動銳化並校正低品質掃描,使其成為將各種圖像格式轉換為文字的理想選擇。

IronOCR 在處理低品質掃描方面有何優勢?

IronOCR 自動增強低品質掃描,減少偏斜、失真和背景噪音,同時改善解析度和對比度,確保更高的文字識別準確度。

哪個 OCR 程式庫更適合跨平台應用?

IronOCR 適用於跨平台應用,因為它支持像 Xamarin 和 Azure 這樣的環境,為在不同平台上工作的開發者提供靈活性。

IronOCR 支持哪些圖像格式?

IronOCR 支持廣泛的圖像格式,讓它在不同的 OCR 應用中具有多樣性。它可以處理圖像和 PDF 文件,提供靈活的多種輸入來源處理。

OCR 技術可以幫助企業的文件管理嗎?

是的,OCR 技術可以通過將實體文件數位化,讓其可搜尋和編輯,有效幫助文件管理。這減少了手動資料輸入,最小化錯誤,並提高了可存取性。

Dynamsoft OCR 如何處理從裝置獲取圖像的問題?

Dynamsoft OCR 支持從符合 TWAIN 標準的裝置和網路攝影機獲取圖像,允許批量掃描及修改掃描儀屬性,以進行高效圖像處理。

IronOCR 與其他程式庫相比,定價選擇如何?

IronOCR 提供可定制的授權,可以根據開發者人數、專案和地點進行調整,與其他某些程式庫相比提供更靈活且具成本效益的選擇。

using OCR 技術時常見的問題有哪些?

OCR 技術常見問題包括處理低解析度圖像、失真和字體變化。然而,像 IronOCR 這樣的程式庫擁有內建功能來解決這些問題,提高 OCR 精確度。

Kannaopat Udonpant
軟體工程師
在成為軟體工程師之前,Kannapat在日本北海道大學完成了環境資源博士學位。在攻讀學位期間,Kannapat還成為車輛機器人實驗室的一員,該實驗室隸屬於生產工程系。在2022年,他憑藉C#技能加入了Iron Software的工程團隊,專注於IronPDF。Kannapat珍視他的工作,因為他能直接向撰寫大部分IronPDF程式碼的開發者學習。除了同儕學習,Kannapat還喜歡在Iron Software工作的社交方面。不寫程式碼或文件時,Kannapat通常在他的PS5上玩遊戲或重看The Last of Us。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話