與其他組件的比較 IronOCR 和 Dynamsoft OCR 之間的比較 Kannapat Udonpant 更新:8月 20, 2025 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 光學字元辨識(OCR)是一種資料輸入過程,涉及對手寫和印刷文字的識別和數位化。 它是一種電腦技術,利用影像分析將印刷文字的數位照片轉換為其他程式(如文字處理器)可以使用的字母和數字。 文字被轉換為字元代碼,以便在電腦上進行搜尋和修改。 過去,所有文件都是紙本的;未來,所有文件可能都是數位化的;而現在,一切都處於變化之中。 在這種過渡狀態下,紙本文件和數位文件並存——因此,像 OCR 這樣的技術對於來回轉換至關重要。 文件恢復、資料輸入和輔助功能只是 OCR 的幾個應用領域。 OCR 應用主要來自掃描的文檔,但偶爾也會使用照片。 OCR 是一項非常寶貴的省時技術,因為重新輸入材料往往是唯一的其他選擇。 以下是一些OCR技術的應用範例: 可從掃描文件(包括傳真)中復原可編輯文字檔案。 利用書籍掃描件建立可搜尋和可編輯的電子書。 使用螢幕截圖搜尋和更改文字。 文字轉語音技巧用於為視障人士朗讀書籍。 雖然這些只是 OCR 的幾個應用領域,但它們證明了該技術在各行業的廣泛應用。 幾乎所有公司的員工每天都會大量依賴文檔,因此業務用途是 OCR 系統開發的關鍵考慮因素。 本文將對兩款功能最強大的OCR閱讀器進行比較: IronOCR Dynamsoft OCR IronOCR 和 Dynamsoft OCR 是兩個 .NET OCR 函式庫,支援掃描影像的轉換和 PDF 文件的 OCR 處理。 只需幾行程式碼,即可將圖像轉換為可搜尋的文字。 您也可以檢索單字、字母和段落。 IronOCR-其卓越特性 IronOCR 具有獨特的功能,可偵測、讀取和解釋未經精確掃描的圖片和 PDF 文件中的文字。 IronOCR 提供了一種從文件和照片中提取文字的最簡單方法,即使它並不總是最快的,因為它會自動銳化和校正低品質掃描件,減少傾斜、失真、背景噪音和透視問題,同時還能提高解析度和對比度。 IronOCR 允許開發人員向其發送單頁或多頁掃描圖像,它將返回所有文字、條碼和二維碼資訊。 OCR 庫中的一組類別為基於 Web 的應用程式、桌面應用程式或控制台應用程式新增了 OCR 功能。 Tesseract OCR C# 以及 net apps 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 桌面應用程式。 您可以使用基本的 OCR API 輕鬆編寫程式碼,將 PDF 或照片中的無用文字轉換為數位文本,以便進行編輯、搜尋、存檔等操作。 掃描器可透過以下方式取得掃描器和其他符合 TWAIN 標準的裝置的影像: 支援本機、緩衝記憶體和磁碟檔案映像傳輸機制。 使用自動送稿器,可以進行大量掃描(ADF)。 TWAIN 屬性可用於修改常見設備功能。 IfAutoFeed、IfAutoScan、解析度、位元深度、亮度、對比度、單位、雙面列印等功能皆可變更。 支援偵測空白頁。 允許您變更和儲存掃描器設定檔。 從符合 UVC 和 WIA 標準的網路攝影機擷取影像: 從選定的網路攝影機拍攝照片的同時,顯示即時視訊串流。 自訂相機設定:亮度、對比、色調、飽和度、銳利度、伽瑪、白平衡、背光補償、增益、啟用色彩、變焦、對焦、曝光、光圈、平移、傾斜、滾動。 穩健的圖像載入/查看 可以載入 BMP、JPEG、PNG、TIFF 和多頁 TIFF 格式的圖片。 支援照片的放大和縮小功能。 可從本機磁碟機、FTP 伺服器、HTTP 伺服器或資料庫擷取映像。 使用最全面的 .NET 影像組件集之一,對 BMP、JPEG、PNG 和 TIFF 影像進行解碼 儲存並上傳/下載 允許您透過檔案流讀取和寫入照片。 支援將拍攝的照片儲存為 BMP、JPEG、PNG、TIFF 或多頁 TIFF 格式至本機磁碟機、Web 伺服器或資料庫。 支援 RLE、G3/G4、LZW、PackBits 和 TIFF 壓縮格式。 支援HTTPS上傳和下載。 最全面的 .NET 影像組件集之一支援 BMP、JPEG、PNG 和 TIFF 影像編碼。 允許您將新獲得的照片附加到現有的 TIFF 檔案中。 在 ASP.NET 中讀取掃描 PDF 或其他影像中的文字(光學字元辨識) 在當今快節奏的社會中,客戶希望工作能快速完成。 常有客戶聯絡我們,告知有緊急專案需要處理。 如果專案涉及掃描包含圖像的紙張,我們的技術可以簡單地識別圖像內容並將其轉換為文字。 光學字元辨識 (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 因此,以下段落的內容百分之百準確: IronOCR 簡單範例 在這個簡單的範例中,我們將測試我們的 C# OCR 庫從 PNG 圖像中讀取文字的準確性。 圖像。 這是一個非常基本的測試,但隨著教學的進行,內容會變得越來越複雜。 敏捷的棕色狐狸跳過了懶惰的狗 雖然表面上看起來很簡單,但實際上背後卻有複雜的運作:掃描影像的對齊、品質和分辨率,查看其屬性,優化 OCR 引擎,最後像人一樣閱讀文字。 OCR 對機器來說是一項艱鉅的任務,其讀取速度可能與人類相當。 換句話說,OCR 不是一個快速的過程。 但就此而言,它完全正確。 在大多數實際場景中,開發人員都希望他們的專案運行速度盡可能快。 在這種情況下,我們建議您改用 IronOCR 插件命名空間中的 OcrInput 和 IronTesseract 類別。 您可以使用 OcrInput 設定 OCR 作業的特定功能,例如: JPEG、TIFF、GIF、BMP 和 PNG 只是幾種可以使用的影像格式。 匯入整個 PDF 文件或部分匯入 PDF 文檔 增強影像的對比度、解析度和尺寸 旋轉、掃描雜訊、數位雜訊、傾斜和負像校正 鐵四維超立方體 從數百種預設語言和方言中進行選擇 立即使用 Tesseract 5、4 或 3 的 OCR 引擎 如果要查看螢幕截圖、程式碼片段或整個文檔,請指定文檔類型。 識別條碼 OCR 結果可以處理成可搜尋的 PDF、HoCR HTML、DOM 和字串。 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% 的準確率使用它。 如您所見,從掃描圖像(例如 TIFF)中讀取文字(以及,如果需要的話,條碼)非常容易。 這項OCR識別工作的準確率是100%。 接下來,我們將嘗試對同一頁進行品質低得多的掃描,採用低 DPI,並伴隨大量的失真和數位雜訊,以及對原紙的損壞。 與其他 OCR 函式庫(如 Tesseract)相比,IronOCR 的優勢就在於此。我們會發現,其他 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 在 JavaScript 中進行 TWAIN 掃描和客戶端 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 Professional 模組進行用戶端 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來指定要從文件中讀取的區域,從而提高速度和準確性。 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 時,也支援內容區域(OCR 裁切)。 使用 Dynamsoft OCR 讀取裁切區域 首先,啟動 Visual Studio 並建立一個新的 C# Windows 窗體應用程序,或開啟一個現有的應用程式。 我們需要包含DynamicDotNetTWAIN.dll 、 DynamicOCR.dll和對應的語言套件。 導覽至"工具"->"選擇工具箱項目",然後前往".NET Framework 元件"選項卡,點擊"瀏覽"按鈕,找到DynamicDotNetTWAIN.dll 。 在解決方案資源管理器中右鍵單擊專案文件,然後選擇"新增"->"現有項目..." 然後從 OCR 資源目錄中新增必要的項目。 這是點擊"載入圖片"按鈕的程式碼: 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 應用程式介面如下: 影像效能調優 輸入影像的品質是決定OCR任務速度的最關鍵因素。 背景噪音越低,dpi越高(理想值約200 dpi),OCR輸出速度越快,準確度越高。 Dynamsoft OCR 的影像處理技術 我們需要在各種情況下使用 OCR,例如用手機掃描信用卡號碼或從紙本文件中提取文字。 Dynamsoft Label Recognition (DLR) 和 Dynamic Web TWAIN (DWT) 都包含 OCR 功能。 雖然它們通常都能做得很好,但我們可以透過使用各種影像處理技術來改善結果。 提亮/去除陰影 光線不足可能會影響OCR辨識結果。 為了改善效果,我們可以美白照片或消除影像中的陰影。 Invert 由於 OCR 引擎通常是用深色文字進行訓練的,因此淺色文字可能更難發現和識別。 如果將它的顏色反轉,就更容易辨識了。 要反轉,我們可以使用 DLR 中的GrayscaleTransformationModes參數。 以下是JSON設定: "GrayscaleTransformationModes": [ { "Mode": "DLR_GTM_INVERTED" } ] DLR.net 的讀取結果: Rescale 如果字母高度太低,OCR引擎可能無法產生良好的辨識結果。 一般來說,影像的DPI至少應為300。 DLR 1.1 中有一個ScaleUpModes參數,可以放大字母。 當然,我們也可以自行調整圖片大小。 直接讀取影像會得到錯誤的結果: 將影像放大2倍後,結果正確: Deskew 文字略有變形是可以接受的。 但是,如果偏差過大,結果將受到不利影響。 為了改善效果,我們需要裁剪影像。 為了實現這一點,我們可以使用 OpenCV 和 Python 中的霍夫線變換。 以下是用於校正上圖傾斜的程式碼: 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 的定價從每年 1,249 美元起。 IronOCR 許可和定價 作為開發人員,我們都希望以盡可能少的資金和資源完成我們的專案——預算至關重要。 查看圖表,確定哪種許可證最符合您的需求和預算。 IronOCR 提供可自訂數量的開發人員、專案和地點的許可證,讓您能夠滿足專案的需求,同時只需為所需的覆蓋範圍付費。 IronOCR 許可證金鑰可讓您發布無浮水印產品。 許可證起價為$799 ,包含一年的支援和升級服務。 您也可以使用試用許可證金鑰免費試用 IronOCR。 結論 IronOCR for C# 可在 Mac、Windows、Linux、Azure OCR 和 Docker 上使用 Tesseract OCR。 需要 .NET Framework 4.0 或更高版本,.NET Standard 2.0+、.NET Core 2.0+、.NET 5、macOS 和 Linux 的 Mono 以及 macOS 的 Xamarin 都是跨平台開發的範例。 IronOCR 還使用最新的 Tesseract 5 引擎來讀取所有主要圖像和 PDF 格式中的文字、條碼和二維碼。 只需幾分鐘,這個程式庫就能為您的桌面、控制台或 Web 應用程式添加 OCR 功能! OCR 還可以讀取 PDF和多頁 TIFF 文件,並且可以將任何 OCR 掃描結果儲存為可搜尋的 PDF 文件或 XHTML 文件。 它的資料輸出選項包括純文字、條碼資料以及包含段落、行、單字和字元的 OCR 結果類別。 它支援 125 種語言,包括阿拉伯語、中文、英語、芬蘭語、法語、德語、希伯來語、義大利語、日語、韓語、葡萄牙語、俄語和西班牙語,但請記住,也可以產生客製化語言包。 Dynamic .NET TWAIN OCR 外掛程式是一個快速且可靠的 .NET 光學字元辨識元件,您可以在用 C# 或 VB .NET 編寫的 WinForms 和 WPF 應用程式中使用它。 您可以使用 Dynamic .NET TWAIN 的影像擷取模組掃描文件或從網路攝影機擷取照片,然後對影像進行 OCR,將影像中的文字轉換為文字、可搜尋的 PDF 檔案或字串。 除了英語外,還提供多種亞洲語言以及阿拉伯語。 IronOCR提供的許可比Dynamsoft OCR更好; IronOcr 的起價為$799 ,並提供免費一年的使用權;而 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 提供可客製化的授權,可根據開發人員、專案和地點的數量量身訂做,相較於其他一些函式庫,提供了更靈活、更具成本效益的選擇。 使用 OCR 技術時會面對哪些常見問題? OCR 技術的常見問題包括處理低解析度影像、扭曲和不同的文字字型。然而,像 IronOCR 之類的函式庫已內建解決這些問題的功能,可提升 OCR 的精確度。 Kannapat Udonpant 立即與工程團隊聊天 軟體工程師 在成為软件工程師之前,Kannapat 從日本北海道大學完成了環境資源博士學位。在追逐學位期间,Kannapat 還成為了生產工程系一部份——汽車机器人实验室的成員。2022 年,他利用他的 C# 技能加入 Iron Software 的工程團隊, 專注於 IronPDF。Kannapat 珍惜他的工作,因为他直接向编写大部分 IronPDF 使用的代码的开发者学习。除了同行学习,Kannapat 还喜欢在 Iron Software 工作的社交十环。当他不编写代码或文档时,Kannapat 通常在他的 PS5 上打游戏或重看《The Last of Us》。 相關文章 發表日期 12月 18, 2025 適用於 Windows 10 的最佳 OCR 軟體:完整比較指南 [2025] 瞭解適用於 Windows 10 的最佳 OCR 軟體。 閱讀更多 發表日期 12月 11, 2025 Tesseract OCR PDF to Text C#:開發人員與 IronOCR 的比較 了解如何使用 Tesseract OCR 和 IronOCR 將 PDF 輕鬆轉換為文字。 閱讀更多 發表日期 12月 11, 2025 使用 Tesseract C# vs IronOCR:在 .NET 中實現 OCR 的完整指南 學習如何有效率地使用 Tesseract C# 和 IronOCR 進行光學字元識別。 閱讀更多 IronOCR 和 Tesseract.NET 之間的比較IronOCR 和 Abbyy Finereader 之間...
發表日期 12月 11, 2025 Tesseract OCR PDF to Text C#:開發人員與 IronOCR 的比較 了解如何使用 Tesseract OCR 和 IronOCR 將 PDF 輕鬆轉換為文字。 閱讀更多
發表日期 12月 11, 2025 使用 Tesseract C# vs IronOCR:在 .NET 中實現 OCR 的完整指南 學習如何有效率地使用 Tesseract C# 和 IronOCR 進行光學字元識別。 閱讀更多