跳至頁尾內容
OCR 工具

如何將圖片轉換為文字

在當前的數位時代中,將基於圖像的內容轉換為易於閱讀、可編輯和可搜尋的文字是至關重要的。 這在存檔紙質文件、從圖像中提取關鍵資訊或數位化印刷材料等情況下尤為重要。 光學字元辨識 (OCR) 技術提供了一種自動化此轉換過程的方案。 一個能夠實現此目標的可靠高效的工具是IronOCR,這是一個適用於.NET的強大OCR程式庫。

本文將說明如何使用IronOCR將圖片轉換為文字,並探討這種轉換如何節省時間、減少錯誤,並簡化如資料提取、存檔和文件處理等過程。

如何將圖片轉換為文字

  1. 下載一個用於OCR工作的C#程式庫
  2. 建立一個新的IronTesseract實例
  3. 使用OcrImageInput載入您的圖片
  4. 使用OcrRead讀取圖片的內容
  5. 將OCR結果匯出到文字檔案

為什麼要將圖片轉換為文字?

您可能希望將圖片轉換為文字的原因有很多,包括:

  • 資料提取:從掃描的文件和圖像中提取文字以進行存檔或資料處理。
  • 編輯掃描內容:編輯或更新以前掃描的文件中的文字,節省人工重新輸入內容的時間。
  • 提高可及性:將印刷材料轉換為數位文字,使其對螢幕閱讀器或文字轉語音應用程式可用。
  • 自動化:通過從發票、收據或商務名片中閱讀文字來自動化資料輸入和處理。

如何開始將圖片轉換為文字

在我們探索IronOCR強大的圖像轉文字功能如何用於從圖片中提取文字之前,讓我們先來看看使用線上工具Docsumo的基本步驟。 線上OCR工具是尋找休閑甚至一次性OCR任務的人的一個有用選擇,因為它不需要任何手動設置。當然,如果您需要經常進行OCR任務,那麼擁有一個強大的OCR工具如IronOCR可能更適合您。

  1. 瀏覽至線上OCR工具
  2. 上傳您的圖片並開始提取流程
  3. 下載結果資料作為文字文件

步驟一:瀏覽至線上OCR工具

要開始利用OCR技術從圖像文件中提取文字,我們首先需要瀏覽至我們想使用的線上圖像OCR工具。

如何將圖片轉換為文字:圖1 - Docsumo OCR工具

步驟二:上傳您的圖片並開始提取流程

現在,通過點擊"上傳文件"按鈕,我們可以上傳我們想要從中提取文字的圖片文件。 工具會立即開始處理圖片。

如何將圖片轉換為文字:圖2 - Docsumo - 文件處理

步驟三:下載結果資料作為文字文件

現在圖片已處理完成,我們可以將提取的文字下載為新的文字文件,以便進一步使用或操作。

如何將圖片轉換為文字:圖3 - Docsumo - 圖片處理完成

您還可以查看該文件,突出顯示各個部分以查看其中包含的文字。 如果您只想查看某些部分中的文字,這特別有用。 然後,您仍然可以將文字下載為文字文件、XLS或JSON。

如何將圖片轉換為文字:圖4

開始使用IronOCR

IronOCR是一個多功能的.NET程式庫,允許您在圖片上執行OCR操作。 它提供廣泛的功能,可以處理各種文件格式(如PNG、JPEG、TIFF和PDF),進行圖片校正,掃描專業文件(護照、車牌等),提供有關掃描文件的高級資訊,轉換掃描文件和突出顯示文字。

安裝IronOCR程式庫

在您可以開始使用IronOCR閱讀圖片之前,您需要安裝它(如果您尚未在專案中安裝)。 您可以在Visual Studio中通過NuGet輕鬆安裝IronOCR。 打開NuGet套件管理器主控台並運行以下命令:

Install-Package IronOcr

或者,您可以通過在方案頁中搜索IronOCR,通過NuGet套件管理頁安裝它。

如何將圖片轉換為文字:圖5

要在您的程式碼中使用IronOCR,請確保在程式碼的頂部有正確的導入語句:

using IronOcr;
using IronOcr;
Imports IronOcr
$vbLabelText   $csharpLabel

將圖片轉換為文字:基本範例

首先,讓我們來看看使用IronOCR的一個基本圖像轉文字範例。 這是任何OCR工具的核心功能,對於這個範例,我們將使用我們用於線上工具的PNG文件。 在此範例中,我們首先實例化了ocr。 然後,我們使用OcrImageInput類從提供的圖片文件建立一個新的OcrImageInput物件。 最後,使用OcrResult物件。 然後,我們可以存取提取的文字並使用ocrResult.Text將其顯示在控制台上。

using IronOcr;

IronTesseract ocr = new IronTesseract();

// Load the image from which to extract text
using OcrImageInput image = new OcrImageInput("example.png");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

IronTesseract ocr = new IronTesseract();

// Load the image from which to extract text
using OcrImageInput image = new OcrImageInput("example.png");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

Private ocr As New IronTesseract()

