IronOCR 開始使用 Get Started with OCR in C# and VB.NET Curtis Chau 更新:2026年1月31日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronOCR是一個 C# 軟體庫,允許.NET平台軟體開發人員識別和讀取圖像和 PDF 文件中的文字。 這是一個純.NET OCR 函式庫,使用了目前已知最先進的 Tesseract 引擎。 安裝 使用NuGet套件管理器安裝 在 Visual Studio 中或使用NuGet套件管理器在命令列中安裝IronOCR 。 在 Visual Studio 中,使用下列命令導覽至控制台: 工具 -> NuGet套件管理器 -> 軟體套件管理器控制台 Install-Package IronOcr 請造訪NuGet查看IronOCR ,以了解更多關於版本更新和安裝的資訊。 還有其他適用於不同平台的IronOCR NuGet套件: 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 for Linux and macOS 此軟體包適用於使用 Linux 和 Mac 且希望使用IronOCR高級功能的使用者。 Linux : https: NuGet macOS : https: NuGet 故障排除 透過此次軟體包的更新, IronOCR將 OpenCV 依賴項合併到軟體包中,從而簡化了軟體包。如果目前匯入 OpenCV 相依性的開發人員遇到下列錯誤,則會出現此問題。 The type of namespace name `OpenCvSharp` could not be found(are you missing a using directive or an assembly reference) 您可以安全地移除 OpenCV 命名空間,問題即可解決。 下載IronOCR .ZIP 文件 您也可以選擇透過 .ZIP 檔案下載IronOCR 。 點擊即可直接下載 DLL 檔案。 下載完 .zip 檔案後: .NET Framework 4.0+ 安裝說明: 將 net40 資料夾中的IronOCR檔案包含到您的專案中 然後加入程式集引用到: 系統配置 系統繪圖 系統.Web 適用於.NET Standard 、 .NET Core 2.0+ 和.NET 5 的說明 將 netstandard2.0 資料夾中的IronOCR檔案包含到您的專案中 然後加入NuGet包引用: 系統繪圖.Common 4.7 或更高版本 下載IronOCR安裝程式(僅限 Windows 系統) 另一個選擇是下載我們的IronOCR安裝程序,它將安裝IronOCR開箱即用所需的所有資源。 請注意,此選項僅適用於 Windows 系統。 要下載安裝程序,請點擊這裡。 下載完 .zip 檔案後: .NET Framework 4.0+ 安裝說明: 將 net40 資料夾中的IronOCR檔案包含到您的專案中 然後加入程式集引用到: 系統配置 系統繪圖 系統.Web 適用於.NET Standard 、 .NET Core 2.0+ 和.NET 5 的說明 將 netstandard2.0 資料夾中的IronOCR檔案包含到您的專案中 然後加入NuGet包引用: 系統繪圖.Common 4.7 或更高版本 為什麼選擇IronOCR? IronOCR是一個易於安裝、功能齊全且文件完善的.NET軟體庫。 選擇IronOCR ,無需使用任何外部網路服務、無需支付持續費用或透過網路發送機密文件,即可實現99.8% 以上的 OCR 準確率。 為什麼 C# 開發人員選擇IronOCR而不是原生 Tesseract: 可以安裝為單一 DLL 檔案或NuGet。 包裝盒內含 Tesseract 5、4 和 3 引擎。 準確率高達99.8% ,遠超普通 Tesseract。 極速和多線程 相容於 MVC、WebApp、桌面、控制台和伺服器應用程式 無需處理任何可執行檔或 C++ 程式碼 完全支援 PDF OCR 對幾乎任何影像檔案或 PDF 檔案執行 OCR 識別 完全支援.NET Core、Standard 和 Framework 支援部署在 Windows、Mac、Linux、Azure、Docker、Lambda 和 AWS 上 讀取條碼與二維碼 將 OCR 結果匯出為 XHTML 將 OCR 資訊匯出為可搜尋的 PDF 文檔 多線程支持 125 種國際語言,全部透過NuGet或 OcrData 文件進行管理 提取圖像、座標、統計資料和字體。 不僅僅是文字。 可用於在商業和專有應用程式中重新分發 Tesseract OCR。 IronOCR 在處理真實世界的影像和不完美的文件(例如照片或低解析度掃描件,這些文件可能有數位雜訊或瑕疵)時表現出色。 其他適用於.NET平台的免費 OCR函式庫,例如其他.NET Tesseract API 和 Web 服務,在這些實際用例中表現並不理想。 OCR with Tesseract 5 - Start Coding in C 下面的程式碼範例展示了使用 C# 或.NET從圖像中讀取文字是多麼容易。 一句話 :path=/static-assets/ocr/content-code-examples/get-started/get-started-1.cs string Text = new IronTesseract().Read(@"img\Screenshot.png").Text; $vbLabelText $csharpLabel 可配置的 Hello World :path=/static-assets/ocr/content-code-examples/get-started/get-started-2.cs 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); $vbLabelText $csharpLabel C# PDF OCR 同樣的方法也可用於從任何 PDF 文件中提取文字。 :path=/static-assets/ocr/content-code-examples/get-started/get-started-3.cs 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"); $vbLabelText $csharpLabel 多頁TIFF檔案的OCR識別 :path=/static-assets/ocr/content-code-examples/get-started/get-started-4.cs 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); $vbLabelText $csharpLabel 條碼和二維碼 IronOCR的一個獨特之處在於,它在掃描文字的同時,還可以讀取文件中的條碼和二維碼。 OcrResult.OcrBarcode 類別的實例為開發者提供有關每個掃描條碼的詳細資訊。 :path=/static-assets/ocr/content-code-examples/get-started/get-started-5.cs 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); } $vbLabelText $csharpLabel 對影像特定區域進行OCR識別 IronOCR 的所有掃描和讀取方法都允許我們精確指定要從頁面的哪個部分讀取文字。 這在處理標準化表格時非常有用,可以節省大量時間並提高效率。 要使用作物區域,我們需要在 System.Drawing 中新增系統引用,以便我們可以使用 System.Drawing.Rectangle 物件。 :path=/static-assets/ocr/content-code-examples/get-started/get-started-6.cs 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); $vbLabelText $csharpLabel 低品質掃描的光學字元識別 IronOCR OcrInput 類別可以修復普通 Tesseract 無法讀取的掃描件。 :path=/static-assets/ocr/content-code-examples/get-started/get-started-7.cs 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); $vbLabelText $csharpLabel 將 OCR 結果匯出為可搜尋 PDF :path=/static-assets/ocr/content-code-examples/get-started/get-started-8.cs 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"); $vbLabelText $csharpLabel TIFF 轉可搜尋 PDF :path=/static-assets/ocr/content-code-examples/get-started/get-started-9.cs 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"); $vbLabelText $csharpLabel 將 OCR 結果匯出為 HTML :path=/static-assets/ocr/content-code-examples/get-started/get-started-10.cs 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"); $vbLabelText $csharpLabel OCR影像增強濾鏡 IronOCR為 OcrInput 物件提供獨特的過濾器,以提高 OCR 效能。 影像增強程式碼範例 :path=/static-assets/ocr/content-code-examples/get-started/get-started-11.cs 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); $vbLabelText $csharpLabel OCR影像濾鏡列表 IronOCR內建的用於增強 OCR 性能的輸入過濾器包括: OcrInput.Rotate(double degrees) - 將影像順時針旋轉一定角度。逆時針旋轉請使用負數。 OcrInput.Binarize() - 此濾鏡將每個像素轉換為黑色或白色,沒有中間色,可能會提高低對比度影像的 OCR 效能。 OcrInput.ToGrayScale() - 將每個像素轉換為灰階陰影。 它可能不會提高準確率,但可以提高速度。 OcrInput.Contrast() - 自動增加對比度,通常可提高低對比度掃描的速度和準確性。 OcrInput.DeNoise() - 消除數位噪聲,僅建議在預期會有噪音時使用。 OcrInput.Invert() - 反轉所有顏色(白色變為黑色,反之亦然)。 OcrInput.Dilate() - 推進形態學,向物件邊界添加像素,與侵蝕相反。 OcrInput.Erode() - 推進形態學,從物件邊界移除像素,與膨脹相反。 OcrInput.Deskew() - 旋轉影像使其方向正確。 由於 Tesseract 的傾斜容差有限,因此這種方法很有用。 OcrInput.EnhanceResolution - 提高低品質影像的解析度。 此設定通常用於自動管理低 DPI 輸入。 EnhanceResolution 偵測低解析度影像(低於 275 dpi),將其放大,並銳化文字以獲得更好的 OCR 結果。 雖然耗時,但通常可以減少 OCR 的整體操作時間。 Language - 支援從 22 種國際語言包中進行選擇。 Strategy - 允許根據單字的統計關係,在快速和不太準確或高級(使用 AI 提高準確性)策略之間進行選擇。 ColorSpace - 選擇以灰色或顏色進行 OCR; 雖然在某些對比度場景下彩色顯示效果可能更好,但灰階顯示通常是最佳選擇。 DetectWhiteTextOnDarkBackgrounds - 調整負片影像,自動偵測並讀取深色背景上的白色文字。 InputImageType - 指導 OCR 庫,指定它是在處理整個文件還是片段。 RotateAndStraighten - 允許IronOCR正確處理旋轉或受透視變形影響的文件。 ReadBarcodes - 可自動讀取條碼和二維碼,同時進行文字掃描,而不會顯著增加時間。 ColorDepth - 決定 OCR 過程中顏色深度的每個像素位數。 更深的加工深度可以提高質量,但也會延長加工時間。 125 語言包 IronOCR透過語言包支援125 種國際語言,這些語言套件以 DLL 的形式分發,可從此網站或NuGet套件管理器下載。 語言包括德語、法語、英語、中文、日語等。 針對 MRZ、MICR 檢查、金融數據、車牌等,有專門的語言包。此外,還可以使用自訂的 Tesseract".traineddata"檔案。 語言範例 // Reference to the path of the source file that demonstrates setting language packs for OCR :path=/static-assets/ocr/content-code-examples/get-started/get-started-12.cs // Reference to the path of the source file that demonstrates setting language packs for OCR 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"); $vbLabelText $csharpLabel 多語言範例 同時使用多種語言進行OCR辨識也是可行的。這可以提高Unicode文檔中英文元資料和URL的OCR識別效率。 // Reference to the path of the source file that demonstrates multi-language OCR :path=/static-assets/ocr/content-code-examples/get-started/get-started-13.cs // Reference to the path of the source file that demonstrates multi-language OCR 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"); $vbLabelText $csharpLabel 詳細的OCR結果對象 IronOCR為每次操作傳回一個 OCR 結果物件。 通常,開發人員會存取 Text 屬性來取得掃描的文字。 但是,結果物件包含更詳細的資訊。 // Reference to the path of the source file demonstrating detailed OCR result object usage :path=/static-assets/ocr/content-code-examples/get-started/get-started-14.cs // Reference to the path of the source file demonstrating detailed OCR result object usage 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, Tables $vbLabelText $csharpLabel 表現 IronOCR開箱即用,無需性能調優或影像修改。 速度快速: IronOCR.2020+ 的速度比以前的版本快 10 倍,錯誤率降低了 250% 以上。 了解更多 要了解有關 C#、VB、F# 或任何其他.NET語言中的 OCR 的更多信息,請閱讀我們的社區教程,其中提供了使用IronOCR的實際示例,並展示了優化庫的細微差別。 我們也提供了針對.NET開發人員的完整 API 參考文件。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 審核人 Jeffrey T. Fritz 首席程序经理 - .NET 社群团队 Jeff 也是 .NET 和 Visual Studio 团队的首席程序经理。他是 .NET Conf 虚拟会议系列的执行制作人,并主持“Fritz 和朋友”这一每周两次的開發者的直播节目,在节目上讨论技術并与观众一起编写代碼。Jeff 撰写研讨会、主持演讲,并计划大型 Microsoft 開發者活動(包括 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP Summit)的內容。 準備好開始了嗎? Nuget 下載 5,525,971 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:5,525,971 查看許可證 還在捲動嗎? 想要快速證明? PM > Install-Package IronOcr 執行範例 觀看您的圖片變成可搜尋的文字。 免費 NuGet 下載 總下載量:5,525,971 查看許可證