' Load the image from which to extract text
Private OcrImageInput As using

' Perform OCR to extract text
Private ocrResult As OcrResult = ocr.Read(image)

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

輸出圖片

如何將圖片轉換為文字:圖6

處理不同圖片格式

IronOCR支持多種圖片格式,如PNG、JPEG、BMP、GIF和TIFF。 從不同圖片格式中讀取文字的過程保持不變,您只需以正確的擴展名載入文件即可。

using IronOcr;

IronTesseract ocr = new IronTesseract();

// Load a BMP image
using OcrImageInput image = new OcrImageInput("example.bmp");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

IronTesseract ocr = new IronTesseract();

// Load a BMP image
using OcrImageInput image = new OcrImageInput("example.bmp");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

Private ocr As New IronTesseract()

' Load a BMP image
Private OcrImageInput As using

' Perform OCR to extract text
Private ocrResult As OcrResult = ocr.Read(image)

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

提高OCR準確性

可以通過優化影像並配置語言、圖像解析度以及圖像中的雜訊等選項來提高OCR性能。 以下是如何通過使用Sharpen()方法微調OCR提高影像品質需要改進的圖像上的文字提取準確性:

using IronOcr;

IronTesseract ocr = new IronTesseract();

// Load the image and apply image processing to improve accuracy
using OcrImageInput image = new OcrImageInput("example.png");
image.DeNoise();
image.Sharpen();

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

IronTesseract ocr = new IronTesseract();

// Load the image and apply image processing to improve accuracy
using OcrImageInput image = new OcrImageInput("example.png");
image.DeNoise();
image.Sharpen();

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

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

Private ocr As New IronTesseract()

' Load the image and apply image processing to improve accuracy
Private OcrImageInput As using
image.DeNoise()
image.Sharpen()

' Perform OCR to extract text
Dim ocrResult As OcrResult = ocr.Read(image)

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

匯出提取的文字

現在我們知道了基本的圖像轉文字過程,讓我們看看如何匯出所得的文字以供日後使用。 在此範例中,我們將使用與之前相同的過程來載入和掃描影像。 然後,使用output.txt並將提取的文字儲存到該文件中。

using IronOcr;
using System.IO;

IronTesseract ocr = new IronTesseract();

// Load the image
using OcrImageInput image = new OcrImageInput("example.png");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

// Save the extracted text to a file
File.WriteAllText("output.txt", ocrResult.Text);
using IronOcr;
using System.IO;

IronTesseract ocr = new IronTesseract();

// Load the image
using OcrImageInput image = new OcrImageInput("example.png");

// Perform OCR to extract text
OcrResult ocrResult = ocr.Read(image);

// Save the extracted text to a file
File.WriteAllText("output.txt", ocrResult.Text);
Imports IronOcr
Imports System.IO

Private ocr As New IronTesseract()

' Load the image
Private OcrImageInput As using

' Perform OCR to extract text
Private ocrResult As OcrResult = ocr.Read(image)

' Save the extracted text to a file
File.WriteAllText("output.txt", ocrResult.Text)
$vbLabelText   $csharpLabel

如何將圖片轉換為文字:圖7

IronOCR的關鍵特點

  1. 高準確性:IronOCR使用先進的Tesseract OCR算法,並包含內建工具處理複雜圖像,確保高準確性。
  2. 多語言支持:支持125+種語言,包括多種書寫字元如拉丁語、西里爾字母、阿拉伯語和亞洲字元。 但是,應該注意的是,只有英文是與IronOCR一起安裝的。 要使用其他語言,您需要為該語言安裝額外的語言包。
  3. PDF OCR:IronOCR可以從掃描的PDF中提取文字,使其成為數位化文件的寶貴工具。
  4. 影像清理:它提供去斜、降噪反轉等影像預處理工具,以改善影像品質以提高OCR準確性。
  5. 簡單整合:API無縫整合到任何.NET專案中,不論是主控台應用程式、網頁應用程式或桌面軟體。

將圖片轉換為文字的常見使用案例

  • 自動資料錄入:企業可以使用OCR自動從表單、收據或名片中提取資料。
  • 文件存檔:組織可以數位化實體文件,使其可搜尋並更易儲存。
  • 可及性:將印刷材料轉換為文字,供螢幕閱讀器或其他輔助技術使用。
  • 研究與分析:快速將掃描的研究材料轉換為文字,以便分析或整合到其他軟體工具中。
  • 學習:將掃描的學習筆記轉換為可編輯的文字,然後可以保存為Word文件,以便在如IronWord、Microsoft Word或Google docs等工具中進一步操作。

結論

使用IronOCR從圖像中轉換文字是一種快速、準確且高效的方法,可處理文件處理任務。 無論您是在處理掃描文件、數位圖像還是PDF文件,IronOCR都簡化了這一過程,提供高準確性、多語言支持和強大的影像處理工具。 這一工具是希望簡化文件管理工作流、自動化資料提取或增強可及性的企業的理想選擇。

使用免費試用立即親自體驗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天。
聊天
電子郵件
給我打電話